]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
tests: fix false rm -I test failure when run as root
authorPádraig Brady <P@draigBrady.com>
Fri, 15 Nov 2013 18:16:54 +0000 (18:16 +0000)
committerPádraig Brady <P@draigBrady.com>
Mon, 18 Nov 2013 01:30:19 +0000 (01:30 +0000)
Fix a recent regression introduced in commit v8.21-127-g5ee7d8f

Also related to this is the recent query about root run `rm -I`
ignoring the mode bits of a file: https://bugzilla.redhat.com/1013171

* tests/rm/interactive-once.sh: Avoid the messages and
corresponding file presence checks with write protected files
when running as root.

tests/rm/interactive-once.sh

index 1064c0851f429c34d258972c479c7cf56472ba87..4ad76c01ab12de055ceac4968bb3b27d052aa880 100755 (executable)
@@ -39,9 +39,15 @@ if ls /dev/stdin >/dev/null 2>&1; then
   echo 'one file, read only, answer no' >> err || fail=1
   touch file1-1 || framework_failure_
   chmod a-w file1-1 || framework_failure_
+  if ! test -w file1-1; then
+    # root won't get prompted
+    write_prot_msg1="rm: remove write-protected regular empty file 'file1-1'? "
+  fi
   rm ---presume-input-tty -I file1-* < in-n >> out 2>> err || fail=1
   echo . >> err || fail=1
-  test -f file1-1 || fail=1
+  if test "$write_prot_msg1"; then
+    test -f file1-1 || fail=1
+  fi
 fi
 
 echo 'three files, no recursion' >> err || fail=1
@@ -72,12 +78,18 @@ if ls /dev/stdin >/dev/null 2>&1; then
   touch file3-1 file3-2 file3-3 file3-4 || framework_failure_
   echo non_empty > file3-4 || framework_failure_ # to shorten diagnostic
   chmod a-w file3-4 || framework_failure_
+  if ! test -w file3-4; then
+    # root won't get prompted
+    write_prot_msg2="rm: remove write-protected regular file 'file3-4'? "
+  fi
   cat in-y in-n | rm ---presume-input-tty -I file3-* >> out 2>> err || fail=1
   echo . >> err || fail=1
   test -f file3-1 && fail=1
   test -f file3-2 && fail=1
   test -f file3-3 && fail=1
-  test -f file3-4 || fail=1
+  if test "$write_prot_msg2"; then
+    test -f file3-4 || fail=1
+  fi
 fi
 
 echo 'one file, recursion, answer no' >> err || fail=1
@@ -104,11 +116,11 @@ test -d dir2-2 && fail=1
 
 cat <<\EOF > expout || fail=1
 EOF
-cat <<\EOF > experr || fail=1
+cat <<EOF > experr || fail=1
 one file, no recursion
 .
 one file, read only, answer no
-rm: remove write-protected regular empty file 'file1-1'? .
+$write_prot_msg1.
 three files, no recursion
 .
 four files, no recursion, answer no
@@ -116,7 +128,7 @@ rm: remove 4 arguments? .
 four files, no recursion, answer yes
 rm: remove 4 arguments? .
 four files, no recursion, 1 read only, answer yes no
-rm: remove 4 arguments? rm: remove write-protected regular file 'file3-4'? .
+rm: remove 4 arguments? $write_prot_msg2.
 one file, recursion, answer no
 rm: remove 1 argument recursively? .
 one file, recursion, answer yes