2 # Test the -I option added to coreutils 6.0
4 # Copyright (C) 2006-2024 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 <https://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 || framework_failure_
34 rm -I file1-
* < in-n
>> out
2>> err || fail
=1
35 echo .
>> err || framework_failure_
36 test -f file1-1
&& fail
=1
39 echo 'one file, read only, answer no' >> err || framework_failure_
40 if ls /dev
/stdin
>/dev
/null
2>&1; then
41 touch file1-1 || framework_failure_
42 chmod a-w file1-1 || framework_failure_
43 if ! test -w file1-1
; then
44 # root won't get prompted
45 write_prot_msg1
="rm: remove write-protected regular empty file 'file1-1'? "
47 rm ---presume-input-tty -I file1-
* < in-n
>> out
2>> err || fail
=1
48 echo .
>> err || framework_failure_
49 if test "$write_prot_msg1"; then
50 test -f file1-1 || fail
=1
53 echo '.' >> err || framework_failure_
56 echo 'three files, no recursion' >> err || framework_failure_
57 rm -I file2-
* < in-n
>> out
2>> err || fail
=1
58 echo .
>> err || framework_failure_
59 test -f file2-1
&& fail
=1
60 test -f file2-2
&& fail
=1
61 test -f file2-3
&& fail
=1
63 echo 'four files, no recursion, answer no' >> err || framework_failure_
64 rm -I file3-
* < in-n
>> out
2>> err || fail
=1
65 echo .
>> err || framework_failure_
66 test -f file3-1 || fail
=1
67 test -f file3-2 || fail
=1
68 test -f file3-3 || fail
=1
69 test -f file3-4 || fail
=1
71 echo 'four files, no recursion, answer yes' >> err || framework_failure_
72 rm -I file3-
* < in-y
>> out
2>> err || fail
=1
73 echo .
>> err || framework_failure_
74 test -f file3-1
&& fail
=1
75 test -f file3-2
&& fail
=1
76 test -f file3-3
&& fail
=1
77 test -f file3-4
&& fail
=1
79 echo 'four files, no recursion, 1 read only, answer yes no' >> err \
81 if ls /dev
/stdin
>/dev
/null
2>&1; then
82 touch file3-1 file3-2 file3-3 file3-4 || framework_failure_
83 echo non_empty
> file3-4 || framework_failure_
# to shorten diagnostic
84 chmod a-w file3-4 || framework_failure_
85 if ! test -w file3-4
; then
86 # root won't get prompted
87 write_prot_msg2
="rm: remove write-protected regular file 'file3-4'? "
89 cat in-y in-n |
rm ---presume-input-tty -I file3-
* >> out
2>> err || fail
=1
90 echo .
>> err || framework_failure_
91 test -f file3-1
&& fail
=1
92 test -f file3-2
&& fail
=1
93 test -f file3-3
&& fail
=1
94 if test "$write_prot_msg2"; then
95 test -f file3-4 || fail
=1
98 echo 'rm: remove 4 arguments? .' >> err || framework_failure_
101 echo 'one file, recursion, answer no' >> err || framework_failure_
102 rm -I -R dir1-
* < in-n
>> out
2>> err || fail
=1
103 echo .
>> err || framework_failure_
104 test -d dir1-1 || fail
=1
106 echo 'one file, recursion, answer yes' >> err || framework_failure_
107 rm -I -R dir1-
* < in-y
>> out
2>> err || fail
=1
108 echo .
>> err || framework_failure_
109 test -d dir1-1
&& fail
=1
111 echo 'multiple files, recursion, answer no' >> err || framework_failure_
112 rm -I -R dir2-
* < in-n
>> out
2>> err || fail
=1
113 echo .
>> err || framework_failure_
114 test -d dir2-1 || fail
=1
115 test -d dir2-2 || fail
=1
117 echo 'multiple files, recursion, answer yes' >> err || framework_failure_
118 rm -I -R dir2-
* < in-y
>> out
2>> err || fail
=1
119 echo .
>> err || framework_failure_
120 test -d dir2-1
&& fail
=1
121 test -d dir2-2
&& fail
=1
123 cat <<EOF > experr || framework_failure_
124 one file, no recursion
126 one file, read only, answer no
128 three files, no recursion
130 four files, no recursion, answer no
131 rm: remove 4 arguments? .
132 four files, no recursion, answer yes
133 rm: remove 4 arguments? .
134 four files, no recursion, 1 read only, answer yes no
135 rm: remove 4 arguments? $write_prot_msg2.
136 one file, recursion, answer no
137 rm: remove 1 argument recursively? .
138 one file, recursion, answer yes
139 rm: remove 1 argument recursively? .
140 multiple files, recursion, answer no
141 rm: remove 2 arguments recursively? .
142 multiple files, recursion, answer yes
143 rm: remove 2 arguments recursively? .
146 compare
/dev
/null out || fail
=1
147 compare experr err || fail
=1