tests: factor 350 fail=0 initializations into test-lib.sh
[platform/upstream/coreutils.git] / tests / rm / interactive-once
1 #!/bin/sh
2 # Test the -I option 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-once
20
21 if test "$VERBOSE" = yes; then
22   set -x
23   rm --version
24 fi
25
26 . $srcdir/test-lib.sh
27
28 mkdir -p dir1-1 dir2-1 dir2-2 || framework_failure
29 touch file1-1 file2-1 file2-2 file2-3 file3-1 file3-2 file3-3 file3-4 \
30   || framework_failure
31 echo y > $test.Iy || framework_failure
32 echo n > $test.In || 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 'one file, no recursion' > err || fail=1
40 rm -I file1-* < $test.In >> out 2>> err || fail=1
41 echo . >> err || fail=1
42 test -f file1-1 && fail=1
43
44 echo 'three files, no recursion' >> err || fail=1
45 rm -I file2-* < $test.In >> out 2>> err || fail=1
46 echo . >> err || fail=1
47 test -f file2-1 && fail=1
48 test -f file2-2 && fail=1
49 test -f file2-3 && fail=1
50
51 echo 'four files, no recursion, answer no' >> err || fail=1
52 rm -I file3-* < $test.In >> 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 test -f file3-3 || fail=1
57 test -f file3-4 || fail=1
58
59 echo 'four files, no recursion, answer yes' >> err || fail=1
60 rm -I file3-* < $test.Iy >> out 2>> err || fail=1
61 echo . >> err || fail=1
62 test -f file3-1 && fail=1
63 test -f file3-2 && fail=1
64 test -f file3-3 && fail=1
65 test -f file3-4 && fail=1
66
67 echo 'one file, recursion, answer no' >> err || fail=1
68 rm -I -R dir1-* < $test.In >> out 2>> err || fail=1
69 echo . >> err || fail=1
70 test -d dir1-1 || fail=1
71
72 echo 'one file, recursion, answer yes' >> err || fail=1
73 rm -I -R dir1-* < $test.Iy >> out 2>> err || fail=1
74 echo . >> err || fail=1
75 test -d dir1-1 && fail=1
76
77 echo 'multiple files, recursion, answer no' >> err || fail=1
78 rm -I -R dir2-* < $test.In >> out 2>> err || fail=1
79 echo . >> err || fail=1
80 test -d dir2-1 || fail=1
81 test -d dir2-2 || fail=1
82
83 echo 'multiple files, recursion, answer yes' >> err || fail=1
84 rm -I -R dir2-* < $test.Iy >> out 2>> err || fail=1
85 echo . >> err || fail=1
86 test -d dir2-1 && fail=1
87 test -d dir2-2 && fail=1
88
89 cat <<\EOF > expout || fail=1
90 EOF
91 cat <<\EOF > experr || fail=1
92 one file, no recursion
93 .
94 three files, no recursion
95 .
96 four files, no recursion, answer no
97 rm: remove all arguments? .
98 four files, no recursion, answer yes
99 rm: remove all arguments? .
100 one file, recursion, answer no
101 rm: remove all arguments recursively? .
102 one file, recursion, answer yes
103 rm: remove all arguments recursively? .
104 multiple files, recursion, answer no
105 rm: remove all arguments recursively? .
106 multiple files, recursion, answer yes
107 rm: remove all arguments recursively? .
108 EOF
109
110 compare out expout || fail=1
111 compare err experr || fail=1
112
113 Exit $fail