2 # Test the -I option added to coreutils 6.0
4 # Copyright (C) 2006-2013 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=.}/tests/init.sh"; path_prepend_ .
/src
22 mkdir
-p dir1-1 dir2-1 dir2-2 || framework_failure_
23 touch file1-1 file2-1 file2-2 file2-3 file3-1 file3-2 file3-3 file3-4 \
25 echo y
> in-y || framework_failure_
26 echo n
> in-n || framework_failure_
27 rm -f out err || framework_failure_
30 # The prompt has a trailing space, and no newline, so an extra
31 # 'echo .' is inserted after each rm to make it obvious what was asked.
33 echo 'one file, no recursion' > err || fail
=1
34 rm -I file1-
* < in-n
>> out
2>> err || fail
=1
35 echo .
>> err || fail
=1
36 test -f file1-1
&& fail
=1
38 if ls /dev
/stdin
>/dev
/null
2>&1; then
39 echo 'one file, read only, answer no' >> err || fail
=1
40 touch file1-1 || framework_failure_
41 chmod a-w file1-1 || framework_failure_
42 if ! test -w file1-1
; then
43 # root won't get prompted
44 write_prot_msg1
="rm: remove write-protected regular empty file 'file1-1'? "
46 rm ---presume-input-tty -I file1-
* < in-n
>> out
2>> err || fail
=1
47 echo .
>> err || fail
=1
48 if test "$write_prot_msg1"; then
49 test -f file1-1 || fail
=1
53 echo 'three files, no recursion' >> err || fail
=1
54 rm -I file2-
* < in-n
>> out
2>> err || fail
=1
55 echo .
>> err || fail
=1
56 test -f file2-1
&& fail
=1
57 test -f file2-2
&& fail
=1
58 test -f file2-3
&& fail
=1
60 echo 'four files, no recursion, answer no' >> err || fail
=1
61 rm -I file3-
* < in-n
>> out
2>> err || fail
=1
62 echo .
>> err || fail
=1
63 test -f file3-1 || fail
=1
64 test -f file3-2 || fail
=1
65 test -f file3-3 || fail
=1
66 test -f file3-4 || fail
=1
68 echo 'four files, no recursion, answer yes' >> err || fail
=1
69 rm -I file3-
* < in-y
>> out
2>> err || fail
=1
70 echo .
>> err || fail
=1
71 test -f file3-1
&& fail
=1
72 test -f file3-2
&& fail
=1
73 test -f file3-3
&& fail
=1
74 test -f file3-4
&& fail
=1
76 if ls /dev
/stdin
>/dev
/null
2>&1; then
77 echo 'four files, no recursion, 1 read only, answer yes no' >> err || fail
=1
78 touch file3-1 file3-2 file3-3 file3-4 || framework_failure_
79 echo non_empty
> file3-4 || framework_failure_
# to shorten diagnostic
80 chmod a-w file3-4 || framework_failure_
81 if ! test -w file3-4
; then
82 # root won't get prompted
83 write_prot_msg2
="rm: remove write-protected regular file 'file3-4'? "
85 cat in-y in-n |
rm ---presume-input-tty -I file3-
* >> out
2>> err || fail
=1
86 echo .
>> err || fail
=1
87 test -f file3-1
&& fail
=1
88 test -f file3-2
&& fail
=1
89 test -f file3-3
&& fail
=1
90 if test "$write_prot_msg2"; then
91 test -f file3-4 || fail
=1
95 echo 'one file, recursion, answer no' >> err || fail
=1
96 rm -I -R dir1-
* < in-n
>> out
2>> err || fail
=1
97 echo .
>> err || fail
=1
98 test -d dir1-1 || fail
=1
100 echo 'one file, recursion, answer yes' >> err || fail
=1
101 rm -I -R dir1-
* < in-y
>> out
2>> err || fail
=1
102 echo .
>> err || fail
=1
103 test -d dir1-1
&& fail
=1
105 echo 'multiple files, recursion, answer no' >> err || fail
=1
106 rm -I -R dir2-
* < in-n
>> out
2>> err || fail
=1
107 echo .
>> err || fail
=1
108 test -d dir2-1 || fail
=1
109 test -d dir2-2 || fail
=1
111 echo 'multiple files, recursion, answer yes' >> err || fail
=1
112 rm -I -R dir2-
* < in-y
>> out
2>> err || fail
=1
113 echo .
>> err || fail
=1
114 test -d dir2-1
&& fail
=1
115 test -d dir2-2
&& fail
=1
117 cat <<\EOF
> expout || fail
=1
119 cat <<EOF > experr || fail=1
120 one file, no recursion
122 one file, read only, answer no
124 three files, no recursion
126 four files, no recursion, answer no
127 rm: remove 4 arguments? .
128 four files, no recursion, answer yes
129 rm: remove 4 arguments? .
130 four files, no recursion, 1 read only, answer yes no
131 rm: remove 4 arguments? $write_prot_msg2.
132 one file, recursion, answer no
133 rm: remove 1 argument recursively? .
134 one file, recursion, answer yes
135 rm: remove 1 argument recursively? .
136 multiple files, recursion, answer no
137 rm: remove 2 arguments recursively? .
138 multiple files, recursion, answer yes
139 rm: remove 2 arguments recursively? .
142 compare expout out || fail
=1
143 compare experr err || fail
=1