From 9eb4c31eb78c28dd9f72d1cbb940270311be343c Mon Sep 17 00:00:00 2001 From: Stefano Lattarini Date: Thu, 30 Aug 2012 14:13:12 +0200 Subject: tests: add .sh and .pl suffixes to shell and perl tests, respectively Not only this shrinks the size of the generated Makefile (from > 6300 lines to ~3000), but will allow further simplifications in future changes. * tests/Makefile.am (TEST_EXTENSIONS): Add '.sh' and '.pl'. (PL_LOG_COMPILER, SH_LOG_COMPILER): New, still defined simply to $(LOG_COMPILER) for the time being. (TESTS, root_tests): Adjust as described. * All tests: Rename as described. --- tests/rm/cycle | 36 ------------ tests/rm/cycle.sh | 36 ++++++++++++ tests/rm/d-1 | 38 ------------- tests/rm/d-1.sh | 38 +++++++++++++ tests/rm/d-2 | 33 ----------- tests/rm/d-2.sh | 33 +++++++++++ tests/rm/d-3 | 37 ------------- tests/rm/d-3.sh | 37 +++++++++++++ tests/rm/dangling-symlink | 45 --------------- tests/rm/dangling-symlink.sh | 45 +++++++++++++++ tests/rm/deep-1 | 53 ------------------ tests/rm/deep-1.sh | 53 ++++++++++++++++++ tests/rm/deep-2 | 49 ----------------- tests/rm/deep-2.sh | 49 +++++++++++++++++ tests/rm/dir-no-w | 42 -------------- tests/rm/dir-no-w.sh | 42 ++++++++++++++ tests/rm/dir-nonrecur | 34 ------------ tests/rm/dir-nonrecur.sh | 34 ++++++++++++ tests/rm/dot-rel | 29 ---------- tests/rm/dot-rel.sh | 29 ++++++++++ tests/rm/empty-inacc | 38 ------------- tests/rm/empty-inacc.sh | 38 +++++++++++++ tests/rm/empty-name | 60 -------------------- tests/rm/empty-name.pl | 60 ++++++++++++++++++++ tests/rm/ext3-perf | 83 ---------------------------- tests/rm/ext3-perf.sh | 83 ++++++++++++++++++++++++++++ tests/rm/f-1 | 26 --------- tests/rm/f-1.sh | 26 +++++++++ tests/rm/fail-2eperm | 55 ------------------ tests/rm/fail-2eperm.sh | 55 ++++++++++++++++++ tests/rm/fail-eacces | 54 ------------------ tests/rm/fail-eacces.sh | 54 ++++++++++++++++++ tests/rm/hash | 37 ------------- tests/rm/hash.sh | 37 +++++++++++++ tests/rm/i-1 | 40 -------------- tests/rm/i-1.sh | 40 ++++++++++++++ tests/rm/i-never | 33 ----------- tests/rm/i-never.sh | 33 +++++++++++ tests/rm/i-no-r | 34 ------------ tests/rm/i-no-r.sh | 34 ++++++++++++ tests/rm/ignorable | 30 ---------- tests/rm/ignorable.sh | 30 ++++++++++ tests/rm/inaccessible | 49 ----------------- tests/rm/inaccessible.sh | 49 +++++++++++++++++ tests/rm/interactive-always | 87 ----------------------------- tests/rm/interactive-always.sh | 87 +++++++++++++++++++++++++++++ tests/rm/interactive-once | 107 ------------------------------------ tests/rm/interactive-once.sh | 107 ++++++++++++++++++++++++++++++++++++ tests/rm/ir-1 | 56 ------------------- tests/rm/ir-1.sh | 56 +++++++++++++++++++ tests/rm/isatty | 53 ------------------ tests/rm/isatty.sh | 53 ++++++++++++++++++ tests/rm/many-dir-entries-vs-OOM | 38 ------------- tests/rm/many-dir-entries-vs-OOM.sh | 38 +++++++++++++ tests/rm/no-give-up | 41 -------------- tests/rm/no-give-up.sh | 41 ++++++++++++++ tests/rm/one-file-system | 48 ---------------- tests/rm/one-file-system.sh | 48 ++++++++++++++++ tests/rm/one-file-system2 | 27 --------- tests/rm/one-file-system2.sh | 27 +++++++++ tests/rm/r-1 | 40 -------------- tests/rm/r-1.sh | 40 ++++++++++++++ tests/rm/r-2 | 45 --------------- tests/rm/r-2.sh | 45 +++++++++++++++ tests/rm/r-3 | 48 ---------------- tests/rm/r-3.sh | 48 ++++++++++++++++ tests/rm/r-4 | 36 ------------ tests/rm/r-4.sh | 36 ++++++++++++ tests/rm/read-only | 52 ------------------ tests/rm/read-only.sh | 52 ++++++++++++++++++ tests/rm/readdir-bug | 41 -------------- tests/rm/readdir-bug.sh | 41 ++++++++++++++ tests/rm/rm1 | 48 ---------------- tests/rm/rm1.sh | 48 ++++++++++++++++ tests/rm/rm2 | 55 ------------------ tests/rm/rm2.sh | 55 ++++++++++++++++++ tests/rm/rm3 | 73 ------------------------ tests/rm/rm3.sh | 73 ++++++++++++++++++++++++ tests/rm/rm4 | 31 ----------- tests/rm/rm4.sh | 31 +++++++++++ tests/rm/rm5 | 52 ------------------ tests/rm/rm5.sh | 52 ++++++++++++++++++ tests/rm/sunos-1 | 29 ---------- tests/rm/sunos-1.sh | 29 ++++++++++ tests/rm/unread2 | 35 ------------ tests/rm/unread2.sh | 35 ++++++++++++ tests/rm/unread3 | 43 --------------- tests/rm/unread3.sh | 43 +++++++++++++++ tests/rm/unreadable | 50 ----------------- tests/rm/unreadable.pl | 50 +++++++++++++++++ tests/rm/v-slash | 34 ------------ tests/rm/v-slash.sh | 34 ++++++++++++ 92 files changed, 2104 insertions(+), 2104 deletions(-) delete mode 100755 tests/rm/cycle create mode 100755 tests/rm/cycle.sh delete mode 100755 tests/rm/d-1 create mode 100755 tests/rm/d-1.sh delete mode 100755 tests/rm/d-2 create mode 100755 tests/rm/d-2.sh delete mode 100755 tests/rm/d-3 create mode 100755 tests/rm/d-3.sh delete mode 100755 tests/rm/dangling-symlink create mode 100755 tests/rm/dangling-symlink.sh delete mode 100755 tests/rm/deep-1 create mode 100755 tests/rm/deep-1.sh delete mode 100755 tests/rm/deep-2 create mode 100755 tests/rm/deep-2.sh delete mode 100755 tests/rm/dir-no-w create mode 100755 tests/rm/dir-no-w.sh delete mode 100755 tests/rm/dir-nonrecur create mode 100755 tests/rm/dir-nonrecur.sh delete mode 100755 tests/rm/dot-rel create mode 100755 tests/rm/dot-rel.sh delete mode 100755 tests/rm/empty-inacc create mode 100755 tests/rm/empty-inacc.sh delete mode 100755 tests/rm/empty-name create mode 100755 tests/rm/empty-name.pl delete mode 100755 tests/rm/ext3-perf create mode 100755 tests/rm/ext3-perf.sh delete mode 100755 tests/rm/f-1 create mode 100755 tests/rm/f-1.sh delete mode 100755 tests/rm/fail-2eperm create mode 100755 tests/rm/fail-2eperm.sh delete mode 100755 tests/rm/fail-eacces create mode 100755 tests/rm/fail-eacces.sh delete mode 100755 tests/rm/hash create mode 100755 tests/rm/hash.sh delete mode 100755 tests/rm/i-1 create mode 100755 tests/rm/i-1.sh delete mode 100755 tests/rm/i-never create mode 100755 tests/rm/i-never.sh delete mode 100755 tests/rm/i-no-r create mode 100755 tests/rm/i-no-r.sh delete mode 100755 tests/rm/ignorable create mode 100755 tests/rm/ignorable.sh delete mode 100755 tests/rm/inaccessible create mode 100755 tests/rm/inaccessible.sh delete mode 100755 tests/rm/interactive-always create mode 100755 tests/rm/interactive-always.sh delete mode 100755 tests/rm/interactive-once create mode 100755 tests/rm/interactive-once.sh delete mode 100755 tests/rm/ir-1 create mode 100755 tests/rm/ir-1.sh delete mode 100755 tests/rm/isatty create mode 100755 tests/rm/isatty.sh delete mode 100755 tests/rm/many-dir-entries-vs-OOM create mode 100755 tests/rm/many-dir-entries-vs-OOM.sh delete mode 100755 tests/rm/no-give-up create mode 100755 tests/rm/no-give-up.sh delete mode 100755 tests/rm/one-file-system create mode 100755 tests/rm/one-file-system.sh delete mode 100755 tests/rm/one-file-system2 create mode 100755 tests/rm/one-file-system2.sh delete mode 100755 tests/rm/r-1 create mode 100755 tests/rm/r-1.sh delete mode 100755 tests/rm/r-2 create mode 100755 tests/rm/r-2.sh delete mode 100755 tests/rm/r-3 create mode 100755 tests/rm/r-3.sh delete mode 100755 tests/rm/r-4 create mode 100755 tests/rm/r-4.sh delete mode 100755 tests/rm/read-only create mode 100755 tests/rm/read-only.sh delete mode 100755 tests/rm/readdir-bug create mode 100755 tests/rm/readdir-bug.sh delete mode 100755 tests/rm/rm1 create mode 100755 tests/rm/rm1.sh delete mode 100755 tests/rm/rm2 create mode 100755 tests/rm/rm2.sh delete mode 100755 tests/rm/rm3 create mode 100755 tests/rm/rm3.sh delete mode 100755 tests/rm/rm4 create mode 100755 tests/rm/rm4.sh delete mode 100755 tests/rm/rm5 create mode 100755 tests/rm/rm5.sh delete mode 100755 tests/rm/sunos-1 create mode 100755 tests/rm/sunos-1.sh delete mode 100755 tests/rm/unread2 create mode 100755 tests/rm/unread2.sh delete mode 100755 tests/rm/unread3 create mode 100755 tests/rm/unread3.sh delete mode 100755 tests/rm/unreadable create mode 100755 tests/rm/unreadable.pl delete mode 100755 tests/rm/v-slash create mode 100755 tests/rm/v-slash.sh (limited to 'tests/rm') diff --git a/tests/rm/cycle b/tests/rm/cycle deleted file mode 100755 index 33e1283b6..000000000 --- a/tests/rm/cycle +++ /dev/null @@ -1,36 +0,0 @@ -#!/bin/sh -# rm (coreutils-4.5.4) could be tricked into mistakenly reporting a cycle. - -# Copyright (C) 2003-2012 Free Software Foundation, Inc. - -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -. "${srcdir=.}/init.sh"; path_prepend_ ../src -print_ver_ rm -skip_if_root_ - -mkdir -p a/b -touch a/b/file -chmod u-w a/b - - -rm -rf a a 2>&1 | sed 's/:[^:]*$//' > out || fail=1 -cat <<\EOF > exp -rm: cannot remove 'a/b/file' -rm: cannot remove 'a/b/file' -EOF - -compare exp out || fail=1 - -Exit $fail diff --git a/tests/rm/cycle.sh b/tests/rm/cycle.sh new file mode 100755 index 000000000..33e1283b6 --- /dev/null +++ b/tests/rm/cycle.sh @@ -0,0 +1,36 @@ +#!/bin/sh +# rm (coreutils-4.5.4) could be tricked into mistakenly reporting a cycle. + +# Copyright (C) 2003-2012 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +. "${srcdir=.}/init.sh"; path_prepend_ ../src +print_ver_ rm +skip_if_root_ + +mkdir -p a/b +touch a/b/file +chmod u-w a/b + + +rm -rf a a 2>&1 | sed 's/:[^:]*$//' > out || fail=1 +cat <<\EOF > exp +rm: cannot remove 'a/b/file' +rm: cannot remove 'a/b/file' +EOF + +compare exp out || fail=1 + +Exit $fail diff --git a/tests/rm/d-1 b/tests/rm/d-1 deleted file mode 100755 index f35e95125..000000000 --- a/tests/rm/d-1 +++ /dev/null @@ -1,38 +0,0 @@ -#!/bin/sh -# Test "rm --dir --verbose". - -# Copyright (C) 2012 Free Software Foundation, Inc. - -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -. "${srcdir=.}/init.sh"; path_prepend_ ../src -print_ver_ rm - -mkdir a || framework_failure_ -> b || framework_failure_ - -rm --verbose --dir a b > out || fail=1 - -cat <<\EOF > exp || framework_failure_ -removed directory: 'a' -removed 'b' -EOF - -test -e a && fail=1 -test -e b && fail=1 - -# Compare expected and actual output. -compare exp out || fail=1 - -Exit $fail diff --git a/tests/rm/d-1.sh b/tests/rm/d-1.sh new file mode 100755 index 000000000..f35e95125 --- /dev/null +++ b/tests/rm/d-1.sh @@ -0,0 +1,38 @@ +#!/bin/sh +# Test "rm --dir --verbose". + +# Copyright (C) 2012 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +. "${srcdir=.}/init.sh"; path_prepend_ ../src +print_ver_ rm + +mkdir a || framework_failure_ +> b || framework_failure_ + +rm --verbose --dir a b > out || fail=1 + +cat <<\EOF > exp || framework_failure_ +removed directory: 'a' +removed 'b' +EOF + +test -e a && fail=1 +test -e b && fail=1 + +# Compare expected and actual output. +compare exp out || fail=1 + +Exit $fail diff --git a/tests/rm/d-2 b/tests/rm/d-2 deleted file mode 100755 index a63cff60d..000000000 --- a/tests/rm/d-2 +++ /dev/null @@ -1,33 +0,0 @@ -#!/bin/sh -# Ensure that 'rm -d dir' (i.e., without --recursive) gives a reasonable -# diagnostic when failing. - -# Copyright (C) 2012 Free Software Foundation, Inc. - -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -. "${srcdir=.}/init.sh"; path_prepend_ ../src -print_ver_ rm - -mkdir d || framework_failure_ -> d/a || framework_failure_ - -rm -d d 2> out && fail=1 -printf "%s\n" \ - "rm: cannot remove 'd': Directory not empty" \ - > exp || framework_failure_ - -compare exp out || fail=1 - -Exit $fail diff --git a/tests/rm/d-2.sh b/tests/rm/d-2.sh new file mode 100755 index 000000000..a63cff60d --- /dev/null +++ b/tests/rm/d-2.sh @@ -0,0 +1,33 @@ +#!/bin/sh +# Ensure that 'rm -d dir' (i.e., without --recursive) gives a reasonable +# diagnostic when failing. + +# Copyright (C) 2012 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +. "${srcdir=.}/init.sh"; path_prepend_ ../src +print_ver_ rm + +mkdir d || framework_failure_ +> d/a || framework_failure_ + +rm -d d 2> out && fail=1 +printf "%s\n" \ + "rm: cannot remove 'd': Directory not empty" \ + > exp || framework_failure_ + +compare exp out || fail=1 + +Exit $fail diff --git a/tests/rm/d-3 b/tests/rm/d-3 deleted file mode 100755 index 2f2cf7492..000000000 --- a/tests/rm/d-3 +++ /dev/null @@ -1,37 +0,0 @@ -#!/bin/sh -# Ensure that 'rm -d -i dir' (i.e., without --recursive) gives a prompt and -# then deletes the directory if it is empty - -# Copyright (C) 2012 Free Software Foundation, Inc. - -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -. "${srcdir=.}/init.sh"; path_prepend_ ../src -print_ver_ rm - -mkdir d || framework_failure_ - -echo "y" | rm -i -d --verbose d > out 2> out.err || fail=1 -printf "%s" \ - "rm: remove directory 'd'? " \ - > exp.err || framework_failure_ - -printf "%s\n" \ - "removed directory: 'd'" \ - > exp || framework_failure_ - -compare exp out || fail=1 -compare exp.err out.err || fail=1 - -Exit $fail diff --git a/tests/rm/d-3.sh b/tests/rm/d-3.sh new file mode 100755 index 000000000..2f2cf7492 --- /dev/null +++ b/tests/rm/d-3.sh @@ -0,0 +1,37 @@ +#!/bin/sh +# Ensure that 'rm -d -i dir' (i.e., without --recursive) gives a prompt and +# then deletes the directory if it is empty + +# Copyright (C) 2012 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +. "${srcdir=.}/init.sh"; path_prepend_ ../src +print_ver_ rm + +mkdir d || framework_failure_ + +echo "y" | rm -i -d --verbose d > out 2> out.err || fail=1 +printf "%s" \ + "rm: remove directory 'd'? " \ + > exp.err || framework_failure_ + +printf "%s\n" \ + "removed directory: 'd'" \ + > exp || framework_failure_ + +compare exp out || fail=1 +compare exp.err out.err || fail=1 + +Exit $fail diff --git a/tests/rm/dangling-symlink b/tests/rm/dangling-symlink deleted file mode 100755 index 92a59066a..000000000 --- a/tests/rm/dangling-symlink +++ /dev/null @@ -1,45 +0,0 @@ -#!/bin/sh -# rm should not prompt before removing a dangling symlink. -# Likewise for a non-dangling symlink. -# But for fileutils-4.1.9, it would do the former and -# for fileutils-4.1.10 the latter. - -# Copyright (C) 2002-2012 Free Software Foundation, Inc. - -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -. "${srcdir=.}/init.sh"; path_prepend_ ../src -print_ver_ rm - -ln -s no-file dangle -ln -s / symlink - - -rm ---presume-input-tty dangle symlink & -pid=$! -# The buggy rm (fileutils-4.1.9) would hang here, waiting for input. - -# Wait up to 3.1s for rm to remove the files -check_files_removed() { - local delay="$1" - local present=0 - ls -l dangle > /dev/null 2>&1 && present=1 - ls -l symlink > /dev/null 2>&1 && present=1 - test $present = 1 && { sleep $delay; return 1; } || : -} -retry_delay_ check_files_removed .1 5 || fail=1 - -kill $pid > /dev/null 2>&1 - -Exit $fail diff --git a/tests/rm/dangling-symlink.sh b/tests/rm/dangling-symlink.sh new file mode 100755 index 000000000..92a59066a --- /dev/null +++ b/tests/rm/dangling-symlink.sh @@ -0,0 +1,45 @@ +#!/bin/sh +# rm should not prompt before removing a dangling symlink. +# Likewise for a non-dangling symlink. +# But for fileutils-4.1.9, it would do the former and +# for fileutils-4.1.10 the latter. + +# Copyright (C) 2002-2012 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +. "${srcdir=.}/init.sh"; path_prepend_ ../src +print_ver_ rm + +ln -s no-file dangle +ln -s / symlink + + +rm ---presume-input-tty dangle symlink & +pid=$! +# The buggy rm (fileutils-4.1.9) would hang here, waiting for input. + +# Wait up to 3.1s for rm to remove the files +check_files_removed() { + local delay="$1" + local present=0 + ls -l dangle > /dev/null 2>&1 && present=1 + ls -l symlink > /dev/null 2>&1 && present=1 + test $present = 1 && { sleep $delay; return 1; } || : +} +retry_delay_ check_files_removed .1 5 || fail=1 + +kill $pid > /dev/null 2>&1 + +Exit $fail diff --git a/tests/rm/deep-1 b/tests/rm/deep-1 deleted file mode 100755 index f739eb594..000000000 --- a/tests/rm/deep-1 +++ /dev/null @@ -1,53 +0,0 @@ -#!/bin/sh -# Test "rm" with a deep hierarchy. - -# Copyright (C) 1997-2012 Free Software Foundation, Inc. - -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -# This is a bit of a torture test for mkdir -p, too. -# GNU rm performs *much* better on systems that have a d_type member -# in the directory structure because then it does only one stat per -# command line argument. - -# If this test takes too long on your system, blame the OS. - -. "${srcdir=.}/init.sh"; path_prepend_ ../src -print_ver_ rm - -umask 022 - - -k20=/k/k/k/k/k/k/k/k/k/k/k/k/k/k/k/k/k/k/k/k -k200=$k20$k20$k20$k20$k20$k20$k20$k20$k20$k20 - -# Be careful not to exceed max file name length (usu 512?). -# Doing so wouldn't affect GNU mkdir or GNU rm, but any tool that -# operates on the full pathname (like 'test') would choke. -k_deep=$k200$k200 - -t=t -# Create a directory in $t with lots of 'k' components. -deep=$t$k_deep -mkdir -p $deep || fail=1 - -# Make sure the deep dir was created. -test -d $deep || fail=1 - -rm -r $t || fail=1 - -# Make sure all of $t was deleted. -test -d $t && fail=1 - -Exit $fail diff --git a/tests/rm/deep-1.sh b/tests/rm/deep-1.sh new file mode 100755 index 000000000..f739eb594 --- /dev/null +++ b/tests/rm/deep-1.sh @@ -0,0 +1,53 @@ +#!/bin/sh +# Test "rm" with a deep hierarchy. + +# Copyright (C) 1997-2012 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# This is a bit of a torture test for mkdir -p, too. +# GNU rm performs *much* better on systems that have a d_type member +# in the directory structure because then it does only one stat per +# command line argument. + +# If this test takes too long on your system, blame the OS. + +. "${srcdir=.}/init.sh"; path_prepend_ ../src +print_ver_ rm + +umask 022 + + +k20=/k/k/k/k/k/k/k/k/k/k/k/k/k/k/k/k/k/k/k/k +k200=$k20$k20$k20$k20$k20$k20$k20$k20$k20$k20 + +# Be careful not to exceed max file name length (usu 512?). +# Doing so wouldn't affect GNU mkdir or GNU rm, but any tool that +# operates on the full pathname (like 'test') would choke. +k_deep=$k200$k200 + +t=t +# Create a directory in $t with lots of 'k' components. +deep=$t$k_deep +mkdir -p $deep || fail=1 + +# Make sure the deep dir was created. +test -d $deep || fail=1 + +rm -r $t || fail=1 + +# Make sure all of $t was deleted. +test -d $t && fail=1 + +Exit $fail diff --git a/tests/rm/deep-2 b/tests/rm/deep-2 deleted file mode 100755 index 266097741..000000000 --- a/tests/rm/deep-2 +++ /dev/null @@ -1,49 +0,0 @@ -#!/bin/sh -# Ensure rm -r DIR does not prompt for very long full relative names in DIR. - -# Copyright (C) 2008-2012 Free Software Foundation, Inc. - -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -. "${srcdir=.}/init.sh"; path_prepend_ ../src -print_ver_ rm -require_perl_ - -# Root can run this test, but it always succeeds, since for root, all -# files are writable, and write_protected_non_symlink never reaches -# the offending euidaccess_stat call. -skip_if_root_ - -mkdir x || framework_failure_ -cd x || framework_failure_ - -# Construct a hierarchy containing a relative file with a long name -: ${PERL=perl} -$PERL \ - -e 'my $d = "x" x 200; foreach my $i (1..52)' \ - -e ' { mkdir ($d, 0700) && chdir $d or die "$!" }' \ - || framework_failure_ - -cd .. || framework_failure_ -echo n > no || framework_failure_ - -rm ---presume-input-tty -r x < no > out || fail=1 - -# expect empty output -test -s out && fail=1 - -# the directory must have been removed -test -d x && fail=1 - -Exit $fail diff --git a/tests/rm/deep-2.sh b/tests/rm/deep-2.sh new file mode 100755 index 000000000..266097741 --- /dev/null +++ b/tests/rm/deep-2.sh @@ -0,0 +1,49 @@ +#!/bin/sh +# Ensure rm -r DIR does not prompt for very long full relative names in DIR. + +# Copyright (C) 2008-2012 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +. "${srcdir=.}/init.sh"; path_prepend_ ../src +print_ver_ rm +require_perl_ + +# Root can run this test, but it always succeeds, since for root, all +# files are writable, and write_protected_non_symlink never reaches +# the offending euidaccess_stat call. +skip_if_root_ + +mkdir x || framework_failure_ +cd x || framework_failure_ + +# Construct a hierarchy containing a relative file with a long name +: ${PERL=perl} +$PERL \ + -e 'my $d = "x" x 200; foreach my $i (1..52)' \ + -e ' { mkdir ($d, 0700) && chdir $d or die "$!" }' \ + || framework_failure_ + +cd .. || framework_failure_ +echo n > no || framework_failure_ + +rm ---presume-input-tty -r x < no > out || fail=1 + +# expect empty output +test -s out && fail=1 + +# the directory must have been removed +test -d x && fail=1 + +Exit $fail diff --git a/tests/rm/dir-no-w b/tests/rm/dir-no-w deleted file mode 100755 index ce33b98e5..000000000 --- a/tests/rm/dir-no-w +++ /dev/null @@ -1,42 +0,0 @@ -#!/bin/sh -# rm (without -r) must give a diagnostic for any directory. -# It must not prompt, even if that directory is unwritable. - -# Copyright (C) 2003-2012 Free Software Foundation, Inc. - -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -. "${srcdir=.}/init.sh"; path_prepend_ ../src -print_ver_ rm - -mkdir --mode=0500 unwritable-dir || framework_failure_ - - -# For rm from coreutils-5.0.1, this would prompt. -rm ---presume-input-tty unwritable-dir < /dev/null > out-t 2>&1 && fail=1 -cat <<\EOF > exp || fail=1 -rm: cannot remove 'unwritable-dir': Is a directory -EOF - -# When run by a non-privileged user we get this: -# rm: cannot remove directory 'unwritable-dir': Is a directory -# When run by root we get this: -# rm: cannot remove 'unwritable-dir': Is a directory -# Normalize the message. -sed 's/remove directory/remove/' out-t > out -rm -f out-t - -compare exp out || fail=1 - -Exit $fail diff --git a/tests/rm/dir-no-w.sh b/tests/rm/dir-no-w.sh new file mode 100755 index 000000000..ce33b98e5 --- /dev/null +++ b/tests/rm/dir-no-w.sh @@ -0,0 +1,42 @@ +#!/bin/sh +# rm (without -r) must give a diagnostic for any directory. +# It must not prompt, even if that directory is unwritable. + +# Copyright (C) 2003-2012 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +. "${srcdir=.}/init.sh"; path_prepend_ ../src +print_ver_ rm + +mkdir --mode=0500 unwritable-dir || framework_failure_ + + +# For rm from coreutils-5.0.1, this would prompt. +rm ---presume-input-tty unwritable-dir < /dev/null > out-t 2>&1 && fail=1 +cat <<\EOF > exp || fail=1 +rm: cannot remove 'unwritable-dir': Is a directory +EOF + +# When run by a non-privileged user we get this: +# rm: cannot remove directory 'unwritable-dir': Is a directory +# When run by root we get this: +# rm: cannot remove 'unwritable-dir': Is a directory +# Normalize the message. +sed 's/remove directory/remove/' out-t > out +rm -f out-t + +compare exp out || fail=1 + +Exit $fail diff --git a/tests/rm/dir-nonrecur b/tests/rm/dir-nonrecur deleted file mode 100755 index 8876e9458..000000000 --- a/tests/rm/dir-nonrecur +++ /dev/null @@ -1,34 +0,0 @@ -#!/bin/sh -# Ensure that 'rm dir' (i.e., without --recursive) gives a reasonable -# diagnostic when failing. - -# Copyright (C) 2005-2012 Free Software Foundation, Inc. - -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -. "${srcdir=.}/init.sh"; path_prepend_ ../src -print_ver_ rm - -mkdir d || framework_failure_ - - -rm d 2> out && fail=1 -cat <<\EOF > exp || fail=1 -rm: cannot remove 'd': Is a directory -EOF - -# Before coreutils-5.93 this test would fail on Solaris 9 and newer. -compare exp out || fail=1 - -Exit $fail diff --git a/tests/rm/dir-nonrecur.sh b/tests/rm/dir-nonrecur.sh new file mode 100755 index 000000000..8876e9458 --- /dev/null +++ b/tests/rm/dir-nonrecur.sh @@ -0,0 +1,34 @@ +#!/bin/sh +# Ensure that 'rm dir' (i.e., without --recursive) gives a reasonable +# diagnostic when failing. + +# Copyright (C) 2005-2012 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +. "${srcdir=.}/init.sh"; path_prepend_ ../src +print_ver_ rm + +mkdir d || framework_failure_ + + +rm d 2> out && fail=1 +cat <<\EOF > exp || fail=1 +rm: cannot remove 'd': Is a directory +EOF + +# Before coreutils-5.93 this test would fail on Solaris 9 and newer. +compare exp out || fail=1 + +Exit $fail diff --git a/tests/rm/dot-rel b/tests/rm/dot-rel deleted file mode 100755 index fc693596a..000000000 --- a/tests/rm/dot-rel +++ /dev/null @@ -1,29 +0,0 @@ -#!/bin/sh -# Use rm -r to remove two non-empty dot-relative directories. -# This would have failed between 2004-10-18 and 2004-10-21. - -# Copyright (C) 2004-2012 Free Software Foundation, Inc. - -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -. "${srcdir=.}/init.sh"; path_prepend_ ../src -print_ver_ rm - -mkdir a b || framework_failure_ -touch a/f b/f || framework_failure_ - - -rm -r a b || fail=1 - -Exit $fail diff --git a/tests/rm/dot-rel.sh b/tests/rm/dot-rel.sh new file mode 100755 index 000000000..fc693596a --- /dev/null +++ b/tests/rm/dot-rel.sh @@ -0,0 +1,29 @@ +#!/bin/sh +# Use rm -r to remove two non-empty dot-relative directories. +# This would have failed between 2004-10-18 and 2004-10-21. + +# Copyright (C) 2004-2012 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +. "${srcdir=.}/init.sh"; path_prepend_ ../src +print_ver_ rm + +mkdir a b || framework_failure_ +touch a/f b/f || framework_failure_ + + +rm -r a b || fail=1 + +Exit $fail diff --git a/tests/rm/empty-inacc b/tests/rm/empty-inacc deleted file mode 100755 index e23cb8553..000000000 --- a/tests/rm/empty-inacc +++ /dev/null @@ -1,38 +0,0 @@ -#!/bin/sh -# Ensure that rm -rf removes an empty-and-inaccessible directory. - -# Copyright (C) 2006-2012 Free Software Foundation, Inc. - -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -. "${srcdir=.}/init.sh"; path_prepend_ ../src -print_ver_ rm -skip_if_root_ - -mkdir -m0 inacc || framework_failure_ - -# Also exercise the different code path that's taken for a directory -# that is empty (hence removable) and unreadable. -mkdir -m a-r -p a/unreadable - - -# This would fail for e.g., coreutils-5.93. -rm -rf inacc || fail=1 -test -d inacc && fail=1 - -# This would fail for e.g., coreutils-5.97. -rm -rf a || fail=1 -test -d a && fail=1 - -Exit $fail diff --git a/tests/rm/empty-inacc.sh b/tests/rm/empty-inacc.sh new file mode 100755 index 000000000..e23cb8553 --- /dev/null +++ b/tests/rm/empty-inacc.sh @@ -0,0 +1,38 @@ +#!/bin/sh +# Ensure that rm -rf removes an empty-and-inaccessible directory. + +# Copyright (C) 2006-2012 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +. "${srcdir=.}/init.sh"; path_prepend_ ../src +print_ver_ rm +skip_if_root_ + +mkdir -m0 inacc || framework_failure_ + +# Also exercise the different code path that's taken for a directory +# that is empty (hence removable) and unreadable. +mkdir -m a-r -p a/unreadable + + +# This would fail for e.g., coreutils-5.93. +rm -rf inacc || fail=1 +test -d inacc && fail=1 + +# This would fail for e.g., coreutils-5.97. +rm -rf a || fail=1 +test -d a && fail=1 + +Exit $fail diff --git a/tests/rm/empty-name b/tests/rm/empty-name deleted file mode 100755 index b609170dc..000000000 --- a/tests/rm/empty-name +++ /dev/null @@ -1,60 +0,0 @@ -#!/usr/bin/perl -# Make sure that rm -r '' fails. - -# Copyright (C) 1998-2012 Free Software Foundation, Inc. - -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -# On SunOS 4.1.3, running rm -r '' in a nonempty directory may -# actually remove files with names of entries in the current directory -# but relative to '/' rather than relative to the current directory. - -use strict; - -(my $program_name = $0) =~ s|.*/||; - -# Turn off localization of executable's output. -@ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3; - -my $prog = 'rm'; - -# FIXME: copied from misc/ls-misc; factor into Coreutils.pm? -sub mk_file(@) -{ - foreach my $f (@_) - { - open (F, '>', $f) && close F - or die "creating $f: $!\n"; - } -} - -my @Tests = - ( - # test-name options input expected-output - # - ['empty-name-1', "''", {EXIT => 1}, - {ERR => "$prog: cannot remove '': No such file or directory\n"}], - - ['empty-name-2', "a '' b", {EXIT => 1}, - {ERR => "$prog: cannot remove '': No such file or directory\n"}, - {PRE => sub { mk_file qw(a b) }}, - {POST => sub {-f 'a' || -f 'b' and die "a or b remain\n" }}, - ], - ); - -my $save_temps = $ENV{SAVE_TEMPS}; -my $verbose = $ENV{VERBOSE}; - -my $fail = run_tests ($program_name, $prog, \@Tests, $save_temps, $verbose); -exit $fail; diff --git a/tests/rm/empty-name.pl b/tests/rm/empty-name.pl new file mode 100755 index 000000000..b609170dc --- /dev/null +++ b/tests/rm/empty-name.pl @@ -0,0 +1,60 @@ +#!/usr/bin/perl +# Make sure that rm -r '' fails. + +# Copyright (C) 1998-2012 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# On SunOS 4.1.3, running rm -r '' in a nonempty directory may +# actually remove files with names of entries in the current directory +# but relative to '/' rather than relative to the current directory. + +use strict; + +(my $program_name = $0) =~ s|.*/||; + +# Turn off localization of executable's output. +@ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3; + +my $prog = 'rm'; + +# FIXME: copied from misc/ls-misc; factor into Coreutils.pm? +sub mk_file(@) +{ + foreach my $f (@_) + { + open (F, '>', $f) && close F + or die "creating $f: $!\n"; + } +} + +my @Tests = + ( + # test-name options input expected-output + # + ['empty-name-1', "''", {EXIT => 1}, + {ERR => "$prog: cannot remove '': No such file or directory\n"}], + + ['empty-name-2', "a '' b", {EXIT => 1}, + {ERR => "$prog: cannot remove '': No such file or directory\n"}, + {PRE => sub { mk_file qw(a b) }}, + {POST => sub {-f 'a' || -f 'b' and die "a or b remain\n" }}, + ], + ); + +my $save_temps = $ENV{SAVE_TEMPS}; +my $verbose = $ENV{VERBOSE}; + +my $fail = run_tests ($program_name, $prog, \@Tests, $save_temps, $verbose); +exit $fail; diff --git a/tests/rm/ext3-perf b/tests/rm/ext3-perf deleted file mode 100755 index 97b0a17b3..000000000 --- a/tests/rm/ext3-perf +++ /dev/null @@ -1,83 +0,0 @@ -#!/bin/sh -# ensure that "rm -rf DIR-with-many-entries" is not O(N^2) - -# Copyright (C) 2008-2012 Free Software Foundation, Inc. - -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -. "${srcdir=.}/init.sh"; path_prepend_ ../src -print_ver_ rm - -very_expensive_ - -# Using rm -rf to remove a 400k-entry directory takes: -# - 9 seconds with the patch, on a 2-yr-old system -# - 350 seconds without the patch, on a high-end system (disk 20-30% faster) -threshold_seconds=60 - -# The number of entries in our test directory. -n=400000 - -# Choose a value that is large enough to ensure an accidentally -# regressed rm would require much longer than $threshold_seconds to remove -# the directory. With n=400k, pre-patch GNU rm would require about 350 -# seconds even on a fast disk. On a relatively modern system, the -# patched version of rm requires about 10 seconds, so even if you -# choose to enable very expensive tests with a disk that is much slower, -# the test should still succeed. - -# Skip unless "." is on an ext[34] file system. -# FIXME-maybe: try to find a suitable file system or allow -# the user to specify it via an envvar. -df -T -t ext3 -t ext4dev -t ext4 . \ - || skip_ 'this test runs only on an ext3 or ext4 file system' - -# Skip if there are too few inodes free. Require some slack. -free_inodes=$(stat -f --format=%d .) || framework_failure_ -min_free_inodes=$(expr 12 \* $n / 10) -test $min_free_inodes -lt $free_inodes \ - || skip_ "too few free inodes on '.': $free_inodes;" \ - "this test requires at least $min_free_inodes" - -ok=0 -start=$(date +%s) -mkdir d && - cd d && - seq $n | xargs touch && - test -f 1 && - test -f $n && - cd .. && - ok=1 -test $ok = 1 || framework_failure_ -setup_duration=$(expr $(date +%s) - $start) -echo creating a $n-entry directory took $setup_duration seconds - -# If set-up took longer than the default $threshold_seconds, -# use the longer set-up duration as the limit. -test $threshold_seconds -lt $setup_duration \ - && threshold_seconds=$setup_duration - -start=$(date +%s) -timeout ${threshold_seconds}s rm -rf d; err=$? -duration=$(expr $(date +%s) - $start) - -case $err in - 124) fail=1; echo rm took longer than $threshold_seconds seconds;; - 0) ;; - *) fail=1;; -esac - -echo removing a $n-entry directory took $duration seconds - -Exit $fail diff --git a/tests/rm/ext3-perf.sh b/tests/rm/ext3-perf.sh new file mode 100755 index 000000000..97b0a17b3 --- /dev/null +++ b/tests/rm/ext3-perf.sh @@ -0,0 +1,83 @@ +#!/bin/sh +# ensure that "rm -rf DIR-with-many-entries" is not O(N^2) + +# Copyright (C) 2008-2012 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +. "${srcdir=.}/init.sh"; path_prepend_ ../src +print_ver_ rm + +very_expensive_ + +# Using rm -rf to remove a 400k-entry directory takes: +# - 9 seconds with the patch, on a 2-yr-old system +# - 350 seconds without the patch, on a high-end system (disk 20-30% faster) +threshold_seconds=60 + +# The number of entries in our test directory. +n=400000 + +# Choose a value that is large enough to ensure an accidentally +# regressed rm would require much longer than $threshold_seconds to remove +# the directory. With n=400k, pre-patch GNU rm would require about 350 +# seconds even on a fast disk. On a relatively modern system, the +# patched version of rm requires about 10 seconds, so even if you +# choose to enable very expensive tests with a disk that is much slower, +# the test should still succeed. + +# Skip unless "." is on an ext[34] file system. +# FIXME-maybe: try to find a suitable file system or allow +# the user to specify it via an envvar. +df -T -t ext3 -t ext4dev -t ext4 . \ + || skip_ 'this test runs only on an ext3 or ext4 file system' + +# Skip if there are too few inodes free. Require some slack. +free_inodes=$(stat -f --format=%d .) || framework_failure_ +min_free_inodes=$(expr 12 \* $n / 10) +test $min_free_inodes -lt $free_inodes \ + || skip_ "too few free inodes on '.': $free_inodes;" \ + "this test requires at least $min_free_inodes" + +ok=0 +start=$(date +%s) +mkdir d && + cd d && + seq $n | xargs touch && + test -f 1 && + test -f $n && + cd .. && + ok=1 +test $ok = 1 || framework_failure_ +setup_duration=$(expr $(date +%s) - $start) +echo creating a $n-entry directory took $setup_duration seconds + +# If set-up took longer than the default $threshold_seconds, +# use the longer set-up duration as the limit. +test $threshold_seconds -lt $setup_duration \ + && threshold_seconds=$setup_duration + +start=$(date +%s) +timeout ${threshold_seconds}s rm -rf d; err=$? +duration=$(expr $(date +%s) - $start) + +case $err in + 124) fail=1; echo rm took longer than $threshold_seconds seconds;; + 0) ;; + *) fail=1;; +esac + +echo removing a $n-entry directory took $duration seconds + +Exit $fail diff --git a/tests/rm/f-1 b/tests/rm/f-1 deleted file mode 100755 index e1ed8d4fa..000000000 --- a/tests/rm/f-1 +++ /dev/null @@ -1,26 +0,0 @@ -#!/bin/sh -# Test "rm -f" with a nonexistent file. - -# Copyright (C) 1997-2012 Free Software Foundation, Inc. - -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -. "${srcdir=.}/init.sh"; path_prepend_ ../src -print_ver_ rm - -mkdir -p d || framework_failure_ - -rm -f d/no-such-file || fail=1 - -Exit $fail diff --git a/tests/rm/f-1.sh b/tests/rm/f-1.sh new file mode 100755 index 000000000..e1ed8d4fa --- /dev/null +++ b/tests/rm/f-1.sh @@ -0,0 +1,26 @@ +#!/bin/sh +# Test "rm -f" with a nonexistent file. + +# Copyright (C) 1997-2012 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +. "${srcdir=.}/init.sh"; path_prepend_ ../src +print_ver_ rm + +mkdir -p d || framework_failure_ + +rm -f d/no-such-file || fail=1 + +Exit $fail diff --git a/tests/rm/fail-2eperm b/tests/rm/fail-2eperm deleted file mode 100755 index fa2f43227..000000000 --- a/tests/rm/fail-2eperm +++ /dev/null @@ -1,55 +0,0 @@ -#!/bin/sh -# Like fail-eperm, but the failure must be for a file encountered -# while trying to remove the containing directory with the sticky bit set. - -# Copyright (C) 2003-2012 Free Software Foundation, Inc. - -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -. "${srcdir=.}/init.sh"; path_prepend_ ../src -print_ver_ rm -require_root_ - -# The containing directory must be owned by the user who eventually runs rm. -chown $NON_ROOT_USERNAME . - -mkdir a || framework_failure_ -chmod 1777 a || framework_failure_ -touch a/b || framework_failure_ - - -# Try to ensure that $NON_ROOT_USERNAME can access -# the required version of rm. -rm_version=$( - setuidgid $NON_ROOT_USERNAME env PATH="$PATH" rm --version | - sed -n '1s/.* //p' -) -case $rm_version in - $PACKAGE_VERSION) ;; - *) skip_ "cannot access just-built rm as user $NON_ROOT_USERNAME";; -esac -setuidgid $NON_ROOT_USERNAME env PATH="$PATH" rm -rf a 2> out-t && fail=1 - -# On some systems, we get 'Not owner'. Convert it. -# On other systems (HPUX), we get 'Permission denied'. Convert it, too. -onp='Operation not permitted' -sed "s/Not owner/$onp/;s/Permission denied/$onp/" out-t > out - -cat <<\EOF > exp -rm: cannot remove 'a/b': Operation not permitted -EOF - -compare exp out || fail=1 - -Exit $fail diff --git a/tests/rm/fail-2eperm.sh b/tests/rm/fail-2eperm.sh new file mode 100755 index 000000000..fa2f43227 --- /dev/null +++ b/tests/rm/fail-2eperm.sh @@ -0,0 +1,55 @@ +#!/bin/sh +# Like fail-eperm, but the failure must be for a file encountered +# while trying to remove the containing directory with the sticky bit set. + +# Copyright (C) 2003-2012 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +. "${srcdir=.}/init.sh"; path_prepend_ ../src +print_ver_ rm +require_root_ + +# The containing directory must be owned by the user who eventually runs rm. +chown $NON_ROOT_USERNAME . + +mkdir a || framework_failure_ +chmod 1777 a || framework_failure_ +touch a/b || framework_failure_ + + +# Try to ensure that $NON_ROOT_USERNAME can access +# the required version of rm. +rm_version=$( + setuidgid $NON_ROOT_USERNAME env PATH="$PATH" rm --version | + sed -n '1s/.* //p' +) +case $rm_version in + $PACKAGE_VERSION) ;; + *) skip_ "cannot access just-built rm as user $NON_ROOT_USERNAME";; +esac +setuidgid $NON_ROOT_USERNAME env PATH="$PATH" rm -rf a 2> out-t && fail=1 + +# On some systems, we get 'Not owner'. Convert it. +# On other systems (HPUX), we get 'Permission denied'. Convert it, too. +onp='Operation not permitted' +sed "s/Not owner/$onp/;s/Permission denied/$onp/" out-t > out + +cat <<\EOF > exp +rm: cannot remove 'a/b': Operation not permitted +EOF + +compare exp out || fail=1 + +Exit $fail diff --git a/tests/rm/fail-eacces b/tests/rm/fail-eacces deleted file mode 100755 index 947dfac36..000000000 --- a/tests/rm/fail-eacces +++ /dev/null @@ -1,54 +0,0 @@ -#!/bin/sh -# Ensure that rm -rf unremovable-non-dir gives a diagnostic. -# Test both a regular file and a symlink -- it makes a difference to rm. -# With the symlink, rm from coreutils-6.9 would fail with a misleading -# ELOOP diagnostic. - -# Copyright (C) 2006-2012 Free Software Foundation, Inc. - -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -. "${srcdir=.}/init.sh"; path_prepend_ ../src -print_ver_ rm -skip_if_root_ - -ok=0 -mkdir d && - touch d/f && - ln -s f d/slink && - chmod a-w d && - ok=1 -test $ok = 1 || framework_failure_ - -mkdir e && - ln -s f e/slink && - chmod a-w e && - ok=1 -test $ok = 1 || framework_failure_ - - -rm -rf d/f 2> out && fail=1 -cat <<\EOF > exp -rm: cannot remove 'd/f': Permission denied -EOF -compare exp out || fail=1 - -# This used to fail with ELOOP. -rm -rf e 2> out && fail=1 -cat <<\EOF > exp -rm: cannot remove 'e/slink': Permission denied -EOF -compare exp out || fail=1 - -Exit $fail diff --git a/tests/rm/fail-eacces.sh b/tests/rm/fail-eacces.sh new file mode 100755 index 000000000..947dfac36 --- /dev/null +++ b/tests/rm/fail-eacces.sh @@ -0,0 +1,54 @@ +#!/bin/sh +# Ensure that rm -rf unremovable-non-dir gives a diagnostic. +# Test both a regular file and a symlink -- it makes a difference to rm. +# With the symlink, rm from coreutils-6.9 would fail with a misleading +# ELOOP diagnostic. + +# Copyright (C) 2006-2012 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +. "${srcdir=.}/init.sh"; path_prepend_ ../src +print_ver_ rm +skip_if_root_ + +ok=0 +mkdir d && + touch d/f && + ln -s f d/slink && + chmod a-w d && + ok=1 +test $ok = 1 || framework_failure_ + +mkdir e && + ln -s f e/slink && + chmod a-w e && + ok=1 +test $ok = 1 || framework_failure_ + + +rm -rf d/f 2> out && fail=1 +cat <<\EOF > exp +rm: cannot remove 'd/f': Permission denied +EOF +compare exp out || fail=1 + +# This used to fail with ELOOP. +rm -rf e 2> out && fail=1 +cat <<\EOF > exp +rm: cannot remove 'e/slink': Permission denied +EOF +compare exp out || fail=1 + +Exit $fail diff --git a/tests/rm/hash b/tests/rm/hash deleted file mode 100755 index 344325e13..000000000 --- a/tests/rm/hash +++ /dev/null @@ -1,37 +0,0 @@ -#!/bin/sh -# Exercise a bug that was fixed in 4.0s. -# Before then, rm would fail occasionally, sometimes via -# a failed assertion, others with a seg fault. - -# Copyright (C) 2000-2012 Free Software Foundation, Inc. - -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -. "${srcdir=.}/init.sh"; path_prepend_ ../src -print_ver_ rm -expensive_ - -# Create a hierarchy with 3*26 leaf directories, each at depth 153. -echo "$0: creating 78 trees, each of depth 153; this will take a while..." >&2 -y=$(seq 1 150|tr -sc '\n' y|tr '\n' /) -for i in 1 2 3; do - for j in a b c d e f g h i j k l m n o p q r s t u v w x y z; do - mkdir -p t/$i/$j/$y || framework_failure_ - done -done - - -rm -r t || fail=1 - -Exit $fail diff --git a/tests/rm/hash.sh b/tests/rm/hash.sh new file mode 100755 index 000000000..344325e13 --- /dev/null +++ b/tests/rm/hash.sh @@ -0,0 +1,37 @@ +#!/bin/sh +# Exercise a bug that was fixed in 4.0s. +# Before then, rm would fail occasionally, sometimes via +# a failed assertion, others with a seg fault. + +# Copyright (C) 2000-2012 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +. "${srcdir=.}/init.sh"; path_prepend_ ../src +print_ver_ rm +expensive_ + +# Create a hierarchy with 3*26 leaf directories, each at depth 153. +echo "$0: creating 78 trees, each of depth 153; this will take a while..." >&2 +y=$(seq 1 150|tr -sc '\n' y|tr '\n' /) +for i in 1 2 3; do + for j in a b c d e f g h i j k l m n o p q r s t u v w x y z; do + mkdir -p t/$i/$j/$y || framework_failure_ + done +done + + +rm -r t || fail=1 + +Exit $fail diff --git a/tests/rm/i-1 b/tests/rm/i-1 deleted file mode 100755 index 67df853f5..000000000 --- a/tests/rm/i-1 +++ /dev/null @@ -1,40 +0,0 @@ -#!/bin/sh -# Test "rm -i". - -# Copyright (C) 1997-2012 Free Software Foundation, Inc. - -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -. "${srcdir=.}/init.sh"; path_prepend_ ../src -print_ver_ rm - -t=t -mkdir -p $t || framework_failure_ -echo > $t/a || framework_failure_ -test -f $t/a || framework_failure_ - -echo y > $t/in-y -echo n > $t/in-n - -rm -i $t/a < $t/in-n > /dev/null 2>&1 || fail=1 -# The file should not have been removed. -test -f $t/a || fail=1 - -rm -i $t/a < $t/in-y > /dev/null 2>&1 || fail=1 -# The file should have been removed this time. -test -f $t/a && fail=1 - -rm -rf $t - -Exit $fail diff --git a/tests/rm/i-1.sh b/tests/rm/i-1.sh new file mode 100755 index 000000000..67df853f5 --- /dev/null +++ b/tests/rm/i-1.sh @@ -0,0 +1,40 @@ +#!/bin/sh +# Test "rm -i". + +# Copyright (C) 1997-2012 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +. "${srcdir=.}/init.sh"; path_prepend_ ../src +print_ver_ rm + +t=t +mkdir -p $t || framework_failure_ +echo > $t/a || framework_failure_ +test -f $t/a || framework_failure_ + +echo y > $t/in-y +echo n > $t/in-n + +rm -i $t/a < $t/in-n > /dev/null 2>&1 || fail=1 +# The file should not have been removed. +test -f $t/a || fail=1 + +rm -i $t/a < $t/in-y > /dev/null 2>&1 || fail=1 +# The file should have been removed this time. +test -f $t/a && fail=1 + +rm -rf $t + +Exit $fail diff --git a/tests/rm/i-never b/tests/rm/i-never deleted file mode 100755 index 80e1fcd98..000000000 --- a/tests/rm/i-never +++ /dev/null @@ -1,33 +0,0 @@ -#!/bin/sh -# Ensure that rm --interactive=never works does not prompt, even for -# an unwritable file. - -# Copyright (C) 2007-2012 Free Software Foundation, Inc. - -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -. "${srcdir=.}/init.sh"; path_prepend_ ../src -print_ver_ rm -skip_if_root_ - -touch f || framework_failure_ -chmod 0 f || framework_failure_ -touch exp || framework_failure_ - - -rm --interactive=never f > out || fail=1 - -compare exp out || fail=1 - -Exit $fail diff --git a/tests/rm/i-never.sh b/tests/rm/i-never.sh new file mode 100755 index 000000000..80e1fcd98 --- /dev/null +++ b/tests/rm/i-never.sh @@ -0,0 +1,33 @@ +#!/bin/sh +# Ensure that rm --interactive=never works does not prompt, even for +# an unwritable file. + +# Copyright (C) 2007-2012 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +. "${srcdir=.}/init.sh"; path_prepend_ ../src +print_ver_ rm +skip_if_root_ + +touch f || framework_failure_ +chmod 0 f || framework_failure_ +touch exp || framework_failure_ + + +rm --interactive=never f > out || fail=1 + +compare exp out || fail=1 + +Exit $fail diff --git a/tests/rm/i-no-r b/tests/rm/i-no-r deleted file mode 100755 index 6b22e1ca1..000000000 --- a/tests/rm/i-no-r +++ /dev/null @@ -1,34 +0,0 @@ -#!/bin/sh -# Since the rewrite for fileutils-4.1.9, 'rm -i DIR' would mistakenly -# recurse into directory DIR. rm -i (without -r) must fail in that case. -# Fixed in coreutils-4.5.2. - -# Copyright (C) 2002-2012 Free Software Foundation, Inc. - -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -. "${srcdir=.}/init.sh"; path_prepend_ ../src -print_ver_ rm - -mkdir dir || framework_failure_ -echo y > y || framework_failure_ - - -# This must fail. -rm -i dir < y > /dev/null 2>&1 && fail=1 - -# The directory must remain. -test -d dir || fail=1 - -Exit $fail diff --git a/tests/rm/i-no-r.sh b/tests/rm/i-no-r.sh new file mode 100755 index 000000000..6b22e1ca1 --- /dev/null +++ b/tests/rm/i-no-r.sh @@ -0,0 +1,34 @@ +#!/bin/sh +# Since the rewrite for fileutils-4.1.9, 'rm -i DIR' would mistakenly +# recurse into directory DIR. rm -i (without -r) must fail in that case. +# Fixed in coreutils-4.5.2. + +# Copyright (C) 2002-2012 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +. "${srcdir=.}/init.sh"; path_prepend_ ../src +print_ver_ rm + +mkdir dir || framework_failure_ +echo y > y || framework_failure_ + + +# This must fail. +rm -i dir < y > /dev/null 2>&1 && fail=1 + +# The directory must remain. +test -d dir || fail=1 + +Exit $fail diff --git a/tests/rm/ignorable b/tests/rm/ignorable deleted file mode 100755 index bcf3b7eb9..000000000 --- a/tests/rm/ignorable +++ /dev/null @@ -1,30 +0,0 @@ -#!/bin/sh -# Ensure that rm -f existing-non-dir/anything exits successfully - -# Copyright (C) 2006-2012 Free Software Foundation, Inc. - -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -. "${srcdir=.}/init.sh"; path_prepend_ ../src -print_ver_ rm -skip_if_root_ - -touch existing-non-dir || framework_failure_ - - -# With coreutils-6.3, this would exit nonzero. It should not. -# Example from Andreas Schwab. -rm -f existing-non-dir/f > out 2>&1 || fail=1 - -Exit $fail diff --git a/tests/rm/ignorable.sh b/tests/rm/ignorable.sh new file mode 100755 index 000000000..bcf3b7eb9 --- /dev/null +++ b/tests/rm/ignorable.sh @@ -0,0 +1,30 @@ +#!/bin/sh +# Ensure that rm -f existing-non-dir/anything exits successfully + +# Copyright (C) 2006-2012 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +. "${srcdir=.}/init.sh"; path_prepend_ ../src +print_ver_ rm +skip_if_root_ + +touch existing-non-dir || framework_failure_ + + +# With coreutils-6.3, this would exit nonzero. It should not. +# Example from Andreas Schwab. +rm -f existing-non-dir/f > out 2>&1 || fail=1 + +Exit $fail diff --git a/tests/rm/inaccessible b/tests/rm/inaccessible deleted file mode 100755 index 2f045815e..000000000 --- a/tests/rm/inaccessible +++ /dev/null @@ -1,49 +0,0 @@ -#!/bin/sh -# Ensure that rm works even when run from a directory -# for which the user has no access at all. - -# Copyright (C) 2004-2012 Free Software Foundation, Inc. - -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -. "${srcdir=.}/init.sh"; path_prepend_ ../src -print_ver_ rm - -# Skip this test if your system has neither the openat-style functions -# nor /proc/self/fd support with which to emulate them. -require_openat_support_ -skip_if_root_ - -p=$(pwd) -mkdir abs1 abs2 no-access || framework_failure_ - - -set +x -(cd no-access; chmod 0 . && rm -r "$p/abs1" rel "$p/abs2") 2> out && fail=1 -test -d "$p/abs1" && fail=1 -test -d "$p/abs2" && fail=1 - -cat <<\EOF > exp || fail=1 -rm: cannot remove 'rel': Permission denied -EOF - -# AIX 4.3.3 fails with a different diagnostic. -# Transform their diagnostic -# ...: The file access permissions do not allow the specified action. -# to the expected one: -sed 's/: The file access permissions.*/: Permission denied/'o1;mv o1 out - -compare exp out || fail=1 - -Exit $fail diff --git a/tests/rm/inaccessible.sh b/tests/rm/inaccessible.sh new file mode 100755 index 000000000..2f045815e --- /dev/null +++ b/tests/rm/inaccessible.sh @@ -0,0 +1,49 @@ +#!/bin/sh +# Ensure that rm works even when run from a directory +# for which the user has no access at all. + +# Copyright (C) 2004-2012 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +. "${srcdir=.}/init.sh"; path_prepend_ ../src +print_ver_ rm + +# Skip this test if your system has neither the openat-style functions +# nor /proc/self/fd support with which to emulate them. +require_openat_support_ +skip_if_root_ + +p=$(pwd) +mkdir abs1 abs2 no-access || framework_failure_ + + +set +x +(cd no-access; chmod 0 . && rm -r "$p/abs1" rel "$p/abs2") 2> out && fail=1 +test -d "$p/abs1" && fail=1 +test -d "$p/abs2" && fail=1 + +cat <<\EOF > exp || fail=1 +rm: cannot remove 'rel': Permission denied +EOF + +# AIX 4.3.3 fails with a different diagnostic. +# Transform their diagnostic +# ...: The file access permissions do not allow the specified action. +# to the expected one: +sed 's/: The file access permissions.*/: Permission denied/'o1;mv o1 out + +compare exp out || fail=1 + +Exit $fail diff --git a/tests/rm/interactive-always b/tests/rm/interactive-always deleted file mode 100755 index 6312cba1c..000000000 --- a/tests/rm/interactive-always +++ /dev/null @@ -1,87 +0,0 @@ -#!/bin/sh -# Test the --interactive[=WHEN] changes added to coreutils 6.0 - -# Copyright (C) 2006-2012 Free Software Foundation, Inc. - -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -. "${srcdir=.}/init.sh"; path_prepend_ ../src -print_ver_ rm - -touch file1-1 file1-2 file2-1 file2-2 file3-1 file3-2 file4-1 file4-2 \ - || framework_failure_ -# If asked, answer no to first question, then yes to second. -echo 'n -y' > in || framework_failure_ -rm -f out err || framework_failure_ - - -# The prompt has a trailing space, and no newline, so an extra -# 'echo .' is inserted after each rm to make it obvious what was asked. - -echo 'no WHEN' > err || fail=1 -rm -R --interactive file1-* < in >> out 2>> err || fail=1 -echo . >> err || fail=1 -test -f file1-1 || fail=1 -test -f file1-2 && fail=1 - -echo 'WHEN=never' >> err || fail=1 -rm -R --interactive=never file2-* < in >> out 2>> err || fail=1 -echo . >> err || fail=1 -test -f file2-1 && fail=1 -test -f file2-2 && fail=1 - -echo 'WHEN=once' >> err || fail=1 -rm -R --interactive=once file3-* < in >> out 2>> err || fail=1 -echo . >> err || fail=1 -test -f file3-1 || fail=1 -test -f file3-2 || fail=1 - -echo 'WHEN=always' >> err || fail=1 -rm -R --interactive=always file4-* < in >> out 2>> err || fail=1 -echo . >> err || fail=1 -test -f file4-1 || fail=1 -test -f file4-2 && fail=1 - -echo '-f overrides --interactive' >> err || fail=1 -rm -R --interactive=once -f file1-* < in >> out 2>> err || fail=1 -echo . >> err || fail=1 -test -f file1-1 && fail=1 - -echo '--interactive overrides -f' >> err || fail=1 -rm -R -f --interactive=once file4-* < in >> out 2>> err || fail=1 -echo . >> err || fail=1 -test -f file4-1 || fail=1 - -cat <<\EOF > expout || fail=1 -EOF -sed 's/@remove_empty/rm: remove regular empty file/g' <<\EOF > experr || fail=1 -no WHEN -@remove_empty 'file1-1'? @remove_empty 'file1-2'? . -WHEN=never -. -WHEN=once -rm: remove all arguments recursively? . -WHEN=always -@remove_empty 'file4-1'? @remove_empty 'file4-2'? . --f overrides --interactive -. ---interactive overrides -f -rm: remove all arguments recursively? . -EOF - -compare expout out || fail=1 -compare experr err || fail=1 - -Exit $fail diff --git a/tests/rm/interactive-always.sh b/tests/rm/interactive-always.sh new file mode 100755 index 000000000..6312cba1c --- /dev/null +++ b/tests/rm/interactive-always.sh @@ -0,0 +1,87 @@ +#!/bin/sh +# Test the --interactive[=WHEN] changes added to coreutils 6.0 + +# Copyright (C) 2006-2012 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +. "${srcdir=.}/init.sh"; path_prepend_ ../src +print_ver_ rm + +touch file1-1 file1-2 file2-1 file2-2 file3-1 file3-2 file4-1 file4-2 \ + || framework_failure_ +# If asked, answer no to first question, then yes to second. +echo 'n +y' > in || framework_failure_ +rm -f out err || framework_failure_ + + +# The prompt has a trailing space, and no newline, so an extra +# 'echo .' is inserted after each rm to make it obvious what was asked. + +echo 'no WHEN' > err || fail=1 +rm -R --interactive file1-* < in >> out 2>> err || fail=1 +echo . >> err || fail=1 +test -f file1-1 || fail=1 +test -f file1-2 && fail=1 + +echo 'WHEN=never' >> err || fail=1 +rm -R --interactive=never file2-* < in >> out 2>> err || fail=1 +echo . >> err || fail=1 +test -f file2-1 && fail=1 +test -f file2-2 && fail=1 + +echo 'WHEN=once' >> err || fail=1 +rm -R --interactive=once file3-* < in >> out 2>> err || fail=1 +echo . >> err || fail=1 +test -f file3-1 || fail=1 +test -f file3-2 || fail=1 + +echo 'WHEN=always' >> err || fail=1 +rm -R --interactive=always file4-* < in >> out 2>> err || fail=1 +echo . >> err || fail=1 +test -f file4-1 || fail=1 +test -f file4-2 && fail=1 + +echo '-f overrides --interactive' >> err || fail=1 +rm -R --interactive=once -f file1-* < in >> out 2>> err || fail=1 +echo . >> err || fail=1 +test -f file1-1 && fail=1 + +echo '--interactive overrides -f' >> err || fail=1 +rm -R -f --interactive=once file4-* < in >> out 2>> err || fail=1 +echo . >> err || fail=1 +test -f file4-1 || fail=1 + +cat <<\EOF > expout || fail=1 +EOF +sed 's/@remove_empty/rm: remove regular empty file/g' <<\EOF > experr || fail=1 +no WHEN +@remove_empty 'file1-1'? @remove_empty 'file1-2'? . +WHEN=never +. +WHEN=once +rm: remove all arguments recursively? . +WHEN=always +@remove_empty 'file4-1'? @remove_empty 'file4-2'? . +-f overrides --interactive +. +--interactive overrides -f +rm: remove all arguments recursively? . +EOF + +compare expout out || fail=1 +compare experr err || fail=1 + +Exit $fail diff --git a/tests/rm/interactive-once b/tests/rm/interactive-once deleted file mode 100755 index 982d1a4d3..000000000 --- a/tests/rm/interactive-once +++ /dev/null @@ -1,107 +0,0 @@ -#!/bin/sh -# Test the -I option added to coreutils 6.0 - -# Copyright (C) 2006-2012 Free Software Foundation, Inc. - -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -. "${srcdir=.}/init.sh"; path_prepend_ ../src -print_ver_ rm - -mkdir -p dir1-1 dir2-1 dir2-2 || framework_failure_ -touch file1-1 file2-1 file2-2 file2-3 file3-1 file3-2 file3-3 file3-4 \ - || framework_failure_ -echo y > in-y || framework_failure_ -echo n > in-n || framework_failure_ -rm -f out err || framework_failure_ - - -# The prompt has a trailing space, and no newline, so an extra -# 'echo .' is inserted after each rm to make it obvious what was asked. - -echo 'one file, no recursion' > err || fail=1 -rm -I file1-* < in-n >> out 2>> err || fail=1 -echo . >> err || fail=1 -test -f file1-1 && fail=1 - -echo 'three files, no recursion' >> err || fail=1 -rm -I file2-* < in-n >> out 2>> err || fail=1 -echo . >> err || fail=1 -test -f file2-1 && fail=1 -test -f file2-2 && fail=1 -test -f file2-3 && fail=1 - -echo 'four files, no recursion, answer no' >> err || fail=1 -rm -I file3-* < in-n >> 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 - -echo 'four files, no recursion, answer yes' >> err || fail=1 -rm -I file3-* < in-y >> 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 - -echo 'one file, recursion, answer no' >> err || fail=1 -rm -I -R dir1-* < in-n >> out 2>> err || fail=1 -echo . >> err || fail=1 -test -d dir1-1 || fail=1 - -echo 'one file, recursion, answer yes' >> err || fail=1 -rm -I -R dir1-* < in-y >> out 2>> err || fail=1 -echo . >> err || fail=1 -test -d dir1-1 && fail=1 - -echo 'multiple files, recursion, answer no' >> err || fail=1 -rm -I -R dir2-* < in-n >> out 2>> err || fail=1 -echo . >> err || fail=1 -test -d dir2-1 || fail=1 -test -d dir2-2 || fail=1 - -echo 'multiple files, recursion, answer yes' >> err || fail=1 -rm -I -R dir2-* < in-y >> out 2>> err || fail=1 -echo . >> err || fail=1 -test -d dir2-1 && fail=1 -test -d dir2-2 && fail=1 - -cat <<\EOF > expout || fail=1 -EOF -cat <<\EOF > experr || fail=1 -one file, no recursion -. -three files, no recursion -. -four files, no recursion, answer no -rm: remove all arguments? . -four files, no recursion, answer yes -rm: remove all arguments? . -one file, recursion, answer no -rm: remove all arguments recursively? . -one file, recursion, answer yes -rm: remove all arguments recursively? . -multiple files, recursion, answer no -rm: remove all arguments recursively? . -multiple files, recursion, answer yes -rm: remove all arguments recursively? . -EOF - -compare expout out || fail=1 -compare experr err || fail=1 - -Exit $fail diff --git a/tests/rm/interactive-once.sh b/tests/rm/interactive-once.sh new file mode 100755 index 000000000..982d1a4d3 --- /dev/null +++ b/tests/rm/interactive-once.sh @@ -0,0 +1,107 @@ +#!/bin/sh +# Test the -I option added to coreutils 6.0 + +# Copyright (C) 2006-2012 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +. "${srcdir=.}/init.sh"; path_prepend_ ../src +print_ver_ rm + +mkdir -p dir1-1 dir2-1 dir2-2 || framework_failure_ +touch file1-1 file2-1 file2-2 file2-3 file3-1 file3-2 file3-3 file3-4 \ + || framework_failure_ +echo y > in-y || framework_failure_ +echo n > in-n || framework_failure_ +rm -f out err || framework_failure_ + + +# The prompt has a trailing space, and no newline, so an extra +# 'echo .' is inserted after each rm to make it obvious what was asked. + +echo 'one file, no recursion' > err || fail=1 +rm -I file1-* < in-n >> out 2>> err || fail=1 +echo . >> err || fail=1 +test -f file1-1 && fail=1 + +echo 'three files, no recursion' >> err || fail=1 +rm -I file2-* < in-n >> out 2>> err || fail=1 +echo . >> err || fail=1 +test -f file2-1 && fail=1 +test -f file2-2 && fail=1 +test -f file2-3 && fail=1 + +echo 'four files, no recursion, answer no' >> err || fail=1 +rm -I file3-* < in-n >> 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 + +echo 'four files, no recursion, answer yes' >> err || fail=1 +rm -I file3-* < in-y >> 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 + +echo 'one file, recursion, answer no' >> err || fail=1 +rm -I -R dir1-* < in-n >> out 2>> err || fail=1 +echo . >> err || fail=1 +test -d dir1-1 || fail=1 + +echo 'one file, recursion, answer yes' >> err || fail=1 +rm -I -R dir1-* < in-y >> out 2>> err || fail=1 +echo . >> err || fail=1 +test -d dir1-1 && fail=1 + +echo 'multiple files, recursion, answer no' >> err || fail=1 +rm -I -R dir2-* < in-n >> out 2>> err || fail=1 +echo . >> err || fail=1 +test -d dir2-1 || fail=1 +test -d dir2-2 || fail=1 + +echo 'multiple files, recursion, answer yes' >> err || fail=1 +rm -I -R dir2-* < in-y >> out 2>> err || fail=1 +echo . >> err || fail=1 +test -d dir2-1 && fail=1 +test -d dir2-2 && fail=1 + +cat <<\EOF > expout || fail=1 +EOF +cat <<\EOF > experr || fail=1 +one file, no recursion +. +three files, no recursion +. +four files, no recursion, answer no +rm: remove all arguments? . +four files, no recursion, answer yes +rm: remove all arguments? . +one file, recursion, answer no +rm: remove all arguments recursively? . +one file, recursion, answer yes +rm: remove all arguments recursively? . +multiple files, recursion, answer no +rm: remove all arguments recursively? . +multiple files, recursion, answer yes +rm: remove all arguments recursively? . +EOF + +compare expout out || fail=1 +compare experr err || fail=1 + +Exit $fail diff --git a/tests/rm/ir-1 b/tests/rm/ir-1 deleted file mode 100755 index 01b33bc1e..000000000 --- a/tests/rm/ir-1 +++ /dev/null @@ -1,56 +0,0 @@ -#!/bin/sh -# Test "rm -ir". - -# Copyright (C) 1997-2012 Free Software Foundation, Inc. - -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -. "${srcdir=.}/init.sh"; path_prepend_ ../src -print_ver_ rm - -t=t -mkdir -p $t $t/a $t/b $t/c || framework_failure_ -> $t/a/a || framework_failure_ -> $t/b/bb || framework_failure_ -> $t/c/cc || framework_failure_ - -cat < in -y -y -y -y -y -y -y -y -n -n -n -EOF - -# Remove all but one of a, b, c -- I doubt that this test can portably -# determine which one was removed based on order of dir entries. -# This is a good argument for switching to a dejagnu-style test suite. -rm --verbose -i -r $t < in > /dev/null 2>&1 || fail=1 - -# $t should not have been removed. -test -d $t || fail=1 - -# There should be only one directory left. -case $(echo $t/*) in - $t/[abc]) ;; - *) fail=1 ;; -esac - -Exit $fail diff --git a/tests/rm/ir-1.sh b/tests/rm/ir-1.sh new file mode 100755 index 000000000..01b33bc1e --- /dev/null +++ b/tests/rm/ir-1.sh @@ -0,0 +1,56 @@ +#!/bin/sh +# Test "rm -ir". + +# Copyright (C) 1997-2012 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +. "${srcdir=.}/init.sh"; path_prepend_ ../src +print_ver_ rm + +t=t +mkdir -p $t $t/a $t/b $t/c || framework_failure_ +> $t/a/a || framework_failure_ +> $t/b/bb || framework_failure_ +> $t/c/cc || framework_failure_ + +cat < in +y +y +y +y +y +y +y +y +n +n +n +EOF + +# Remove all but one of a, b, c -- I doubt that this test can portably +# determine which one was removed based on order of dir entries. +# This is a good argument for switching to a dejagnu-style test suite. +rm --verbose -i -r $t < in > /dev/null 2>&1 || fail=1 + +# $t should not have been removed. +test -d $t || fail=1 + +# There should be only one directory left. +case $(echo $t/*) in + $t/[abc]) ;; + *) fail=1 ;; +esac + +Exit $fail diff --git a/tests/rm/isatty b/tests/rm/isatty deleted file mode 100755 index f28653cc8..000000000 --- a/tests/rm/isatty +++ /dev/null @@ -1,53 +0,0 @@ -#!/bin/sh -# Make sure 'chown 0 f; rm f' prompts before removing f. - -# Copyright (C) 2001-2012 Free Software Foundation, Inc. - -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -. "${srcdir=.}/init.sh"; path_prepend_ ../src -print_ver_ rm -skip_if_root_ - - -# Skip this test if there is no /dev/stdin file. -ls /dev/stdin >/dev/null 2>&1 \ - || skip_ 'there is no /dev/stdin file' - -touch f -chmod 0 f -rm ---presume-input-tty f > out 2>&1 & -pid=$! - -# Wait a second, to give a buggy rm (as in fileutils-4.0.40) -# enough time to remove the file. -sleep 1 - -# The file must still exist. -test -f f || fail=1 - -kill $pid > /dev/null 2>&1 - -# Note the trailing 'x' -- so I don't have to have a trailing -# blank in this file :-) -cat > exp <<\EOF -rm: remove write-protected regular empty file 'f'? x -EOF - -# Append an 'x' and a newline. -echo x >> out - -compare exp out || fail=1 - -Exit $fail diff --git a/tests/rm/isatty.sh b/tests/rm/isatty.sh new file mode 100755 index 000000000..f28653cc8 --- /dev/null +++ b/tests/rm/isatty.sh @@ -0,0 +1,53 @@ +#!/bin/sh +# Make sure 'chown 0 f; rm f' prompts before removing f. + +# Copyright (C) 2001-2012 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +. "${srcdir=.}/init.sh"; path_prepend_ ../src +print_ver_ rm +skip_if_root_ + + +# Skip this test if there is no /dev/stdin file. +ls /dev/stdin >/dev/null 2>&1 \ + || skip_ 'there is no /dev/stdin file' + +touch f +chmod 0 f +rm ---presume-input-tty f > out 2>&1 & +pid=$! + +# Wait a second, to give a buggy rm (as in fileutils-4.0.40) +# enough time to remove the file. +sleep 1 + +# The file must still exist. +test -f f || fail=1 + +kill $pid > /dev/null 2>&1 + +# Note the trailing 'x' -- so I don't have to have a trailing +# blank in this file :-) +cat > exp <<\EOF +rm: remove write-protected regular empty file 'f'? x +EOF + +# Append an 'x' and a newline. +echo x >> out + +compare exp out || fail=1 + +Exit $fail diff --git a/tests/rm/many-dir-entries-vs-OOM b/tests/rm/many-dir-entries-vs-OOM deleted file mode 100755 index b5f10dac4..000000000 --- a/tests/rm/many-dir-entries-vs-OOM +++ /dev/null @@ -1,38 +0,0 @@ -#!/bin/sh -# In coreutils-8.12, rm,du,chmod, etc. would use too much memory -# when processing a directory with many entries (as in > 100,000). - -# Copyright (C) 2011-2012 Free Software Foundation, Inc. - -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -. "${srcdir=.}/init.sh"; path_prepend_ ../src -print_ver_ rm du chmod - -expensive_ - -# With many files in a single directory... -mkdir d && cd d || framework_failure_ -seq 200000|xargs touch || framework_failure_ - -cd .. - -# Restricted to 40MB, each of these coreutils-8.12 programs would fail -# with a diagnostic like "rm: fts_read failed: Cannot allocate memory". -ulimit -v 40000 -du -sh d || fail=1 -chmod -R 700 d || fail=1 -rm -rf d || fail=1 - -Exit $fail diff --git a/tests/rm/many-dir-entries-vs-OOM.sh b/tests/rm/many-dir-entries-vs-OOM.sh new file mode 100755 index 000000000..b5f10dac4 --- /dev/null +++ b/tests/rm/many-dir-entries-vs-OOM.sh @@ -0,0 +1,38 @@ +#!/bin/sh +# In coreutils-8.12, rm,du,chmod, etc. would use too much memory +# when processing a directory with many entries (as in > 100,000). + +# Copyright (C) 2011-2012 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +. "${srcdir=.}/init.sh"; path_prepend_ ../src +print_ver_ rm du chmod + +expensive_ + +# With many files in a single directory... +mkdir d && cd d || framework_failure_ +seq 200000|xargs touch || framework_failure_ + +cd .. + +# Restricted to 40MB, each of these coreutils-8.12 programs would fail +# with a diagnostic like "rm: fts_read failed: Cannot allocate memory". +ulimit -v 40000 +du -sh d || fail=1 +chmod -R 700 d || fail=1 +rm -rf d || fail=1 + +Exit $fail diff --git a/tests/rm/no-give-up b/tests/rm/no-give-up deleted file mode 100755 index 0deb262a4..000000000 --- a/tests/rm/no-give-up +++ /dev/null @@ -1,41 +0,0 @@ -#!/bin/sh -# With rm from coreutils-5.2.1 and earlier, 'rm -r' would mistakenly -# give up too early under some conditions. - -# Copyright (C) 2004-2012 Free Software Foundation, Inc. - -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -. "${srcdir=.}/init.sh"; path_prepend_ ../src -print_ver_ rm -require_root_ - -mkdir d || framework_failure_ -touch d/f || framework_failure_ -chown -R $NON_ROOT_USERNAME d || framework_failure_ - -# Ensure that non-root can access files in root-owned ".". -chmod go=x . || framework_failure_ - - -# This must fail, since '.' is not writable by $NON_ROOT_USERNAME. -setuidgid $NON_ROOT_USERNAME env PATH="$PATH" rm -rf d 2>/dev/null && fail=1 - -# d must remain. -test -d d || fail=1 - -# f must have been removed. -test -f d/f && fail=1 - -Exit $fail diff --git a/tests/rm/no-give-up.sh b/tests/rm/no-give-up.sh new file mode 100755 index 000000000..0deb262a4 --- /dev/null +++ b/tests/rm/no-give-up.sh @@ -0,0 +1,41 @@ +#!/bin/sh +# With rm from coreutils-5.2.1 and earlier, 'rm -r' would mistakenly +# give up too early under some conditions. + +# Copyright (C) 2004-2012 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +. "${srcdir=.}/init.sh"; path_prepend_ ../src +print_ver_ rm +require_root_ + +mkdir d || framework_failure_ +touch d/f || framework_failure_ +chown -R $NON_ROOT_USERNAME d || framework_failure_ + +# Ensure that non-root can access files in root-owned ".". +chmod go=x . || framework_failure_ + + +# This must fail, since '.' is not writable by $NON_ROOT_USERNAME. +setuidgid $NON_ROOT_USERNAME env PATH="$PATH" rm -rf d 2>/dev/null && fail=1 + +# d must remain. +test -d d || fail=1 + +# f must have been removed. +test -f d/f && fail=1 + +Exit $fail diff --git a/tests/rm/one-file-system b/tests/rm/one-file-system deleted file mode 100755 index 675c3fd0a..000000000 --- a/tests/rm/one-file-system +++ /dev/null @@ -1,48 +0,0 @@ -#!/bin/sh -# Demonstrate rm's new --one-file-system option. - -# Copyright (C) 2006-2012 Free Software Foundation, Inc. - -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -. "${srcdir=.}/init.sh"; path_prepend_ ../src -print_ver_ rm -require_root_ - -cleanup_() -{ - # When you take the undesirable shortcut of making /etc/mtab a link - # to /proc/mounts, unmounting "$other_partition_tmpdir" would fail. - # So, here we unmount a/b instead. - umount a/b - rm -rf "$other_partition_tmpdir" -} -. "$abs_srcdir/other-fs-tmpdir" - -t=$other_partition_tmpdir -mkdir -p a/b $t/y -mount --bind $t a/b \ - || skip_ "This test requires mount with a working --bind option." - -cat <<\EOF > exp || framework_failure_ -rm: skipping 'a/b', since it's on a different device -EOF - - -rm --one-file-system -rf a 2> out && fail=1 -test -d $t/y || fail=1 - -compare exp out || fail=1 - -Exit $fail diff --git a/tests/rm/one-file-system.sh b/tests/rm/one-file-system.sh new file mode 100755 index 000000000..675c3fd0a --- /dev/null +++ b/tests/rm/one-file-system.sh @@ -0,0 +1,48 @@ +#!/bin/sh +# Demonstrate rm's new --one-file-system option. + +# Copyright (C) 2006-2012 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +. "${srcdir=.}/init.sh"; path_prepend_ ../src +print_ver_ rm +require_root_ + +cleanup_() +{ + # When you take the undesirable shortcut of making /etc/mtab a link + # to /proc/mounts, unmounting "$other_partition_tmpdir" would fail. + # So, here we unmount a/b instead. + umount a/b + rm -rf "$other_partition_tmpdir" +} +. "$abs_srcdir/other-fs-tmpdir" + +t=$other_partition_tmpdir +mkdir -p a/b $t/y +mount --bind $t a/b \ + || skip_ "This test requires mount with a working --bind option." + +cat <<\EOF > exp || framework_failure_ +rm: skipping 'a/b', since it's on a different device +EOF + + +rm --one-file-system -rf a 2> out && fail=1 +test -d $t/y || fail=1 + +compare exp out || fail=1 + +Exit $fail diff --git a/tests/rm/one-file-system2 b/tests/rm/one-file-system2 deleted file mode 100755 index 077df76e6..000000000 --- a/tests/rm/one-file-system2 +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/sh -# Verify --one-file-system does delete within a file system - -# Copyright (C) 2009-2012 Free Software Foundation, Inc. - -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -. "${srcdir=.}/init.sh"; path_prepend_ ../src -print_ver_ rm - -mkdir -p a/b - -rm --one-file-system -rf a || fail=1 -test -d a && fail=1 - -Exit $fail diff --git a/tests/rm/one-file-system2.sh b/tests/rm/one-file-system2.sh new file mode 100755 index 000000000..077df76e6 --- /dev/null +++ b/tests/rm/one-file-system2.sh @@ -0,0 +1,27 @@ +#!/bin/sh +# Verify --one-file-system does delete within a file system + +# Copyright (C) 2009-2012 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +. "${srcdir=.}/init.sh"; path_prepend_ ../src +print_ver_ rm + +mkdir -p a/b + +rm --one-file-system -rf a || fail=1 +test -d a && fail=1 + +Exit $fail diff --git a/tests/rm/r-1 b/tests/rm/r-1 deleted file mode 100755 index 858269d75..000000000 --- a/tests/rm/r-1 +++ /dev/null @@ -1,40 +0,0 @@ -#!/bin/sh -# Test "rm -r --verbose". - -# Copyright (C) 1997-2012 Free Software Foundation, Inc. - -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -. "${srcdir=.}/init.sh"; path_prepend_ ../src -print_ver_ rm - -mkdir a a/a || framework_failure_ -> b || framework_failure_ - -cat <<\EOF > exp || framework_failure_ -removed directory: 'a/a' -removed directory: 'a' -removed 'b' -EOF - -rm --verbose -r a b > out || fail=1 - -for d in $dirs; do - test -d $d && fail=1 -done - -# Compare expected and actual output. -compare exp out || fail=1 - -Exit $fail diff --git a/tests/rm/r-1.sh b/tests/rm/r-1.sh new file mode 100755 index 000000000..858269d75 --- /dev/null +++ b/tests/rm/r-1.sh @@ -0,0 +1,40 @@ +#!/bin/sh +# Test "rm -r --verbose". + +# Copyright (C) 1997-2012 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +. "${srcdir=.}/init.sh"; path_prepend_ ../src +print_ver_ rm + +mkdir a a/a || framework_failure_ +> b || framework_failure_ + +cat <<\EOF > exp || framework_failure_ +removed directory: 'a/a' +removed directory: 'a' +removed 'b' +EOF + +rm --verbose -r a b > out || fail=1 + +for d in $dirs; do + test -d $d && fail=1 +done + +# Compare expected and actual output. +compare exp out || fail=1 + +Exit $fail diff --git a/tests/rm/r-2 b/tests/rm/r-2 deleted file mode 100755 index c946f63db..000000000 --- a/tests/rm/r-2 +++ /dev/null @@ -1,45 +0,0 @@ -#!/bin/sh -# Test "rm -r --verbose". - -# Copyright (C) 1997-2012 Free Software Foundation, Inc. - -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -. "${srcdir=.}/init.sh"; path_prepend_ ../src -print_ver_ rm - -mkdir t t/a t/a/b || framework_failure_ -> t/a/f || framework_failure_ -> t/a/b/g || framework_failure_ - -# FIXME: if this fails, it's a framework failure -cat <<\EOF | sort > t/E || framework_failure_ -removed directory: 't/a' -removed directory: 't/a/b' -removed 't/a/b/g' -removed 't/a/f' -EOF - -# Note that both the expected output (above) and the actual output lines -# are sorted, because directory entries may be processed in arbitrary order. -rm --verbose -r t/a | sort > t/O || fail=1 - -if test -d t/a; then - fail=1 -fi - -# Compare expected and actual output. -cmp t/E t/O || fail=1 - -Exit $fail diff --git a/tests/rm/r-2.sh b/tests/rm/r-2.sh new file mode 100755 index 000000000..c946f63db --- /dev/null +++ b/tests/rm/r-2.sh @@ -0,0 +1,45 @@ +#!/bin/sh +# Test "rm -r --verbose". + +# Copyright (C) 1997-2012 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +. "${srcdir=.}/init.sh"; path_prepend_ ../src +print_ver_ rm + +mkdir t t/a t/a/b || framework_failure_ +> t/a/f || framework_failure_ +> t/a/b/g || framework_failure_ + +# FIXME: if this fails, it's a framework failure +cat <<\EOF | sort > t/E || framework_failure_ +removed directory: 't/a' +removed directory: 't/a/b' +removed 't/a/b/g' +removed 't/a/f' +EOF + +# Note that both the expected output (above) and the actual output lines +# are sorted, because directory entries may be processed in arbitrary order. +rm --verbose -r t/a | sort > t/O || fail=1 + +if test -d t/a; then + fail=1 +fi + +# Compare expected and actual output. +cmp t/E t/O || fail=1 + +Exit $fail diff --git a/tests/rm/r-3 b/tests/rm/r-3 deleted file mode 100755 index 71c8a0f64..000000000 --- a/tests/rm/r-3 +++ /dev/null @@ -1,48 +0,0 @@ -#!/bin/sh -# Create and remove a directory with more than 254 files. - -# Copyright (C) 1997-2012 Free Software Foundation, Inc. - -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - - -# An early version of my rewritten rm failed to remove all of -# the files on SunOS4 when there were 254 or more in a directory. - -# And the rm from coreutils-5.0 exposes the same problem when there -# are 338 or more files in a directory on a Darwin-6.5 system - -. "${srcdir=.}/init.sh"; path_prepend_ ../src -print_ver_ rm - -mkdir t || framework_failure_ -cd t || framework_failure_ - -# Create 500 files (20 * 25). -for i in 0 1 2 3 4 5 6 7 8 9 a b c d e f g h i j; do - files= - for j in a b c d e f g h i j k l m n o p q r s t u v w x y; do - files="$files $i$j" - done - touch $files || framework_failure_ -done - -test -f 0a || framework_failure_ -test -f by || framework_failure_ -cd .. || framework_failure_ - -rm -rf t || fail=1 -test -d t && fail=1 - -Exit $fail diff --git a/tests/rm/r-3.sh b/tests/rm/r-3.sh new file mode 100755 index 000000000..71c8a0f64 --- /dev/null +++ b/tests/rm/r-3.sh @@ -0,0 +1,48 @@ +#!/bin/sh +# Create and remove a directory with more than 254 files. + +# Copyright (C) 1997-2012 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + + +# An early version of my rewritten rm failed to remove all of +# the files on SunOS4 when there were 254 or more in a directory. + +# And the rm from coreutils-5.0 exposes the same problem when there +# are 338 or more files in a directory on a Darwin-6.5 system + +. "${srcdir=.}/init.sh"; path_prepend_ ../src +print_ver_ rm + +mkdir t || framework_failure_ +cd t || framework_failure_ + +# Create 500 files (20 * 25). +for i in 0 1 2 3 4 5 6 7 8 9 a b c d e f g h i j; do + files= + for j in a b c d e f g h i j k l m n o p q r s t u v w x y; do + files="$files $i$j" + done + touch $files || framework_failure_ +done + +test -f 0a || framework_failure_ +test -f by || framework_failure_ +cd .. || framework_failure_ + +rm -rf t || fail=1 +test -d t && fail=1 + +Exit $fail diff --git a/tests/rm/r-4 b/tests/rm/r-4 deleted file mode 100755 index 0bfb76072..000000000 --- a/tests/rm/r-4 +++ /dev/null @@ -1,36 +0,0 @@ -#!/bin/sh -# Try to remove '.' and '..' recursively. - -# Copyright (C) 2006-2012 Free Software Foundation, Inc. - -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -. "${srcdir=.}/init.sh"; path_prepend_ ../src -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 - -# This test is too dangerous -- if there's a bug you're wiped out! -# rm -fr / 2>/dev/null && fail=1 - -test -f d/a || fail=1 - -Exit $fail diff --git a/tests/rm/r-4.sh b/tests/rm/r-4.sh new file mode 100755 index 000000000..0bfb76072 --- /dev/null +++ b/tests/rm/r-4.sh @@ -0,0 +1,36 @@ +#!/bin/sh +# Try to remove '.' and '..' recursively. + +# Copyright (C) 2006-2012 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +. "${srcdir=.}/init.sh"; path_prepend_ ../src +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 + +# This test is too dangerous -- if there's a bug you're wiped out! +# rm -fr / 2>/dev/null && fail=1 + +test -f d/a || fail=1 + +Exit $fail diff --git a/tests/rm/read-only b/tests/rm/read-only deleted file mode 100755 index 018648be0..000000000 --- a/tests/rm/read-only +++ /dev/null @@ -1,52 +0,0 @@ -#!/bin/sh -# Ensure that rm -f nonexistent-file-on-read-only-fs succeeds. - -# Copyright (C) 2009-2012 Free Software Foundation, Inc. - -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -. "${srcdir=.}/init.sh"; path_prepend_ ../src -print_ver_ rm -require_root_ - -cwd=$(pwd) -cleanup_() { cd /; umount "$cwd/mnt"; } - -skip=0 -# Create a file system, then mount it. -dd if=/dev/zero of=blob bs=8192 count=200 > /dev/null 2>&1 \ - || skip=1 -mkdir mnt || skip=1 -mkfs -t ext2 -F blob \ - || skip_ "failed to create ext2 file system" - -mount -oloop blob mnt || skip=1 -echo test > mnt/f || skip=1 -test -s mnt/f || skip=1 -mount -o remount,loop,ro mnt || skip=1 - -test $skip = 1 \ - && skip_ "insufficient mount/ext2 support" - -# Applying rm -f to a nonexistent file on a read-only file system must succeed. -rm -f mnt/no-such > out 2>&1 || fail=1 -# It must produce no diagnostic. -test -s out && fail=1 - -# However, trying to remove an existing file must fail. -rm -f mnt/f > out 2>&1 && fail=1 -# with a diagnostic. -test -s out || fail=1 - -Exit $fail diff --git a/tests/rm/read-only.sh b/tests/rm/read-only.sh new file mode 100755 index 000000000..018648be0 --- /dev/null +++ b/tests/rm/read-only.sh @@ -0,0 +1,52 @@ +#!/bin/sh +# Ensure that rm -f nonexistent-file-on-read-only-fs succeeds. + +# Copyright (C) 2009-2012 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +. "${srcdir=.}/init.sh"; path_prepend_ ../src +print_ver_ rm +require_root_ + +cwd=$(pwd) +cleanup_() { cd /; umount "$cwd/mnt"; } + +skip=0 +# Create a file system, then mount it. +dd if=/dev/zero of=blob bs=8192 count=200 > /dev/null 2>&1 \ + || skip=1 +mkdir mnt || skip=1 +mkfs -t ext2 -F blob \ + || skip_ "failed to create ext2 file system" + +mount -oloop blob mnt || skip=1 +echo test > mnt/f || skip=1 +test -s mnt/f || skip=1 +mount -o remount,loop,ro mnt || skip=1 + +test $skip = 1 \ + && skip_ "insufficient mount/ext2 support" + +# Applying rm -f to a nonexistent file on a read-only file system must succeed. +rm -f mnt/no-such > out 2>&1 || fail=1 +# It must produce no diagnostic. +test -s out && fail=1 + +# However, trying to remove an existing file must fail. +rm -f mnt/f > out 2>&1 && fail=1 +# with a diagnostic. +test -s out || fail=1 + +Exit $fail diff --git a/tests/rm/readdir-bug b/tests/rm/readdir-bug deleted file mode 100755 index 711e1bc0e..000000000 --- a/tests/rm/readdir-bug +++ /dev/null @@ -1,41 +0,0 @@ -#!/bin/sh -# Exercise the Darwin/MacOS bug worked around on 2006-09-29, -# whereby rm would fail to remove all entries in a directory. - -# Copyright (C) 2006-2012 Free Software Foundation, Inc. - -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -. "${srcdir=.}/init.sh"; path_prepend_ ../src -print_ver_ rm - -# Create a directory containing many files. -# What counts is a combination of the number of files and -# the lengths of their names. For details, see -# http://lists.gnu.org/archive/html/bug-coreutils/2006-09/msg00326.html -mkdir b || framework_failure_ -cd b || framework_failure_ -for i in $(seq 1 250); do - touch $(printf %040d $i) || framework_failure_ -done -cd .. || framework_failure_ - - -# On a buggy system, this would fail with the diagnostic, -# "cannot remove directory 'b': Directory not empty" -rm -rf b || fail=1 - -test -d b && fail=1 - -Exit $fail diff --git a/tests/rm/readdir-bug.sh b/tests/rm/readdir-bug.sh new file mode 100755 index 000000000..711e1bc0e --- /dev/null +++ b/tests/rm/readdir-bug.sh @@ -0,0 +1,41 @@ +#!/bin/sh +# Exercise the Darwin/MacOS bug worked around on 2006-09-29, +# whereby rm would fail to remove all entries in a directory. + +# Copyright (C) 2006-2012 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +. "${srcdir=.}/init.sh"; path_prepend_ ../src +print_ver_ rm + +# Create a directory containing many files. +# What counts is a combination of the number of files and +# the lengths of their names. For details, see +# http://lists.gnu.org/archive/html/bug-coreutils/2006-09/msg00326.html +mkdir b || framework_failure_ +cd b || framework_failure_ +for i in $(seq 1 250); do + touch $(printf %040d $i) || framework_failure_ +done +cd .. || framework_failure_ + + +# On a buggy system, this would fail with the diagnostic, +# "cannot remove directory 'b': Directory not empty" +rm -rf b || fail=1 + +test -d b && fail=1 + +Exit $fail diff --git a/tests/rm/rm1 b/tests/rm/rm1 deleted file mode 100755 index aa90c57cc..000000000 --- a/tests/rm/rm1 +++ /dev/null @@ -1,48 +0,0 @@ -#!/bin/sh -# exercise another small part of remove.c - -# Copyright (C) 2002-2012 Free Software Foundation, Inc. - -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -. "${srcdir=.}/init.sh"; path_prepend_ ../src -print_ver_ rm -skip_if_root_ - -mkdir -p b/a/p b/c b/d || framework_failure_ -chmod u-w b/a || framework_failure_ - - -# This should fail. -rm -rf b > out 2>&1 && fail=1 -cat <<\EOF > exp -rm: cannot remove directory 'b/a/p': Permission denied -EOF - -# On some systems, rm doesn't have enough information to -# say it's a directory. -cat <<\EOF > exp2 -rm: cannot remove 'b/a/p': Permission denied -EOF - -cmp out exp > /dev/null 2>&1 || { - cmp out exp2 || fail=1 - } -test $fail = 1 && compare exp out - -test -d b/a/p || fail=1 -test -d b/c && fail=1 -test -d b/d && fail=1 - -Exit $fail diff --git a/tests/rm/rm1.sh b/tests/rm/rm1.sh new file mode 100755 index 000000000..aa90c57cc --- /dev/null +++ b/tests/rm/rm1.sh @@ -0,0 +1,48 @@ +#!/bin/sh +# exercise another small part of remove.c + +# Copyright (C) 2002-2012 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +. "${srcdir=.}/init.sh"; path_prepend_ ../src +print_ver_ rm +skip_if_root_ + +mkdir -p b/a/p b/c b/d || framework_failure_ +chmod u-w b/a || framework_failure_ + + +# This should fail. +rm -rf b > out 2>&1 && fail=1 +cat <<\EOF > exp +rm: cannot remove directory 'b/a/p': Permission denied +EOF + +# On some systems, rm doesn't have enough information to +# say it's a directory. +cat <<\EOF > exp2 +rm: cannot remove 'b/a/p': Permission denied +EOF + +cmp out exp > /dev/null 2>&1 || { + cmp out exp2 || fail=1 + } +test $fail = 1 && compare exp out + +test -d b/a/p || fail=1 +test -d b/c && fail=1 +test -d b/d && fail=1 + +Exit $fail diff --git a/tests/rm/rm2 b/tests/rm/rm2 deleted file mode 100755 index 7bbdfeaba..000000000 --- a/tests/rm/rm2 +++ /dev/null @@ -1,55 +0,0 @@ -#!/bin/sh -# exercise another small part of remove.c - -# Copyright (C) 2002-2012 Free Software Foundation, Inc. - -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -. "${srcdir=.}/init.sh"; path_prepend_ ../src -print_ver_ rm -skip_if_root_ - -mkdir -p a/0 || framework_failure_ -mkdir -p a/1/2 b/3 || framework_failure_ -mkdir a/2 a/3 || framework_failure_ -chmod u-x a/1 b || framework_failure_ - - -# Exercise two separate code paths -- though both result -# in the same sort of diagnostic. -# Both of these should fail. -rm -rf a b > out 2>&1 && fail=1 -cat <<\EOF > exp -rm: cannot remove 'a/1': Permission denied -rm: cannot remove 'b': Permission denied -EOF - -cat <<\EOF > exp-solaris -rm: cannot remove 'a/1/2': Permission denied -rm: cannot remove 'b/3': Permission denied -EOF - -cmp out exp > /dev/null 2>&1 \ - || { cmp out exp-solaris > /dev/null 2>&1 || fail=1; } -test $fail = 1 && compare exp out - -test -d a/0 && fail=1 -test -d a/1 || fail=1 -test -d a/2 && fail=1 -test -d a/3 && fail=1 - -chmod u+x b -test -d b/3 || fail=1 - -Exit $fail diff --git a/tests/rm/rm2.sh b/tests/rm/rm2.sh new file mode 100755 index 000000000..7bbdfeaba --- /dev/null +++ b/tests/rm/rm2.sh @@ -0,0 +1,55 @@ +#!/bin/sh +# exercise another small part of remove.c + +# Copyright (C) 2002-2012 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +. "${srcdir=.}/init.sh"; path_prepend_ ../src +print_ver_ rm +skip_if_root_ + +mkdir -p a/0 || framework_failure_ +mkdir -p a/1/2 b/3 || framework_failure_ +mkdir a/2 a/3 || framework_failure_ +chmod u-x a/1 b || framework_failure_ + + +# Exercise two separate code paths -- though both result +# in the same sort of diagnostic. +# Both of these should fail. +rm -rf a b > out 2>&1 && fail=1 +cat <<\EOF > exp +rm: cannot remove 'a/1': Permission denied +rm: cannot remove 'b': Permission denied +EOF + +cat <<\EOF > exp-solaris +rm: cannot remove 'a/1/2': Permission denied +rm: cannot remove 'b/3': Permission denied +EOF + +cmp out exp > /dev/null 2>&1 \ + || { cmp out exp-solaris > /dev/null 2>&1 || fail=1; } +test $fail = 1 && compare exp out + +test -d a/0 && fail=1 +test -d a/1 || fail=1 +test -d a/2 && fail=1 +test -d a/3 && fail=1 + +chmod u+x b +test -d b/3 || fail=1 + +Exit $fail diff --git a/tests/rm/rm3 b/tests/rm/rm3 deleted file mode 100755 index 37ee87b22..000000000 --- a/tests/rm/rm3 +++ /dev/null @@ -1,73 +0,0 @@ -#!/bin/sh -# exercise another small part of remove.c - -# Copyright (C) 2002-2012 Free Software Foundation, Inc. - -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -. "${srcdir=.}/init.sh"; path_prepend_ ../src -print_ver_ rm -skip_if_root_ - -mkdir -p z || framework_failure_ -cd z || framework_failure_ -touch empty empty-u || framework_failure_ -echo not-empty > fu -ln -s empty-f slink -ln -s . slinkdot -mkdir d du || framework_failure_ -chmod u-w fu du empty-u || framework_failure_ -cd .. - - -cat < in -y -y -y -y -y -y -y -y -y -EOF - -# Both of these should fail. -rm -ir z < in > out 2>&1 || fail=1 - -# Given input like 'rm: ...? rm: ...? ' (no trailing newline), -# the 'head...' part of the pipeline below removes the trailing space, so -# that sed doesn't have to deal with a line lacking a terminating newline. -# This avoids a bug whereby some vendor-provided (Tru64) versions of sed -# would mistakenly tack a newline onto the end of the output. -tr '?' '\n' < out | head --bytes=-1 | sed 's/^ //' |sort > o2 -mv o2 out - -sort < exp || fail=1 -rm: descend into directory 'z' -rm: remove regular empty file 'z/empty' -rm: remove write-protected regular file 'z/fu' -rm: remove write-protected regular empty file 'z/empty-u' -rm: remove symbolic link 'z/slink' -rm: remove symbolic link 'z/slinkdot' -rm: remove directory 'z/d' -rm: remove write-protected directory 'z/du' -rm: remove directory 'z' -EOF - -compare exp out || fail=1 - -test -d z && fail=1 - -Exit $fail diff --git a/tests/rm/rm3.sh b/tests/rm/rm3.sh new file mode 100755 index 000000000..37ee87b22 --- /dev/null +++ b/tests/rm/rm3.sh @@ -0,0 +1,73 @@ +#!/bin/sh +# exercise another small part of remove.c + +# Copyright (C) 2002-2012 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +. "${srcdir=.}/init.sh"; path_prepend_ ../src +print_ver_ rm +skip_if_root_ + +mkdir -p z || framework_failure_ +cd z || framework_failure_ +touch empty empty-u || framework_failure_ +echo not-empty > fu +ln -s empty-f slink +ln -s . slinkdot +mkdir d du || framework_failure_ +chmod u-w fu du empty-u || framework_failure_ +cd .. + + +cat < in +y +y +y +y +y +y +y +y +y +EOF + +# Both of these should fail. +rm -ir z < in > out 2>&1 || fail=1 + +# Given input like 'rm: ...? rm: ...? ' (no trailing newline), +# the 'head...' part of the pipeline below removes the trailing space, so +# that sed doesn't have to deal with a line lacking a terminating newline. +# This avoids a bug whereby some vendor-provided (Tru64) versions of sed +# would mistakenly tack a newline onto the end of the output. +tr '?' '\n' < out | head --bytes=-1 | sed 's/^ //' |sort > o2 +mv o2 out + +sort < exp || fail=1 +rm: descend into directory 'z' +rm: remove regular empty file 'z/empty' +rm: remove write-protected regular file 'z/fu' +rm: remove write-protected regular empty file 'z/empty-u' +rm: remove symbolic link 'z/slink' +rm: remove symbolic link 'z/slinkdot' +rm: remove directory 'z/d' +rm: remove write-protected directory 'z/du' +rm: remove directory 'z' +EOF + +compare exp out || fail=1 + +test -d z && fail=1 + +Exit $fail diff --git a/tests/rm/rm4 b/tests/rm/rm4 deleted file mode 100755 index 3e22aad9d..000000000 --- a/tests/rm/rm4 +++ /dev/null @@ -1,31 +0,0 @@ -#!/bin/sh -# ensure that 'rm dir' fails without --recursive - -# Copyright (C) 2002-2012 Free Software Foundation, Inc. - -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -. "${srcdir=.}/init.sh"; path_prepend_ ../src -print_ver_ rm -skip_if_root_ - -mkdir dir || framework_failure_ - - -# This should fail. -rm dir > /dev/null 2>&1 && fail=1 - -test -d dir || fail=1 - -Exit $fail diff --git a/tests/rm/rm4.sh b/tests/rm/rm4.sh new file mode 100755 index 000000000..3e22aad9d --- /dev/null +++ b/tests/rm/rm4.sh @@ -0,0 +1,31 @@ +#!/bin/sh +# ensure that 'rm dir' fails without --recursive + +# Copyright (C) 2002-2012 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +. "${srcdir=.}/init.sh"; path_prepend_ ../src +print_ver_ rm +skip_if_root_ + +mkdir dir || framework_failure_ + + +# This should fail. +rm dir > /dev/null 2>&1 && fail=1 + +test -d dir || fail=1 + +Exit $fail diff --git a/tests/rm/rm5 b/tests/rm/rm5 deleted file mode 100755 index 56c6bbc26..000000000 --- a/tests/rm/rm5 +++ /dev/null @@ -1,52 +0,0 @@ -#!/bin/sh -# a basic test of rm -ri - -# Copyright (C) 2002-2012 Free Software Foundation, Inc. - -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -. "${srcdir=.}/init.sh"; path_prepend_ ../src -print_ver_ rm -skip_if_root_ - -mkdir -p d/e || framework_failure_ -cat < in || framework_failure_ -y -y -y -EOF - -cat <<\EOF > exp || framework_failure_ -rm: descend into directory 'd' -rm: remove directory 'd/e' -rm: remove directory 'd' -EOF - - -rm -ir d < in > out 2>&1 || fail=1 - -# Given input like 'rm: ...? rm: ...? ' (no trailing newline), -# the 'head...' part of the pipeline below removes the trailing space, so -# that sed doesn't have to deal with a line lacking a terminating newline. -# This avoids a bug whereby some vendor-provided (Tru64) versions of sed -# would mistakenly tack a newline onto the end of the output. -tr '?' '\n' < out | head --bytes=-1 | sed 's/^ //' > o2 -mv o2 out - -# Make sure it's been removed. -test -d d && fail=1 - -compare exp out || fail=1 - -Exit $fail diff --git a/tests/rm/rm5.sh b/tests/rm/rm5.sh new file mode 100755 index 000000000..56c6bbc26 --- /dev/null +++ b/tests/rm/rm5.sh @@ -0,0 +1,52 @@ +#!/bin/sh +# a basic test of rm -ri + +# Copyright (C) 2002-2012 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +. "${srcdir=.}/init.sh"; path_prepend_ ../src +print_ver_ rm +skip_if_root_ + +mkdir -p d/e || framework_failure_ +cat < in || framework_failure_ +y +y +y +EOF + +cat <<\EOF > exp || framework_failure_ +rm: descend into directory 'd' +rm: remove directory 'd/e' +rm: remove directory 'd' +EOF + + +rm -ir d < in > out 2>&1 || fail=1 + +# Given input like 'rm: ...? rm: ...? ' (no trailing newline), +# the 'head...' part of the pipeline below removes the trailing space, so +# that sed doesn't have to deal with a line lacking a terminating newline. +# This avoids a bug whereby some vendor-provided (Tru64) versions of sed +# would mistakenly tack a newline onto the end of the output. +tr '?' '\n' < out | head --bytes=-1 | sed 's/^ //' > o2 +mv o2 out + +# Make sure it's been removed. +test -d d && fail=1 + +compare exp out || fail=1 + +Exit $fail diff --git a/tests/rm/sunos-1 b/tests/rm/sunos-1 deleted file mode 100755 index 584236abc..000000000 --- a/tests/rm/sunos-1 +++ /dev/null @@ -1,29 +0,0 @@ -#!/bin/sh -# Make sure that rm -r '' fails. - -# Copyright (C) 1997-2012 Free Software Foundation, Inc. - -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - - -# On SunOS 4.1.3, running rm -r '' in a nonempty directory may -# actually remove files with names of entries in the current directory -# but relative to '/' rather than relative to the current directory. - -. "${srcdir=.}/init.sh"; path_prepend_ ../src -print_ver_ rm - -rm -r '' > /dev/null 2>&1 && fail=1 - -Exit $fail diff --git a/tests/rm/sunos-1.sh b/tests/rm/sunos-1.sh new file mode 100755 index 000000000..584236abc --- /dev/null +++ b/tests/rm/sunos-1.sh @@ -0,0 +1,29 @@ +#!/bin/sh +# Make sure that rm -r '' fails. + +# Copyright (C) 1997-2012 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + + +# On SunOS 4.1.3, running rm -r '' in a nonempty directory may +# actually remove files with names of entries in the current directory +# but relative to '/' rather than relative to the current directory. + +. "${srcdir=.}/init.sh"; path_prepend_ ../src +print_ver_ rm + +rm -r '' > /dev/null 2>&1 && fail=1 + +Exit $fail diff --git a/tests/rm/unread2 b/tests/rm/unread2 deleted file mode 100755 index 46fc98cd8..000000000 --- a/tests/rm/unread2 +++ /dev/null @@ -1,35 +0,0 @@ -#!/bin/sh -# exercise one small part of remove.c - -# Copyright (C) 2002-2012 Free Software Foundation, Inc. - -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -. "${srcdir=.}/init.sh"; path_prepend_ ../src -print_ver_ rm -skip_if_root_ - -mkdir -p a/b || framework_failure_ -chmod u-r a - - -# This should fail. -rm -rf a > out 2>&1 && fail=1 -cat <<\EOF > exp -rm: cannot remove 'a': Permission denied -EOF - -compare exp out || fail=1 - -Exit $fail diff --git a/tests/rm/unread2.sh b/tests/rm/unread2.sh new file mode 100755 index 000000000..46fc98cd8 --- /dev/null +++ b/tests/rm/unread2.sh @@ -0,0 +1,35 @@ +#!/bin/sh +# exercise one small part of remove.c + +# Copyright (C) 2002-2012 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +. "${srcdir=.}/init.sh"; path_prepend_ ../src +print_ver_ rm +skip_if_root_ + +mkdir -p a/b || framework_failure_ +chmod u-r a + + +# This should fail. +rm -rf a > out 2>&1 && fail=1 +cat <<\EOF > exp +rm: cannot remove 'a': Permission denied +EOF + +compare exp out || fail=1 + +Exit $fail diff --git a/tests/rm/unread3 b/tests/rm/unread3 deleted file mode 100755 index 4b8bbc2d3..000000000 --- a/tests/rm/unread3 +++ /dev/null @@ -1,43 +0,0 @@ -#!/bin/sh -# Ensure that rm works even from an unreadable working directory. - -# Copyright (C) 2004-2012 Free Software Foundation, Inc. - -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -. "${srcdir=.}/init.sh"; path_prepend_ ../src -print_ver_ rm -skip_if_root_ - -mkdir -p a/1 b c d/2 e/3 || framework_failure_ - - -t=$(pwd) -cd c -chmod u=x,go= . - -# With coreutils-5.2.1, this would get a failed assertion. -rm -r "$t/a" "$t/b" || fail=1 - -# With coreutils-5.2.1, this would get the following: -# rm: cannot get current directory: Permission denied -# rm: failed to return to initial working directory: Bad file descriptor -rm -r "$t/d" "$t/e" || fail=1 - -test -d "$t/a" && fail=1 -test -d "$t/b" && fail=1 -test -d "$t/d" && fail=1 -test -d "$t/e" && fail=1 - -Exit $fail diff --git a/tests/rm/unread3.sh b/tests/rm/unread3.sh new file mode 100755 index 000000000..4b8bbc2d3 --- /dev/null +++ b/tests/rm/unread3.sh @@ -0,0 +1,43 @@ +#!/bin/sh +# Ensure that rm works even from an unreadable working directory. + +# Copyright (C) 2004-2012 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +. "${srcdir=.}/init.sh"; path_prepend_ ../src +print_ver_ rm +skip_if_root_ + +mkdir -p a/1 b c d/2 e/3 || framework_failure_ + + +t=$(pwd) +cd c +chmod u=x,go= . + +# With coreutils-5.2.1, this would get a failed assertion. +rm -r "$t/a" "$t/b" || fail=1 + +# With coreutils-5.2.1, this would get the following: +# rm: cannot get current directory: Permission denied +# rm: failed to return to initial working directory: Bad file descriptor +rm -r "$t/d" "$t/e" || fail=1 + +test -d "$t/a" && fail=1 +test -d "$t/b" && fail=1 +test -d "$t/d" && fail=1 +test -d "$t/e" && fail=1 + +Exit $fail diff --git a/tests/rm/unreadable b/tests/rm/unreadable deleted file mode 100755 index ebc8511c2..000000000 --- a/tests/rm/unreadable +++ /dev/null @@ -1,50 +0,0 @@ -#!/usr/bin/perl -# Test "rm" and unreadable directories. - -# Copyright (C) 1998-2012 Free Software Foundation, Inc. - -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -use strict; - -(my $program_name = $0) =~ s|.*/||; - -# Turn off localization of executable's output. -@ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3; - -my $d = "dir-$$"; -my $mkdir = {PRE => sub {mkdir $d,0100 or die "$d: $!\n"}}; -my $prog = 'rm'; -my $uid = $<; - -my @Tests = - ( - # test-name options input expected-output - # - # Removing an empty, unwritable directory succeeds. - ['unreadable-1', '-rf', $d, {EXIT => 0}, $mkdir], - - ['unreadable-2', '-rf', $d, - {EXIT => $uid == 0 ? 0 : 1}, - {ERR => $uid == 0 ? '' - : "$prog: cannot remove '$d': Permission denied\n"}, - {PRE => sub { (mkdir $d,0700 and mkdir "$d/x",0700 and chmod 0100,$d) - or die "$d: $!\n"}} ], - ); - -my $save_temps = $ENV{SAVE_TEMPS}; -my $verbose = $ENV{VERBOSE}; - -my $fail = run_tests ($program_name, $prog, \@Tests, $save_temps, $verbose); -exit $fail; diff --git a/tests/rm/unreadable.pl b/tests/rm/unreadable.pl new file mode 100755 index 000000000..ebc8511c2 --- /dev/null +++ b/tests/rm/unreadable.pl @@ -0,0 +1,50 @@ +#!/usr/bin/perl +# Test "rm" and unreadable directories. + +# Copyright (C) 1998-2012 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +use strict; + +(my $program_name = $0) =~ s|.*/||; + +# Turn off localization of executable's output. +@ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3; + +my $d = "dir-$$"; +my $mkdir = {PRE => sub {mkdir $d,0100 or die "$d: $!\n"}}; +my $prog = 'rm'; +my $uid = $<; + +my @Tests = + ( + # test-name options input expected-output + # + # Removing an empty, unwritable directory succeeds. + ['unreadable-1', '-rf', $d, {EXIT => 0}, $mkdir], + + ['unreadable-2', '-rf', $d, + {EXIT => $uid == 0 ? 0 : 1}, + {ERR => $uid == 0 ? '' + : "$prog: cannot remove '$d': Permission denied\n"}, + {PRE => sub { (mkdir $d,0700 and mkdir "$d/x",0700 and chmod 0100,$d) + or die "$d: $!\n"}} ], + ); + +my $save_temps = $ENV{SAVE_TEMPS}; +my $verbose = $ENV{VERBOSE}; + +my $fail = run_tests ($program_name, $prog, \@Tests, $save_temps, $verbose); +exit $fail; diff --git a/tests/rm/v-slash b/tests/rm/v-slash deleted file mode 100755 index 2fae859b2..000000000 --- a/tests/rm/v-slash +++ /dev/null @@ -1,34 +0,0 @@ -#!/bin/sh -# avoid extra slashes in --verbose output - -# Copyright (C) 2007-2012 Free Software Foundation, Inc. - -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -. "${srcdir=.}/init.sh"; path_prepend_ ../src -print_ver_ rm - -mkdir a || framework_failure_ -touch a/x || framework_failure_ - - -rm --verbose -r a/// > out || fail=1 -cat <<\EOF > exp || fail=1 -removed 'a/x' -removed directory: 'a' -EOF - -compare exp out || fail=1 - -Exit $fail diff --git a/tests/rm/v-slash.sh b/tests/rm/v-slash.sh new file mode 100755 index 000000000..2fae859b2 --- /dev/null +++ b/tests/rm/v-slash.sh @@ -0,0 +1,34 @@ +#!/bin/sh +# avoid extra slashes in --verbose output + +# Copyright (C) 2007-2012 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +. "${srcdir=.}/init.sh"; path_prepend_ ../src +print_ver_ rm + +mkdir a || framework_failure_ +touch a/x || framework_failure_ + + +rm --verbose -r a/// > out || fail=1 +cat <<\EOF > exp || fail=1 +removed 'a/x' +removed directory: 'a' +EOF + +compare exp out || fail=1 + +Exit $fail -- cgit v1.2.3-54-g00ecf