summaryrefslogtreecommitdiff
path: root/tests/t0000-basic.sh
blob: 6b6b07e9a22d0124fda66e631b97ad3beb33fa1a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/bin/sh
# Ensure that a simple command using -s succeeds with no prompt

# Copyright (C) 2007 Free Software Foundation, Inc.

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

../parted/parted --version > /dev/null 2>&1
if test $? != 0; then
  echo >&2 'You have not built parted yet.'
  exit 1
fi

test_description='Test the very basics part #1.'

: ${srcdir=.}
. $srcdir/test-lib.sh

# FIXME: is id -u portable enough?
uid=`id -u` || uid=1

# create a file of size N bytes
N=1M
dev=loop-file

test_expect_success \
    'create the test file' \
    'dd if=/dev/null of=$dev bs=1 seek=$N 2> /dev/null'

test_expect_success \
    'run parted -s FILE mklabel msdos' \
    'parted -s $dev mklabel msdos > out 2>&1'
test_expect_success 'expect no output' 'compare out /dev/null'

# ----------------------------------------------
# Now, ensure that a simple mklabel command succeeds.
# Since there's no -s option, there are prompts -- sometimes.

test_expect_success \
    'erase the left-over label' \
    'dd if=/dev/zero of=$dev bs=4K count=1 2> /dev/null'

# First iteration works with no prompting, since there is no preexisting label.
test_expect_success \
    'run parted mklabel (without -s) on a blank disk' \
    'parted $dev mklabel msdos > out 2>&1'

test_expect_success \
    'create expected output file' \
    'emit_superuser_warning > exp'

test_expect_success \
    'check its "interactive" output' \
    'compare out exp 1>&2'

test_expect_success 'create interactive input' 'printf "y\n" > in'

# Now that there's a label, rerunning the same command is interactive.
test_expect_success \
    'rerun that same command, but now with a preexisting label' \
    'parted ---pretend-input-tty $dev mklabel msdos < in > out 2>&1'

# Transform the actual output, to avoid spurious differences when
# $PWD contains a symlink-to-dir.  Also, remove the ^M      ...^M bogosity.
test_expect_success \
    'normalize the actual output' \
    'mv out o2 && sed -e "s,on /.*/$dev,on DEVICE,;s,
   *
,,;s, $,," \
                      -e "s,^.*/lt-parted: ,parted: ," o2 > out'

# Create expected output file.
fail=0
{ emit_superuser_warning > exp; } || fail=1
cat <<EOF >> exp || fail=1
Warning: The existing disk label on DEVICE will be destroyed and all\
 data on this disk will be lost. Do you want to continue?
Yes/No? y
EOF
test_expect_success \
    'create expected output file' \
    'test $fail = 0'

test_expect_success \
    'check its output -- slightly different here, due to prompts' \
    'compare out exp'

test_done