2 # Ensure that a simple command using -s succeeds with no prompt
4 # Copyright (C) 2007, 2009-2012 Free Software Foundation, Inc.
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 . "${srcdir=.}/init.sh"; path_prepend_ ../parted
21 parted --version || fail_ 'You have not built parted yet.'
23 # FIXME: is id -u portable enough?
26 # create a file of size N bytes
30 # create the test file
31 dd if=/dev/null of=$dev bs=1 seek=$N 2> /dev/null || fail=1
33 # run parted -s FILE mklabel msdos
34 parted -s $dev mklabel msdos > out 2>&1 || fail=1
35 compare /dev/null out || fail=1
37 # ----------------------------------------------
38 # Now, ensure that a simple mklabel command succeeds.
39 # Since there's no -s option, there are prompts -- sometimes.
41 # erase the left-over label
42 dd if=/dev/zero of=$dev bs=4K count=1 conv=notrunc 2> /dev/null || fail=1
44 # First iteration works with no prompting, since there is no preexisting label.
45 # run parted mklabel (without -s) on a blank disk
46 parted $dev mklabel msdos > out 2>&1 || fail=1
48 # create expected output file
49 emit_superuser_warning > exp || fail=1
51 # check its "interactive" output
52 compare exp out || fail=1
54 # create interactive input
55 printf 'y\n' > in || fail=1
57 # Now that there's a label, rerunning the same command is interactive.
58 # rerun that same command, but now with a preexisting label
59 parted ---pretend-input-tty $dev mklabel msdos < in > out 2>&1 || fail=1
61 # Transform the actual output, to avoid spurious differences when
62 # $PWD contains a symlink-to-dir. Also, remove the ^M ...^M bogosity.
63 # normalize the actual output
64 mv out o2 && sed -e "s,on /.*/$dev,on DEVICE,;s,
\r *
\r,,g;s, $,," \
65 -e "s,^.*/lt-parted: ,parted: ," o2 > out
67 # Create expected output file.
68 { emit_superuser_warning > exp; } || fail=1
69 cat <<EOF >> exp || fail=1
70 Warning: The existing disk label on DEVICE will be destroyed and all\
71 data on this disk will be lost. Do you want to continue?
75 # check its output -- slightly different here, due to prompts
76 compare exp out || fail=1