OSDN Git Service

maint: remove now-unused fat-related functions
[android-x86/external-parted.git] / tests / t0000-basic.sh
1 #!/bin/sh
2 # Ensure that a simple command using -s succeeds with no prompt
3
4 # Copyright (C) 2007, 2009-2012 Free Software Foundation, Inc.
5
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.
10
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.
15
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/>.
18
19 . "${srcdir=.}/init.sh"; path_prepend_ ../parted
20
21 parted --version || fail_ 'You have not built parted yet.'
22
23 # FIXME: is id -u portable enough?
24 uid=`id -u` || uid=1
25
26 # create a file of size N bytes
27 N=1M
28 dev=loop-file
29
30 # create the test file
31 dd if=/dev/null of=$dev bs=1 seek=$N 2> /dev/null || fail=1
32
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
36
37 # ----------------------------------------------
38 # Now, ensure that a simple mklabel command succeeds.
39 # Since there's no -s option, there are prompts -- sometimes.
40
41 # erase the left-over label
42 dd if=/dev/zero of=$dev bs=4K count=1 conv=notrunc 2> /dev/null || fail=1
43
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
47
48 # create expected output file
49 emit_superuser_warning > exp || fail=1
50
51 # check its "interactive" output
52 compare exp out || fail=1
53
54 # create interactive input
55 printf 'y\n' > in || fail=1
56
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
60
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
66
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?
72 Yes/No? y
73 EOF
74
75 # check its output -- slightly different here, due to prompts
76 compare exp out || fail=1
77
78 Exit $fail