]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
tests: enhance rm test regarding "." and ".."
authorBernhard Voelker <mail@bernhard-voelker.de>
Fri, 22 Nov 2013 14:54:06 +0000 (15:54 +0100)
committerBernhard Voelker <mail@bernhard-voelker.de>
Fri, 22 Nov 2013 14:54:06 +0000 (15:54 +0100)
Recent commit 2da7009d changed the error diagnostic of rm(1) trying
to remove "." or "..".  Enhance the corresponding test.

* tests/rm/r-4.sh: Ensure rm(1) outputs the expected error diagnostic.

tests/rm/r-4.sh

index 94702a6d1e9f697ba7e93f0c41aa8eaf872a3601..a3ceaf985ed4b506172e54510485540779ecac38 100755 (executable)
@@ -22,11 +22,26 @@ print_ver_ rm
 mkdir d || framework_failure_
 touch d/a || framework_failure_
 
-rm -fr d/. 2>/dev/null && fail=1
-rm -fr d/./ 2>/dev/null && fail=1
-rm -fr d/.//// 2>/dev/null && fail=1
-rm -fr d/.. 2>/dev/null && fail=1
-rm -fr d/../ 2>/dev/null && fail=1
+# Expected error diagnostic as grep pattern.
+exp="^rm: refusing to remove '\.' or '\.\.' directory: skipping '.*'\$"
+
+rmtest()
+{
+  # Try removing - expecting failure.
+  rm -fr "$1" 2> err && fail=1
+
+  # Ensure the expected error diagnostic is output.
+  grep "$exp" err || { cat err; fail=1; }
+
+  return $fail
+}
+
+rmtest 'd/.'     || fail=1
+rmtest 'd/./'    || fail=1
+rmtest 'd/.////' || fail=1
+rmtest 'd/..'    || fail=1
+rmtest 'd/../'   || fail=1
+
 
 # This test is too dangerous -- if there's a bug you're wiped out!
 # rm -fr / 2>/dev/null && fail=1