tests: factor 350 fail=0 initializations into test-lib.sh
[platform/upstream/coreutils.git] / tests / rm / interactive-always
1 #!/bin/sh
2 # Test the --interactive[=WHEN] changes added to coreutils 6.0
3
4 # Copyright (C) 2006-2009 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 test=interactive-always
20
21 if test "$VERBOSE" = yes; then
22   set -x
23   rm --version
24 fi
25
26 . $srcdir/test-lib.sh
27
28 touch file1-1 file1-2 file2-1 file2-2 file3-1 file3-2 file4-1 file4-2 \
29   || framework_failure
30 # If asked, answer no to first question, then yes to second.
31 echo 'n
32 y' > $test.I || framework_failure
33 rm -f out err || framework_failure
34
35
36 # The prompt has a trailing space, and no newline, so an extra
37 # 'echo .' is inserted after each rm to make it obvious what was asked.
38
39 echo 'no WHEN' > err || fail=1
40 rm -R --interactive file1-* < $test.I >> out 2>> err || fail=1
41 echo . >> err || fail=1
42 test -f file1-1 || fail=1
43 test -f file1-2 && fail=1
44
45 echo 'WHEN=never' >> err || fail=1
46 rm -R --interactive=never file2-* < $test.I >> out 2>> err || fail=1
47 echo . >> err || fail=1
48 test -f file2-1 && fail=1
49 test -f file2-2 && fail=1
50
51 echo 'WHEN=once' >> err || fail=1
52 rm -R --interactive=once file3-* < $test.I >> out 2>> err || fail=1
53 echo . >> err || fail=1
54 test -f file3-1 || fail=1
55 test -f file3-2 || fail=1
56
57 echo 'WHEN=always' >> err || fail=1
58 rm -R --interactive=always file4-* < $test.I >> out 2>> err || fail=1
59 echo . >> err || fail=1
60 test -f file4-1 || fail=1
61 test -f file4-2 && fail=1
62
63 echo '-f overrides --interactive' >> err || fail=1
64 rm -R --interactive=once -f file1-* < $test.I >> out 2>> err || fail=1
65 echo . >> err || fail=1
66 test -f file1-1 && fail=1
67
68 echo '--interactive overrides -f' >> err || fail=1
69 rm -R -f --interactive=once file4-* < $test.I >> out 2>> err || fail=1
70 echo . >> err || fail=1
71 test -f file4-1 || fail=1
72
73 cat <<\EOF > expout || fail=1
74 EOF
75 cat <<\EOF > experr || fail=1
76 no WHEN
77 rm: remove regular empty file `file1-1'? rm: remove regular empty file `file1-2'? .
78 WHEN=never
79 .
80 WHEN=once
81 rm: remove all arguments recursively? .
82 WHEN=always
83 rm: remove regular empty file `file4-1'? rm: remove regular empty file `file4-2'? .
84 -f overrides --interactive
85 .
86 --interactive overrides -f
87 rm: remove all arguments recursively? .
88 EOF
89
90 compare out expout || fail=1
91 compare err experr || fail=1
92
93 Exit $fail