diff options
author | Jim Meyering <jim@meyering.net> | 2007-09-12 14:52:26 +0200 |
---|---|---|
committer | Jim Meyering <jim@meyering.net> | 2007-09-15 08:40:39 +0200 |
commit | a669dfdabb3fa1be2e1367d53a797d495e7bd5c9 (patch) | |
tree | c88d6414649f7f4f5571138e193c72da44a03876 | |
parent | 0539705768992ebcc290bc859f64e27898c7f958 (diff) | |
download | coreutils-a669dfdabb3fa1be2e1367d53a797d495e7bd5c9.tar.xz |
More misc, test-related changes. (some to allow running tests as root)
75 files changed, 334 insertions, 808 deletions
diff --git a/tests/chgrp/no-x b/tests/chgrp/no-x index a98ba90ef..57900d83c 100755 --- a/tests/chgrp/no-x +++ b/tests/chgrp/no-x @@ -24,9 +24,8 @@ fi . $srcdir/../lang-default . $srcdir/../group-names -PRIV_CHECK_ARG=require-non-root . $srcdir/../priv-check - . $srcdir/../test-lib.sh +skip_if_root_ set _ $groups; shift g1=$1 diff --git a/tests/chmod/no-x b/tests/chmod/no-x index 64dffb95b..8e84ad262 100755 --- a/tests/chmod/no-x +++ b/tests/chmod/no-x @@ -23,10 +23,10 @@ if test "$VERBOSE" = yes; then fi . $srcdir/../lang-default -PRIV_CHECK_ARG=require-non-root . $srcdir/../priv-check . $srcdir/../test-lib.sh +skip_if_root_ -mkdir -p d/no-x/y || framework_failure +mkdir -p d/no-x/y a/b || framework_failure chmod u=rw d/no-x || framework_failure fail=0 @@ -52,7 +52,6 @@ EOF compare out exp || fail=1 -mkdir -p a/b cd a # This will fail with ``chmod: fts_read failed: Permission denied'' chmod a-x . b 2> /dev/null && fail=1 diff --git a/tests/chown/preserve-root b/tests/chown/preserve-root index de45cbc16..e41847291 100755 --- a/tests/chown/preserve-root +++ b/tests/chown/preserve-root @@ -22,8 +22,8 @@ if test "$VERBOSE" = yes; then fi . $srcdir/../lang-default -PRIV_CHECK_ARG=require-non-root . $srcdir/../priv-check . $srcdir/../test-lib.sh +skip_if_root_ mkdir d && ln -s / d/slink-to-root diff --git a/tests/cp/fail-perm b/tests/cp/fail-perm index 0ed9166f4..49b06b0ce 100755 --- a/tests/cp/fail-perm +++ b/tests/cp/fail-perm @@ -22,8 +22,8 @@ if test "$VERBOSE" = yes; then fi . $srcdir/../lang-default -PRIV_CHECK_ARG=require-non-root . $srcdir/../priv-check . $srcdir/../test-lib.sh +skip_if_root_ mkdir D D/D || framework_failure touch D/a || framework_failure diff --git a/tests/dd/misc b/tests/dd/misc index aea949109..76183b3f8 100755 --- a/tests/dd/misc +++ b/tests/dd/misc @@ -31,14 +31,9 @@ tmp_out=dd-out.$$ fail=0 warn=0 -test_failure=0 -echo data > $tmp_in || test_failure=1 -ln $tmp_in $tmp_in2 || test_failure=1 -ln -s $tmp_in $tmp_sym || test_failure=1 -if test $test_failure = 1; then - echo 'failure in testing framework' - exit 1 -fi +echo data > $tmp_in || framework_failure +ln $tmp_in $tmp_in2 || framework_failure +ln -s $tmp_in $tmp_sym || framework_failure dd if=$tmp_in of=$tmp_out 2> /dev/null || fail=1 compare $tmp_in $tmp_out || fail=1 diff --git a/tests/du/inacc-dest b/tests/du/inacc-dest index cd2e1e828..c2bab2cf9 100755 --- a/tests/du/inacc-dest +++ b/tests/du/inacc-dest @@ -23,8 +23,8 @@ if test "$VERBOSE" = yes; then fi . $srcdir/../lang-default -PRIV_CHECK_ARG=require-non-root . $srcdir/../priv-check . $srcdir/../test-lib.sh +skip_if_root_ mkdir f && cd f && mkdir a b c d e && touch c/j && chmod a-x c \ || framework_failure diff --git a/tests/du/inacc-dir b/tests/du/inacc-dir index 1ee5943b4..f7d553aca 100755 --- a/tests/du/inacc-dir +++ b/tests/du/inacc-dir @@ -21,6 +21,7 @@ if test "$VERBOSE" = yes; then fi . $srcdir/../test-lib.sh +skip_if_root_ mkdir -p a/sub || framework_failure diff --git a/tests/du/inaccessible-cwd b/tests/du/inaccessible-cwd index 6706c19aa..8eb6693e7 100755 --- a/tests/du/inaccessible-cwd +++ b/tests/du/inaccessible-cwd @@ -25,8 +25,8 @@ if test "$VERBOSE" = yes; then du --version fi -PRIV_CHECK_ARG=require-non-root . $srcdir/../priv-check . $srcdir/../test-lib.sh +skip_if_root_ cwd=`pwd` mkdir -p no-x a/b || framework_failure diff --git a/tests/du/no-x b/tests/du/no-x index 630ca17a3..5f888ed51 100755 --- a/tests/du/no-x +++ b/tests/du/no-x @@ -23,8 +23,8 @@ if test "$VERBOSE" = yes; then fi . $srcdir/../lang-default -PRIV_CHECK_ARG=require-non-root . $srcdir/../priv-check . $srcdir/../test-lib.sh +skip_if_root_ mkdir -p d/no-x/y || framework_failure chmod u=rw d/no-x || framework_failure diff --git a/tests/install/basic-1 b/tests/install/basic-1 index 89d14d228..ca24a9d22 100755 --- a/tests/install/basic-1 +++ b/tests/install/basic-1 @@ -21,9 +21,9 @@ if test "$VERBOSE" = yes; then ginstall --version fi -PRIV_CHECK_ARG=require-non-root . $srcdir/../priv-check . $srcdir/../lang-default . $srcdir/../test-lib.sh +skip_if_root_ dir=dir file=file diff --git a/tests/ls/stat-failed b/tests/ls/stat-failed index 02c3bf19c..2d6e98821 100755 --- a/tests/ls/stat-failed +++ b/tests/ls/stat-failed @@ -23,8 +23,8 @@ if test "$VERBOSE" = yes; then fi . $srcdir/../lang-default -PRIV_CHECK_ARG=require-non-root . $srcdir/../priv-check . $srcdir/../test-lib.sh +skip_if_root_ mkdir d || framework_failure ln -s / d/s || framework_failure diff --git a/tests/misc/pathchk1 b/tests/misc/pathchk1 index ffe917910..453a8e277 100755 --- a/tests/misc/pathchk1 +++ b/tests/misc/pathchk1 @@ -21,8 +21,8 @@ if test "$VERBOSE" = yes; then pathchk --version fi -PRIV_CHECK_ARG=require-non-root . $srcdir/../priv-check . $srcdir/../test-lib.sh +skip_if_root_ touch file || framework_failure diff --git a/tests/misc/selinux b/tests/misc/selinux index 90ab2d6c4..a4fc78ac4 100755 --- a/tests/misc/selinux +++ b/tests/misc/selinux @@ -12,8 +12,8 @@ fi . $srcdir/../lang-default . $srcdir/../selinux -PRIV_CHECK_ARG=require-non-root . $srcdir/../priv-check . $srcdir/../test-lib.sh +skip_if_root_ # Create a regular file, dir, fifo. touch f || framework_failure diff --git a/tests/misc/shred-remove b/tests/misc/shred-remove index ae7443b18..f09c6f3e8 100755 --- a/tests/misc/shred-remove +++ b/tests/misc/shred-remove @@ -21,8 +21,8 @@ if test "$VERBOSE" = yes; then shred --version fi -PRIV_CHECK_ARG=require-non-root . $srcdir/../priv-check . $srcdir/../test-lib.sh +skip_if_root_ # The length of the basename is what matters. # In this case, shred would try to rename the file 256^10 times diff --git a/tests/mkdir/p-3 b/tests/mkdir/p-3 index ff011e60f..401091131 100755 --- a/tests/mkdir/p-3 +++ b/tests/mkdir/p-3 @@ -23,8 +23,8 @@ if test "$VERBOSE" = yes; then mkdir --version fi -PRIV_CHECK_ARG=require-non-root . $srcdir/../priv-check . $srcdir/../test-lib.sh +skip_if_root_ mkdir no-access || framework_failure mkdir no-acce2s || framework_failure diff --git a/tests/mv/Makefile.am b/tests/mv/Makefile.am index d043c8bad..4fa09fbd2 100644 --- a/tests/mv/Makefile.am +++ b/tests/mv/Makefile.am @@ -32,10 +32,18 @@ TESTS = \ perm-1 \ i-link-no \ part-fail \ - dup-source childproof i-4 i-5 update i-2 mv-special-1 \ - into-self into-self-2 into-self-3 into-self-4 \ + dup-source childproof update mv-special-1 \ + into-self \ + into-self-2 \ + into-self-3 \ + into-self-4 \ + i-1 \ + i-2 \ + i-3 \ + i-4 \ + i-5 \ backup-is-src \ - i-1 hard-link-1 force partition-perm to-symlink dir-file diag \ + hard-link-1 force partition-perm to-symlink dir-file diag \ part-symlink part-rename trailing-slash EXTRA_DIST = $(TESTS) vfat diff --git a/tests/mv/childproof b/tests/mv/childproof index 6d93974a4..cdce93253 100755 --- a/tests/mv/childproof +++ b/tests/mv/childproof @@ -26,8 +26,8 @@ if test "$VERBOSE" = yes; then fi . $srcdir/../lang-default -PRIV_CHECK_ARG=require-non-root . $srcdir/../priv-check . $srcdir/../test-lib.sh +skip_if_root_ mkdir a b c || framework_failure echo a > a/f || framework_failure diff --git a/tests/mv/dup-source b/tests/mv/dup-source index a851ba8cf..a3eff6bdc 100755 --- a/tests/mv/dup-source +++ b/tests/mv/dup-source @@ -26,8 +26,8 @@ if test "$VERBOSE" = yes; then fi . $srcdir/../lang-default -PRIV_CHECK_ARG=require-non-root . $srcdir/../priv-check . $srcdir/../test-lib.sh +skip_if_root_ fail=0 diff --git a/tests/mv/hard-2 b/tests/mv/hard-2 index 62467e628..7833e43f7 100755 --- a/tests/mv/hard-2 +++ b/tests/mv/hard-2 @@ -23,8 +23,8 @@ if test "$VERBOSE" = yes; then cp --version fi -PRIV_CHECK_ARG=require-non-root . $srcdir/../priv-check . $srcdir/../test-lib.sh +skip_if_root_ mkdir dst || framework_failure (cd dst && touch a b c) || framework_failure diff --git a/tests/mv/hard-3 b/tests/mv/hard-3 index cb02422cd..8d532a7c9 100755 --- a/tests/mv/hard-3 +++ b/tests/mv/hard-3 @@ -35,8 +35,8 @@ if test "$VERBOSE" = yes; then cp --version fi -PRIV_CHECK_ARG=require-non-root . $srcdir/../priv-check . $srcdir/../test-lib.sh +skip_if_root_ mkdir -p x dst/x || framework_failure touch dst/x/b || framework_failure diff --git a/tests/mv/i-2 b/tests/mv/i-2 index 6c654c98f..49f9d985f 100755 --- a/tests/mv/i-2 +++ b/tests/mv/i-2 @@ -27,8 +27,8 @@ fi # Make sure we get English translations. . $srcdir/../lang-default -PRIV_CHECK_ARG=require-non-root . $srcdir/../priv-check . $srcdir/../test-lib.sh +skip_if_root_ for i in a b c d e f g h; do echo $i > $i || framework_failure diff --git a/tests/mv/i-3 b/tests/mv/i-3 index 8a75de7f2..15f25ced8 100755 --- a/tests/mv/i-3 +++ b/tests/mv/i-3 @@ -23,8 +23,9 @@ if test "$VERBOSE" = yes; then fi . $srcdir/../lang-default -PRIV_CHECK_ARG=require-non-root . $srcdir/../priv-check +. $srcdir/../input-tty . $srcdir/../test-lib.sh +skip_if_root_ touch f g h i || framework_failure chmod 0 g i || framework_failure @@ -40,7 +41,7 @@ kill $pid # Make sure out contains the prompt. case "`cat out`" in - "mv: overwrite \`g', overriding mode 0000?"*) ;; + "mv: try to overwrite \`g', overriding mode 0000"*) ;; *) fail=1 ;; esac diff --git a/tests/mv/leak-fd b/tests/mv/leak-fd index 515ad20fb..7a0a0ba5d 100755 --- a/tests/mv/leak-fd +++ b/tests/mv/leak-fd @@ -27,8 +27,8 @@ fi # framework-failure on systems with a smaller command-line length . $srcdir/../expensive -PRIV_CHECK_ARG=require-non-root . $srcdir/../priv-check . $srcdir/../test-lib.sh +skip_if_root_ cleanup_() { rm -rf "$other_partition_tmpdir"; } . "$abs_top_srcdir/tests/other-fs-tmpdir" diff --git a/tests/mv/part-fail b/tests/mv/part-fail index 1a43bafcd..4f12c1415 100755 --- a/tests/mv/part-fail +++ b/tests/mv/part-fail @@ -25,8 +25,8 @@ if test "$VERBOSE" = yes; then fi . $srcdir/../lang-default -PRIV_CHECK_ARG=require-non-root . $srcdir/../priv-check . $srcdir/../test-lib.sh +skip_if_root_ cleanup_() { t=$other_partition_tmpdir; chmod -R 700 "$t"; rm -rf "$t"; } . "$abs_top_srcdir/tests/other-fs-tmpdir" diff --git a/tests/mv/perm-1 b/tests/mv/perm-1 index af859197c..08a4eaa5b 100755 --- a/tests/mv/perm-1 +++ b/tests/mv/perm-1 @@ -23,8 +23,8 @@ if test "$VERBOSE" = yes; then fi . $srcdir/../lang-default -PRIV_CHECK_ARG=require-non-root . $srcdir/../priv-check . $srcdir/../test-lib.sh +skip_if_root_ mkdir -p no-write/dir || framework_failure chmod u-w no-write || framework_failure diff --git a/tests/rm/Makefile.am b/tests/rm/Makefile.am index 2246ecd6f..21d3f4db2 100644 --- a/tests/rm/Makefile.am +++ b/tests/rm/Makefile.am @@ -17,6 +17,9 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. TESTS = \ + deep-1 \ + hash \ + dangling-symlink \ v-slash \ i-never \ fail-eacces \ @@ -32,8 +35,8 @@ TESTS = \ dir-no-w \ fail-2eperm \ cycle i-no-r fail-eperm \ - dangling-symlink rm1 rm2 rm3 rm4 rm5 \ - unread2 r-1 r-2 r-3 r-4 i-1 ir-1 f-1 sunos-1 deep-1 hash \ + rm1 rm2 rm3 rm4 rm5 \ + unread2 r-1 r-2 r-3 r-4 i-1 ir-1 f-1 sunos-1 \ interactive-always interactive-once \ isatty # unreadable empty-name EXTRA_DIST = $(TESTS) @@ -48,3 +51,5 @@ TESTS_ENVIRONMENT = \ PATH="$(VG_PATH_PREFIX)`pwd`/../../src$(PATH_SEPARATOR)$$PATH" \ PACKAGE_VERSION=$(PACKAGE_VERSION) \ PROG=rm + +include $(top_srcdir)/tests/check.mk diff --git a/tests/rm/cycle b/tests/rm/cycle index b6e3576fd..9f7bfcc79 100755 --- a/tests/rm/cycle +++ b/tests/rm/cycle @@ -1,7 +1,7 @@ #!/bin/sh # rm (coreutils-4.5.4) could be tricked into mistakenly reporting a cycle. -# Copyright (C) 2003, 2006 Free Software Foundation, Inc. +# Copyright (C) 2003, 2006, 2007 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 @@ -22,25 +22,13 @@ if test "$VERBOSE" = yes; then fi . $srcdir/../lang-default -PRIV_CHECK_ARG=require-non-root . $srcdir/../priv-check +. $srcdir/../test-lib.sh +skip_if_root_ -pwd=`pwd` -t0=`echo "$0"|sed 's,.*/,,'`.tmp; tmp=$t0/$$ -trap 'status=$?; cd "$pwd" && chmod -R u+rwx $t0 && rm -rf $t0 && exit $status' 0 -trap '(exit $?); exit $?' 1 2 13 15 - -framework_failure=0 -mkdir -p $tmp || framework_failure=1 -cd $tmp || framework_failure=1 mkdir -p a/b touch a/b/file chmod u-w a/b -if test $framework_failure = 1; then - echo "$0: failure in testing framework" 1>&2 - (exit 1); exit 1 -fi - fail=0 rm -rf a a 2>&1 | sed 's/:[^:]*$//' > out || fail=1 @@ -49,7 +37,6 @@ rm: cannot remove `a/b/file' rm: cannot remove `a/b/file' EOF -cmp out exp || fail=1 -test $fail = 1 && diff out exp 2> /dev/null +compare out exp || fail=1 (exit $fail); exit $fail diff --git a/tests/rm/dangling-symlink b/tests/rm/dangling-symlink index 872819048..12d07312a 100755 --- a/tests/rm/dangling-symlink +++ b/tests/rm/dangling-symlink @@ -24,22 +24,11 @@ if test "$VERBOSE" = yes; then rm --version fi -pwd=`pwd` -t0=`echo "$0"|sed 's,.*/,,'`.tmp; tmp=$t0/$$ -trap 'status=$?; cd "$pwd" && chmod -R u+rwx $t0 && rm -rf $t0 && exit $status' 0 -trap '(exit $?); exit' 1 2 13 15 - -framework_failure=0 -mkdir -p $tmp || framework_failure=1 -cd $tmp || framework_failure=1 +. $srcdir/../test-lib.sh + ln -s no-file dangle ln -s / symlink -if test $framework_failure = 1; then - echo "$0: failure in testing framework" 1>&2 - (exit 1); exit 1 -fi - fail=0 rm ---presume-input-tty dangle symlink & diff --git a/tests/rm/deep-1 b/tests/rm/deep-1 index c9c60eb22..a0f72e82c 100755 --- a/tests/rm/deep-1 +++ b/tests/rm/deep-1 @@ -1,8 +1,7 @@ #!/bin/sh # Test "rm" with a deep hierarchy. -# Copyright (C) 1997, 2002, 2003, 2004, 2006 Free Software Foundation, -# Inc. +# Copyright (C) 1997, 2002-2004, 2006-2007 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 @@ -29,10 +28,7 @@ if test "$VERBOSE" = yes; then rm --version fi -pwd=`pwd` -t0=`echo "$0"|sed 's,.*/,,'`.tmp;tmp=$t0/$$ -trap 'status=$?; cd "$pwd" && rm -rf $t0 && exit $status' 0 -trap '(exit $?); exit' 1 2 13 15 +. $srcdir/../test-lib.sh umask 022 @@ -46,16 +42,17 @@ k200=$k20$k20$k20$k20$k20$k20$k20$k20$k20$k20 # operates on the full pathname (like `test') would choke. k_deep=$k200$k200 -# Create a directory in $tmp with lots of `k' components. -deep=$tmp$k_deep +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 $tmp || fail=1 +rm -r $t || fail=1 -# Make sure all of $tmp was deleted. -test -d $tmp && fail=1 +# Make sure all of $t was deleted. +test -d $t && fail=1 (exit $fail); exit $fail diff --git a/tests/rm/dir-no-w b/tests/rm/dir-no-w index c2fbf5bbb..2ed6926bf 100755 --- a/tests/rm/dir-no-w +++ b/tests/rm/dir-no-w @@ -2,7 +2,7 @@ # rm (without -r) must give a diagnostic for any directory. # It must not prompt, even if that directory is unwritable. -# Copyright (C) 2003, 2005, 2006 Free Software Foundation, Inc. +# Copyright (C) 2003, 2005, 2006, 2007 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 @@ -22,23 +22,10 @@ if test "$VERBOSE" = yes; then rm --version fi -. $srcdir/../envvar-check . $srcdir/../lang-default +. $srcdir/../test-lib.sh -pwd=`pwd` -t0=`echo "$0"|sed 's,.*/,,'`.tmp; tmp=$t0/$$ -trap 'status=$?; cd "$pwd" && chmod -R u+rwx $t0 && rm -rf $t0 && exit $status' 0 -trap '(exit $?); exit $?' 1 2 13 15 - -framework_failure=0 -mkdir -p $tmp || framework_failure=1 -cd $tmp || framework_failure=1 -mkdir --mode=0500 unwritable-dir || framework_failure=1 - -if test $framework_failure = 1; then - echo "$0: failure in testing framework" 1>&2 - (exit 1); exit 1 -fi +mkdir --mode=0500 unwritable-dir || framework_failure fail=0 @@ -56,7 +43,6 @@ EOF sed 's/remove directory/remove/' out-t > out rm -f out-t -cmp out exp || fail=1 -test $fail = 1 && diff out exp 2> /dev/null +compare out exp || fail=1 (exit $fail); exit $fail diff --git a/tests/rm/dir-nonrecur b/tests/rm/dir-nonrecur index 92ab1d495..b912e6362 100755 --- a/tests/rm/dir-nonrecur +++ b/tests/rm/dir-nonrecur @@ -2,7 +2,7 @@ # Ensure that `rm dir' (i.e., without --recursive) gives a reasonable # diagnostic when failing. -# Copyright (C) 2005, 2006 Free Software Foundation, Inc. +# Copyright (C) 2005, 2006, 2007 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 @@ -23,21 +23,9 @@ if test "$VERBOSE" = yes; then fi . $srcdir/../lang-default +. $srcdir/../test-lib.sh -pwd=`pwd` -t0=`echo "$0"|sed 's,.*/,,'`.tmp; tmp=$t0/$$ -trap 'status=$?; cd "$pwd" && chmod -R u+rwx $t0 && rm -rf $t0 && exit $status' 0 -trap '(exit $?); exit $?' 1 2 13 15 - -framework_failure=0 -mkdir -p $tmp || framework_failure=1 -cd $tmp || framework_failure=1 -mkdir d || framework_failure=1 - -if test $framework_failure = 1; then - echo "$0: failure in testing framework" 1>&2 - (exit 1); exit 1 -fi +mkdir d || framework_failure fail=0 @@ -47,7 +35,6 @@ rm: cannot remove `d': Is a directory EOF # Before coreutils-5.93 this test would fail on Solaris 9 and newer. -cmp out exp || fail=1 -test $fail = 1 && diff out exp 2> /dev/null +compare out exp || fail=1 (exit $fail); exit $fail diff --git a/tests/rm/dot-rel b/tests/rm/dot-rel index cb16b1af9..f31e6f04c 100755 --- a/tests/rm/dot-rel +++ b/tests/rm/dot-rel @@ -22,22 +22,10 @@ if test "$VERBOSE" = yes; then rm --version fi -pwd=`pwd` -t0=`echo "$0"|sed 's,.*/,,'`.tmp; tmp=$t0/$$ -trap 'status=$?; cd "$pwd" && chmod -R u+rwx $t0 && rm -rf $t0 && exit $status' 0 -trap '(exit $?); exit $?' 1 2 13 15 +. $srcdir/../test-lib.sh -framework_failure=0 -mkdir -p $tmp || framework_failure=1 -cd $tmp || framework_failure=1 - -mkdir a b || framework_failure=1 -touch a/f b/f || framework_failure=1 - -if test $framework_failure = 1; then - echo "$0: failure in testing framework" 1>&2 - (exit 1); exit 1 -fi +mkdir a b || framework_failure +touch a/f b/f || framework_failure fail=0 diff --git a/tests/rm/empty-inacc b/tests/rm/empty-inacc index a92b52849..32772e755 100755 --- a/tests/rm/empty-inacc +++ b/tests/rm/empty-inacc @@ -1,7 +1,7 @@ #!/bin/sh # Ensure that rm -rf removes an empty-and-inaccessible directory. -# Copyright (C) 2006 Free Software Foundation, Inc. +# Copyright (C) 2006, 2007 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 @@ -21,27 +21,15 @@ if test "$VERBOSE" = yes; then rm --version fi -PRIV_CHECK_ARG=require-non-root . $srcdir/../priv-check +. $srcdir/../test-lib.sh +skip_if_root_ -pwd=`pwd` -t0=`echo "$0"|sed 's,.*/,,'`.tmp; tmp=$t0/$$ -trap 'status=$?; cd "$pwd" && chmod -R u+rwx $t0 && rm -rf $t0 && exit $status' 0 -trap '(exit $?); exit $?' 1 2 13 15 - -framework_failure=0 -mkdir -p $tmp || framework_failure=1 -cd $tmp || framework_failure=1 -mkdir -m0 inacc || framework_failure=1 +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 -if test $framework_failure = 1; then - echo "$0: failure in testing framework" 1>&2 - (exit 1); exit 1 -fi - fail=0 # This would fail for e.g., coreutils-5.93. diff --git a/tests/rm/f-1 b/tests/rm/f-1 index 7fce0bb8c..750d66038 100755 --- a/tests/rm/f-1 +++ b/tests/rm/f-1 @@ -1,7 +1,7 @@ #!/bin/sh # Test "rm -f" with a nonexistent file. -# Copyright (C) 1997, 2002, 2004, 2006 Free Software Foundation, Inc. +# Copyright (C) 1997, 2002, 2004, 2006, 2007 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 @@ -23,20 +23,11 @@ if test "$VERBOSE" = yes; then rm --version fi -pwd=`pwd` -t0=`echo "$0"|sed 's,.*/,,'`.tmp;tmp=$t0/$$ -trap 'status=$?; cd "$pwd" && rm -rf $t0 && exit $status' 0 -trap '(exit $?); exit' 1 2 13 15 +. $srcdir/../test-lib.sh -test_failure=0 -mkdir -p $tmp || test_failure=1 - -if test $test_failure = 1; then - echo 'failure in testing framework' - exit 1 -fi +mkdir -p d || framework_failure fail=0 -rm -f $tmp/no-such-file || fail=1 +rm -f d/no-such-file || fail=1 (exit $fail); exit $fail diff --git a/tests/rm/fail-2eperm b/tests/rm/fail-2eperm index ed43807c9..bafd5bfcc 100755 --- a/tests/rm/fail-2eperm +++ b/tests/rm/fail-2eperm @@ -24,27 +24,14 @@ fi . $srcdir/../lang-default PRIV_CHECK_ARG=require-root . $srcdir/../priv-check - -pwd=`pwd` -t0=`echo "$0"|sed 's,.*/,,'`.tmp; tmp=$t0/$$ -trap 'status=$?; cd "$pwd" && chmod -R u+rwx $t0 && rm -rf $t0 && exit $status' 0 -trap '(exit $?); exit $?' 1 2 13 15 - -framework_failure=0 -mkdir -p $tmp || framework_failure=1 -cd $tmp || framework_failure=1 +. $srcdir/../test-lib.sh # The containing directory must be owned by the user who eventually runs rm. chown $NON_ROOT_USERNAME . -mkdir a || framework_failure=1 -chmod 1777 a || framework_failure=1 -touch a/b || framework_failure=1 - -if test $framework_failure = 1; then - echo "$0: failure in testing framework" 1>&2 - (exit 1); exit 1 -fi +mkdir a || framework_failure +chmod 1777 a || framework_failure +touch a/b || framework_failure fail=0 @@ -53,7 +40,7 @@ fail=0 rm_version=`setuidgid $NON_ROOT_USERNAME env PATH="$PATH" rm --version|sed -n '1s/.* //p'` case $rm_version in $PACKAGE_VERSION) ;; - *) echo "$0: cannot access required version ($PACKAGE_VERSION) of rm" 1>&2 + *) echo "$0: cannot access just-built rm as user $NON_ROOT_USERNAME" 1>&2 fail=1 ;; esac setuidgid $NON_ROOT_USERNAME env PATH="$PATH" rm -rf a 2> out-t && fail=1 @@ -67,7 +54,6 @@ cat <<\EOF > exp rm: cannot remove `a/b': Operation not permitted EOF -cmp out exp || fail=1 -test $fail = 1 && diff out exp 2> /dev/null +compare out exp || fail=1 (exit $fail); exit $fail diff --git a/tests/rm/fail-eacces b/tests/rm/fail-eacces index 3293ad550..b15c2f544 100755 --- a/tests/rm/fail-eacces +++ b/tests/rm/fail-eacces @@ -22,22 +22,10 @@ if test "$VERBOSE" = yes; then fi . $srcdir/../lang-default -PRIV_CHECK_ARG=require-non-root . $srcdir/../priv-check +. $srcdir/../test-lib.sh +skip_if_root_ -pwd=`pwd` -t0=`echo "$0"|sed 's,.*/,,'`.tmp; tmp=$t0/$$ -trap 'status=$?; cd "$pwd" && chmod -R u+rwx $t0 && rm -rf $t0 && exit $status' 0 -trap '(exit $?); exit $?' 1 2 13 15 - -framework_failure=0 -mkdir -p $tmp || framework_failure=1 -cd $tmp || framework_failure=1 -mkdir d && touch d/f && chmod a-w d || framework_failure=1 - -if test $framework_failure = 1; then - echo "$0: failure in testing framework" 1>&2 - (exit 1); exit 1 -fi +mkdir d && touch d/f && chmod a-w d || framework_failure fail=0 @@ -46,7 +34,6 @@ cat <<\EOF > exp rm: cannot remove `d/f': Permission denied EOF -cmp out exp || fail=1 -test $fail = 1 && diff out exp 2> /dev/null +compare out exp || fail=1 (exit $fail); exit $fail diff --git a/tests/rm/hash b/tests/rm/hash index 40c238ff9..0261eef2c 100755 --- a/tests/rm/hash +++ b/tests/rm/hash @@ -3,7 +3,7 @@ # Before then, rm would fail occasionally, sometimes via # a failed assertion, others with a seg fault. -# Copyright (C) 2000, 2002, 2003, 2004, 2006 Free Software Foundation, Inc. +# Copyright (C) 2000, 2002, 2003, 2004, 2006, 2007 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 @@ -25,29 +25,17 @@ if test "$VERBOSE" = yes; then rm --version fi -pwd=`pwd` -t0=`echo "$0"|sed 's,.*/,,'`.tmp;tmp=$t0/$$ -trap 'status=$?; cd "$pwd" && rm -rf $t0 || exit $?; exit $status' 0 -trap 'exit $?' 1 2 13 15 - -framework_failure=0 -mkdir -p $tmp || framework_failure=1 -cd $tmp +. $srcdir/../test-lib.sh # 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=1 + mkdir -p t/$i/$j/$y || framework_failure done done -if test $framework_failure = 1; then - echo 'failure in testing framework' - exit 1 -fi - fail=0 rm -r t || fail=1 diff --git a/tests/rm/i-1 b/tests/rm/i-1 index 14ba0dc38..b0d939c2a 100755 --- a/tests/rm/i-1 +++ b/tests/rm/i-1 @@ -1,7 +1,7 @@ #!/bin/sh # Test "rm -i". -# Copyright (C) 1997, 1998, 2002, 2004, 2006 Free Software Foundation, Inc. +# Copyright (C) 1997-1998, 2002, 2004, 2006-2007 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 @@ -23,33 +23,25 @@ if test "$VERBOSE" = yes; then rm --version fi -pwd=`pwd` -t0=`echo "$0"|sed 's,.*/,,'`.tmp;tmp=$t0/$$ -trap 'status=$?; cd "$pwd" && rm -rf $t0 && exit $status' 0 -trap '(exit $?); exit' 1 2 13 15 +. $srcdir/../test-lib.sh -test_failure=0 -mkdir -p $tmp || test_failure=1 -echo > $tmp/a || test_failure=1 -test -f $tmp/a || test_failure=1 +t=t +mkdir -p $t || framework_failure +echo > $t/a || framework_failure +test -f $t/a || framework_failure -if test $test_failure = 1; then - echo 'failure in testing framework' - exit 1 -fi - -echo y > $tmp/$test.Iy -echo n > $tmp/$test.In +echo y > $t/$test.Iy +echo n > $t/$test.In fail=0 -rm -i $tmp/a < $tmp/$test.In > /dev/null 2>&1 || fail=1 +rm -i $t/a < $t/$test.In > /dev/null 2>&1 || fail=1 # The file should not have been removed. -test -f $tmp/a || fail=1 +test -f $t/a || fail=1 -rm -i $tmp/a < $tmp/$test.Iy > /dev/null 2>&1 || fail=1 +rm -i $t/a < $t/$test.Iy > /dev/null 2>&1 || fail=1 # The file should have been removed this time. -test -f $tmp/a && fail=1 +test -f $t/a && fail=1 -rm -rf $tmp +rm -rf $t (exit $fail); exit $fail diff --git a/tests/rm/i-never b/tests/rm/i-never index c70e3eadf..16edcf6f7 100755 --- a/tests/rm/i-never +++ b/tests/rm/i-never @@ -22,30 +22,17 @@ if test "$VERBOSE" = yes; then rm --version fi -PRIV_CHECK_ARG=require-non-root . $srcdir/../priv-check - -pwd=`pwd` -t0=`echo "$0"|sed 's,.*/,,'`.tmp; tmp=$t0/$$ -trap 'status=$?; cd "$pwd" && chmod -R u+rwx $t0 && rm -rf $t0 && exit $status' 0 -trap '(exit $?); exit $?' 1 2 13 15 - -framework_failure=0 -mkdir -p $tmp || framework_failure=1 -cd $tmp || framework_failure=1 -touch f || framework_failure=1 -chmod 0 f || framework_failure=1 -touch exp || framework_failure=1 - -if test $framework_failure = 1; then - echo "$0: failure in testing framework" 1>&2 - (exit 1); exit 1 -fi +. $srcdir/../test-lib.sh +skip_if_root_ + +touch f || framework_failure +chmod 0 f || framework_failure +touch exp || framework_failure fail=0 rm --interactive=never f > out || fail=1 -cmp out exp || fail=1 -test $fail = 1 && diff out exp 2> /dev/null +compare out exp || fail=1 (exit $fail); exit $fail diff --git a/tests/rm/i-no-r b/tests/rm/i-no-r index 9362aed62..0c2e898d2 100755 --- a/tests/rm/i-no-r +++ b/tests/rm/i-no-r @@ -23,21 +23,10 @@ if test "$VERBOSE" = yes; then rm --version fi -pwd=`pwd` -t0=`echo "$0"|sed 's,.*/,,'`.tmp; tmp=$t0/$$ -trap 'status=$?; cd "$pwd" && chmod -R u+rwx $t0 && rm -rf $t0 && exit $status' 0 -trap '(exit $?); exit $?' 1 2 13 15 - -framework_failure=0 -mkdir -p $tmp || framework_failure=1 -cd $tmp || framework_failure=1 -mkdir dir || framework_failure=1 -echo y > y || framework_failure=1 - -if test $framework_failure = 1; then - echo "$0: failure in testing framework" 1>&2 - (exit 1); exit 1 -fi +. $srcdir/../test-lib.sh + +mkdir dir || framework_failure +echo y > y || framework_failure fail=0 diff --git a/tests/rm/ignorable b/tests/rm/ignorable index 142af2f94..a3fe1dcaf 100755 --- a/tests/rm/ignorable +++ b/tests/rm/ignorable @@ -1,7 +1,7 @@ #!/bin/sh # Ensure that rm -f existing-non-dir/anything exits successfully -# Copyright (C) 2006 Free Software Foundation, Inc. +# Copyright (C) 2006, 2007 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 @@ -21,22 +21,10 @@ if test "$VERBOSE" = yes; then rm --version fi -PRIV_CHECK_ARG=require-non-root . $srcdir/../priv-check +. $srcdir/../test-lib.sh +skip_if_root_ -pwd=`pwd` -t0=`echo "$0"|sed 's,.*/,,'`.tmp; tmp=$t0/$$ -trap 'status=$?; cd "$pwd" && chmod -R u+rwx $t0 && rm -rf $t0 && exit $status' 0 -trap '(exit $?); exit $?' 1 2 13 15 - -framework_failure=0 -mkdir -p $tmp || framework_failure=1 -cd $tmp || framework_failure=1 -touch existing-non-dir || framework_failure=1 - -if test $framework_failure = 1; then - echo "$0: failure in testing framework" 1>&2 - (exit 1); exit 1 -fi +touch existing-non-dir || framework_failure fail=0 diff --git a/tests/rm/inaccessible b/tests/rm/inaccessible index 0d6e5399e..8d05b3ede 100755 --- a/tests/rm/inaccessible +++ b/tests/rm/inaccessible @@ -2,7 +2,7 @@ # Ensure that rm works even when run from a directory # for which the user has no access at all. -# Copyright (C) 2004, 2006 Free Software Foundation, Inc. +# Copyright (C) 2004, 2006, 2007 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 @@ -22,7 +22,6 @@ if test "$VERBOSE" = yes; then rm --version fi -PRIV_CHECK_ARG=require-non-root . $srcdir/../priv-check . $srcdir/../lang-default # Skip this test if your system has neither the openat-style functions @@ -35,24 +34,14 @@ if test $skip = yes; then (exit 77); exit 77 fi -pwd=`pwd` -t0=`echo "$0"|sed 's,.*/,,'`.tmp; tmp=$t0/$$ -trap 'status=$?; cd "$pwd" && chmod -R u+rwx $t0 && rm -rf $t0 && exit $status' 0 -trap '(exit $?); exit $?' 1 2 13 15 +. $srcdir/../test-lib.sh +skip_if_root_ -framework_failure=0 -mkdir -p $tmp || framework_failure=1 -cd $tmp || framework_failure=1 -mkdir abs1 abs2 no-access || framework_failure=1 - -if test $framework_failure = 1; then - echo "$0: failure in testing framework" 1>&2 - (exit 1); exit 1 -fi +p=`pwd` +mkdir abs1 abs2 no-access || framework_failure fail=0 -p=$pwd/$tmp set +x (cd no-access; chmod 0 . && rm -r "$p/abs1" rel "$p/abs2") 2> out && fail=1 test -d "$p/abs1" && fail=1 @@ -68,7 +57,6 @@ EOF # to the expected one: sed 's/: The file access permissions.*/: Permission denied/'<out>o1;mv o1 out -cmp out exp || fail=1 -test $fail = 1 && diff out exp 2> /dev/null +compare out exp || fail=1 (exit $fail); exit $fail diff --git a/tests/rm/interactive-always b/tests/rm/interactive-always index 686ac2feb..f085ec169 100755 --- a/tests/rm/interactive-always +++ b/tests/rm/interactive-always @@ -1,7 +1,7 @@ #!/bin/sh # Test the --interactive[=WHEN] changes added to coreutils 6.0 -# Copyright (C) 2006 Free Software Foundation, Inc. +# Copyright (C) 2006, 2007 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 @@ -24,27 +24,14 @@ if test "$VERBOSE" = yes; then fi . $srcdir/../lang-default - -pwd=`pwd` -t0=`echo "$0"|sed 's,.*/,,'`.tmp; tmp=$t0/$$ -trap 'status=$?; cd "$pwd" && chmod -R u+rwx $t0 && rm -rf $t0 && exit $status' 0 -trap '(exit $?); exit $?' 1 2 13 15 - -framework_failure=0 -mkdir -p $tmp || framework_failure=1 -cd $tmp || framework_failure=1 +. $srcdir/../test-lib.sh touch file1-1 file1-2 file2-1 file2-2 file3-1 file3-2 file4-1 file4-2 \ - || framework_failure=1 + || framework_failure # If asked, answer no to first question, then yes to second. echo 'n -y' > $test.I || framework_failure=1 -rm -f out err || framework_failure=1 - -if test $framework_failure = 1; then - echo "$0: failure in testing framework" 1>&2 - (exit 1); exit 1 -fi +y' > $test.I || framework_failure +rm -f out err || framework_failure fail=0 @@ -102,10 +89,7 @@ rm: remove regular empty file `file4-1'? rm: remove regular empty file `file4-2' rm: remove all arguments recursively? . EOF -cmp out expout || fail=1 -cmp err experr || fail=1 -test $fail = 1 && { - diff out expout 2> /dev/null; diff err experr 2> /dev/null -} +compare out expout || fail=1 +compare err experr || fail=1 (exit $fail); exit $fail diff --git a/tests/rm/interactive-once b/tests/rm/interactive-once index cd3c2b234..e09db7c12 100755 --- a/tests/rm/interactive-once +++ b/tests/rm/interactive-once @@ -1,7 +1,7 @@ #!/bin/sh # Test the -I option added to coreutils 6.0 -# Copyright (C) 2006 Free Software Foundation, Inc. +# Copyright (C) 2006, 2007 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 @@ -24,27 +24,14 @@ if test "$VERBOSE" = yes; then fi . $srcdir/../lang-default +. $srcdir/../test-lib.sh -pwd=`pwd` -t0=`echo "$0"|sed 's,.*/,,'`.tmp; tmp=$t0/$$ -trap 'status=$?; cd "$pwd" && chmod -R u+rwx $t0 && rm -rf $t0 && exit $status' 0 -trap '(exit $?); exit $?' 1 2 13 15 - -framework_failure=0 -mkdir -p $tmp || framework_failure=1 -cd $tmp || framework_failure=1 - -mkdir -p dir1-1 dir2-1 dir2-2 || framework_failure=1 +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=1 -echo y > $test.Iy || framework_failure=1 -echo n > $test.In || framework_failure=1 -rm -f out err || framework_failure=1 - -if test $framework_failure = 1; then - echo "$0: failure in testing framework" 1>&2 - (exit 1); exit 1 -fi + || framework_failure +echo y > $test.Iy || framework_failure +echo n > $test.In || framework_failure +rm -f out err || framework_failure fail=0 @@ -122,10 +109,7 @@ multiple files, recursion, answer yes rm: remove all arguments recursively? . EOF -cmp out expout || fail=1 -cmp err experr || fail=1 -test $fail = 1 && { - diff out expout 2> /dev/null; diff err experr 2> /dev/null -} +compare out expout || fail=1 +compare err experr || fail=1 (exit $fail); exit $fail diff --git a/tests/rm/ir-1 b/tests/rm/ir-1 index 6bd278d47..c3af0acc1 100755 --- a/tests/rm/ir-1 +++ b/tests/rm/ir-1 @@ -1,7 +1,7 @@ #!/bin/sh # Test "rm -ir". -# Copyright (C) 1997, 1998, 2002, 2004, 2006 Free Software Foundation, +# Copyright (C) 1997, 1998, 2002, 2004, 2006, 2007 Free Software Foundation, # Inc. # This program is free software: you can redistribute it and/or modify @@ -24,21 +24,13 @@ if test "$VERBOSE" = yes; then rm --version fi -pwd=`pwd` -t0=`echo "$0"|sed 's,.*/,,'`.tmp;tmp=$t0/$$ -trap 'status=$?; cd "$pwd" && rm -rf $t0 && exit $status' 0 -trap '(exit $?); exit' 1 2 13 15 +. $srcdir/../test-lib.sh -test_failure=0 -mkdir -p $tmp $tmp/a $tmp/b $tmp/c || test_failure=1 -> $tmp/a/a || test_failure=1 -> $tmp/b/bb || test_failure=1 -> $tmp/c/cc || test_failure=1 - -if test $test_failure = 1; then - echo 'failure in testing framework' - exit 1 -fi +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 <<EOF > $test.I y @@ -58,17 +50,15 @@ EOF # determine which one was removed based on order of dir entries. # This is a good argument for switching to a dejagnu-style test suite. fail=0 -rm --verbose -i -r $tmp < $test.I > /dev/null 2>&1 || fail=1 +rm --verbose -i -r $t < $test.I > /dev/null 2>&1 || fail=1 -# $tmp should not have been removed. -test -d $tmp || fail=1 +# $t should not have been removed. +test -d $t || fail=1 # There should be only one directory left. -case `echo $tmp/*` in - $tmp/[abc]) ;; +case `echo $t/*` in + $t/[abc]) ;; *) fail=1 ;; esac -rm -rf $tmp $test.I - (exit $fail); exit $fail diff --git a/tests/rm/isatty b/tests/rm/isatty index 6c26c118c..cb3f0fd2b 100755 --- a/tests/rm/isatty +++ b/tests/rm/isatty @@ -1,8 +1,7 @@ #!/bin/sh # Make sure `chown 0 f; rm f' prompts before removing f. -# Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006 Free Software Foundation, -# Inc. +# Copyright (C) 2001-2007 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 @@ -23,21 +22,8 @@ if test "$VERBOSE" = yes; then fi . $srcdir/../lang-default -PRIV_CHECK_ARG=require-non-root . $srcdir/../priv-check - -pwd=`pwd` -t0=`echo "$0"|sed 's,.*/,,'`.tmp;tmp=$t0/$$ -trap 'status=$?; cd "$pwd" && rm -rf $t0 && exit $status' 0 -trap '(exit $?); exit' 1 2 13 15 - -framework_failure=0 -mkdir -p $tmp || framework_failure=1 -cd $tmp || framework_failure=1 - -if test $framework_failure = 1; then - echo 'failure in testing framework' 1>&2 - (exit 1); exit 1 -fi +. $srcdir/../test-lib.sh +skip_if_root_ fail=0 @@ -69,7 +55,6 @@ EOF # Append an `x' and a newline. echo x >> out -cmp out exp || fail=1 -test $fail = 1 && diff out exp 2> /dev/null +compare out exp || fail=1 (exit $fail); exit $fail diff --git a/tests/rm/no-give-up b/tests/rm/no-give-up index e112ff705..14d2a4694 100755 --- a/tests/rm/no-give-up +++ b/tests/rm/no-give-up @@ -23,26 +23,14 @@ if test "$VERBOSE" = yes; then fi PRIV_CHECK_ARG=require-root . $srcdir/../priv-check +. $srcdir/../test-lib.sh -pwd=`pwd` -t0=`echo "$0"|sed 's,.*/,,'`.tmp; tmp=$t0/$$ -trap 'status=$?; cd "$pwd" && chmod -R u+rwx $t0 && rm -rf $t0 && exit $status' 0 -trap '(exit $?); exit $?' 1 2 13 15 - -framework_failure=0 -mkdir -p $tmp || framework_failure=1 -cd $tmp || framework_failure=1 -mkdir d || framework_failure=1 -touch d/f || framework_failure=1 -chown -R $NON_ROOT_USERNAME d || framework_failure=1 +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=1 - -if test $framework_failure = 1; then - echo "$0: failure in testing framework" 1>&2 - (exit 1); exit 1 -fi +chmod go=x . || framework_failure fail=0 diff --git a/tests/rm/one-file-system b/tests/rm/one-file-system index 9d71a21c7..471216c2c 100755 --- a/tests/rm/one-file-system +++ b/tests/rm/one-file-system @@ -1,7 +1,7 @@ #!/bin/sh # Demonstrate rm's new --one-file-system option. -# Copyright (C) 2006 Free Software Foundation, Inc. +# Copyright (C) 2006, 2007 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 @@ -23,43 +23,26 @@ fi PRIV_CHECK_ARG=require-root . $srcdir/../priv-check . $srcdir/../lang-default -. $srcdir/../other-fs-tmpdir +. $srcdir/../test-lib.sh -if test -z "$other_partition_tmpdir"; then - (exit 77); exit 77 -fi - -pwd=`pwd` -t0=`echo "$0"|sed 's,.*/,,'`.tmp; tmp=$t0/$$ -trap 'status=$?; cd $pwd; chmod -R u+rwx $t0; rm -rf $t0 && exit $status' 0 -trap '(exit $?); exit $?' 1 2 13 15 - -t0="$t0 $other_partition_tmpdir" - -framework_failure=0 -mkdir -p $tmp || framework_failure=1 -cd $tmp || framework_failure=1 +# If used, these must *follow* test-lib.sh. +cleanup_() { rm -rf "$other_partition_tmpdir"; } +. "$abs_top_srcdir/tests/other-fs-tmpdir" t=$other_partition_tmpdir mkdir -p a/b $t/y -mount --bind $t a/b || framework_failure=1 +mount --bind $t a/b || framework_failure -cat <<\EOF > exp || framework_failure=1 +cat <<\EOF > exp || framework_failure rm: skipping `a/b', since it's on a different device EOF -if test $framework_failure = 1; then - echo "$0: setup failed; skipping this test" 1>&2 - (exit 77); exit 77 -fi - fail=0 rm --one-file-system -rf a 2> out && fail=1 test -d $t/y || fail=1 umount $t -cmp out exp || fail=1 -test $fail = 1 && diff out exp 2> /dev/null +compare out exp || fail=1 (exit $fail); exit $fail diff --git a/tests/rm/r-1 b/tests/rm/r-1 index 61350bb70..5e05d43ea 100755 --- a/tests/rm/r-1 +++ b/tests/rm/r-1 @@ -1,7 +1,7 @@ #!/bin/sh # Test "rm -r --verbose". -# Copyright (C) 1997, 1998, 2000, 2002, 2004, 2006 Free Software +# Copyright (C) 1997, 1998, 2000, 2002, 2004, 2006, 2007 Free Software # Foundation, Inc. # This program is free software: you can redistribute it and/or modify @@ -25,30 +25,17 @@ if test "$VERBOSE" = yes; then fi . $srcdir/../lang-default +. $srcdir/../test-lib.sh -pwd=`pwd` -t0=`echo "$0"|sed 's,.*/,,'`.tmp; tmp=$t0/$$ -trap 'status=$?; cd "$pwd" && rm -rf $t0 && exit $status' 0 -trap '(exit $?); exit' 1 2 13 15 +mkdir a a/a || framework_failure +> b || framework_failure -framework_failure=0 -mkdir -p $tmp || framework_failure=1 -cd $tmp || framework_failure=1 - -mkdir a a/a || framework_failure=1 -> b || framework_failure=1 - -cat <<\EOF > $test.E || framework_failure=1 +cat <<\EOF > $test.E || framework_failure removed directory: `a/a' removed directory: `a' removed `b' EOF -if test $framework_failure = 1; then - echo "$0: failure in testing framework" 1>&2 - (exit 1); exit 1 -fi - fail=0 rm --verbose -r a b > $test.O || fail=1 @@ -59,7 +46,6 @@ for d in $dirs; do done # Compare expected and actual output. -cmp $test.E $test.O || fail=1 -test $fail = 1 && diff $test.E $test.O 2> /dev/null +compare $test.E $test.O || fail=1 (exit $fail); exit $fail diff --git a/tests/rm/r-2 b/tests/rm/r-2 index d4ad64e34..0e381ad40 100755 --- a/tests/rm/r-2 +++ b/tests/rm/r-2 @@ -1,7 +1,7 @@ #!/bin/sh # Test "rm -r --verbose". -# Copyright (C) 1997, 1998, 2000, 2002, 2004, 2006 Free Software +# Copyright (C) 1997, 1998, 2000, 2002, 2004, 2006, 2007 Free Software # Foundation, Inc. # This program is free software: you can redistribute it and/or modify @@ -18,38 +18,25 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. if test "$VERBOSE" = yes; then - rm --version set -x + rm --version fi . $srcdir/../lang-default +. $srcdir/../test-lib.sh -pwd=`pwd` -t0=`echo "$0"|sed 's,.*/,,'`.tmp;tmp=$t0/$$ -trap 'status=$?; cd "$pwd" && rm -rf $t0 || exit $?; exit $status' 0 -trap 'exit $?' 1 2 13 15 - -framework_failure=0 -mkdir -p $tmp || framework_failure=1 -cd $tmp - -mkdir t t/a t/a/b || framework_failure=1 -> t/a/f || framework_failure=1 -> t/a/b/g || framework_failure=1 +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=1 +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 -if test $framework_failure = 1; then - echo 'failure in testing framework' - exit 1 -fi - # Note that both the expected output (above) and the actual output lines # are sorted, because directory entries may be processed in arbitrary order. fail=0 @@ -61,6 +48,5 @@ fi # Compare expected and actual output. cmp t/E t/O || fail=1 -test $fail = 1 && diff t/E t/O 2> /dev/null (exit $fail); exit $fail diff --git a/tests/rm/r-3 b/tests/rm/r-3 index feca33a5c..485832d0b 100755 --- a/tests/rm/r-3 +++ b/tests/rm/r-3 @@ -1,8 +1,7 @@ #!/bin/sh # Create and remove a directory with more than 254 files. -# Copyright (C) 1997, 2001, 2002, 2003, 2004, 2006 Free Software Foundation, -# Inc. +# Copyright (C) 1997, 2001-2004, 2006-2007 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 @@ -25,18 +24,14 @@ # are 338 or more files in a directory on a Darwin-6.5 system if test "$VERBOSE" = yes; then - rm --version set -x + rm --version fi -pwd=`pwd` -t0=`echo "$0"|sed 's,.*/,,'`.tmp;tmp=$t0/$$ -trap 'status=$?; cd "$pwd" && rm -rf $t0 && exit $status' 0 -trap '(exit $?); exit' 1 2 13 15 +. $srcdir/../test-lib.sh -framework_fail=0 -mkdir -p $tmp || framework_fail=1 -cd $tmp || framework_fail=1 +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 @@ -44,20 +39,15 @@ for i in 0 1 2 3 4 5 6 7 8 9 a b c d e f g h i j; 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; do files="$files $i$j" done - touch $files || framework_fail=1 + touch $files || framework_failure done -test -f 0a || framework_fail=1 -test -f by || framework_fail=1 -cd "$pwd" || framework_fail=1 - -if test $framework_fail = 1; then - echo 'failure in testing framework' - (exit 1); exit 1 -fi +test -f 0a || framework_failure +test -f by || framework_failure +cd .. || framework_failure fail=0 -rm -rf $tmp || fail=1 -test -d $tmp && fail=1 +rm -rf t || fail=1 +test -d t && fail=1 (exit $fail); exit $fail diff --git a/tests/rm/r-4 b/tests/rm/r-4 index b7a1fd2f0..8320542f7 100755 --- a/tests/rm/r-4 +++ b/tests/rm/r-4 @@ -1,7 +1,7 @@ #!/bin/sh # Try to remove '.' and '..' recursively. -# Copyright (C) 2006 Free Software Foundation, Inc. +# Copyright (C) 2006, 2007 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 @@ -16,39 +16,26 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. - if test "$VERBOSE" = yes; then - rm --version set -x + rm --version fi -pwd=`pwd` -t0=`echo "$0"|sed 's,.*/,,'`.tmp; tmp=$t0/$$ -trap 'status=$?; cd "$pwd" && rm -rf $t0 && exit $status' 0 -trap '(exit $?); exit' 1 2 13 15 +. $srcdir/../test-lib.sh -framework_failure=0 -mkdir -p $tmp || framework_failure=1 -cd $tmp || framework_failure=1 - -touch a || framework_failure=1 -cd "$pwd" || framework_failure=1 - -if test $framework_failure = 1; then - echo 'failure in testing framework' - (exit 1); exit 1 -fi +mkdir d || framework_failure +touch d/a || framework_failure fail=0 -rm -fr $tmp/. 2>/dev/null && fail=1 -rm -fr $tmp/./ 2>/dev/null && fail=1 -rm -fr $tmp/.//// 2>/dev/null && fail=1 -rm -fr $tmp/.. 2>/dev/null && fail=1 -rm -fr $tmp/../ 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 +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 $tmp/a || fail=1 +test -f d/a || fail=1 (exit $fail); exit $fail diff --git a/tests/rm/readdir-bug b/tests/rm/readdir-bug index b9e90b4ef..6386b7583 100755 --- a/tests/rm/readdir-bug +++ b/tests/rm/readdir-bug @@ -22,30 +22,18 @@ if test "$VERBOSE" = yes; then rm --version fi -pwd=`pwd` -t0=`echo "$0"|sed 's,.*/,,'`.tmp; tmp=$t0/$$ -trap 'status=$?; cd "$pwd" && chmod -R u+rwx $t0 && rm -rf $t0 && exit $status' 0 -trap '(exit $?); exit $?' 1 2 13 15 - -framework_failure=0 -mkdir -p $tmp || framework_failure=1 -cd $tmp || framework_failure=1 +. $srcdir/../test-lib.sh # 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=1 -cd b || framework_failure=1 +mkdir b || framework_failure +cd b || framework_failure for i in `seq 1 250`; do - touch `printf %040d $i` || framework_failure=1 + touch `printf %040d $i` || framework_failure done -cd .. || framework_failure=1 - -if test $framework_failure = 1; then - echo "$0: failure in testing framework" 1>&2 - (exit 1); exit 1 -fi +cd .. || framework_failure fail=0 diff --git a/tests/rm/rm1 b/tests/rm/rm1 index 1f062a6d7..37705639d 100755 --- a/tests/rm/rm1 +++ b/tests/rm/rm1 @@ -1,7 +1,7 @@ #!/bin/sh # exercise another small part of remove.c -# Copyright (C) 2002, 2004, 2006 Free Software Foundation, Inc. +# Copyright (C) 2002, 2004, 2006, 2007 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 @@ -21,25 +21,12 @@ if test "$VERBOSE" = yes; then rm --version fi -. $srcdir/../envvar-check . $srcdir/../lang-default -PRIV_CHECK_ARG=require-non-root . $srcdir/../priv-check +. $srcdir/../test-lib.sh +skip_if_root_ -pwd=`pwd` -t0=`echo "$0"|sed 's,.*/,,'`.tmp; tmp=$t0/$$ -trap 'status=$?; cd "$pwd" && chmod -R u+rwx $t0 && rm -rf $t0 && exit $status' 0 -trap '(exit $?); exit' 1 2 13 15 - -framework_failure=0 -mkdir -p $tmp || framework_failure=1 -cd $tmp || framework_failure=1 -mkdir -p b/a/p b/c b/d || framework_failure=1 -chmod u-w b/a || framework_failure=1 - -if test $framework_failure = 1; then - echo "$0: failure in testing framework" 1>&2 - (exit 1); exit 1 -fi +mkdir -p b/a/p b/c b/d || framework_failure +chmod u-w b/a || framework_failure fail=0 diff --git a/tests/rm/rm2 b/tests/rm/rm2 index 3798856ac..2524db06f 100755 --- a/tests/rm/rm2 +++ b/tests/rm/rm2 @@ -1,8 +1,7 @@ #!/bin/sh # exercise another small part of remove.c -# Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation, -# Inc. +# Copyright (C) 2002-2007 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 @@ -22,27 +21,14 @@ if test "$VERBOSE" = yes; then rm --version fi -. $srcdir/../envvar-check . $srcdir/../lang-default -PRIV_CHECK_ARG=require-non-root . $srcdir/../priv-check +. $srcdir/../test-lib.sh +skip_if_root_ -pwd=`pwd` -t0=`echo "$0"|sed 's,.*/,,'`.tmp; tmp=$t0/$$ -trap 'status=$?; cd "$pwd" && chmod -R u+rwx $t0 && rm -rf $t0 && exit $status' 0 -trap '(exit $?); exit' 1 2 13 15 - -framework_failure=0 -mkdir -p $tmp || framework_failure=1 -cd $tmp || framework_failure=1 -mkdir -p a/0 || framework_failure=1 -mkdir -p a/1/2 b/3 || framework_failure=1 -mkdir a/2 a/3 || framework_failure=1 -chmod u-x a/1 b || framework_failure=1 - -if test $framework_failure = 1; then - echo "$0: failure in testing framework" 1>&2 - (exit 1); exit 1 -fi +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 fail=0 @@ -60,7 +46,8 @@ 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; } +cmp out exp > /dev/null 2>&1 \ + || { cmp out exp-solaris > /dev/null 2>&1 || fail=1; } test $fail = 1 && diff out exp 2> /dev/null test -d a/0 && fail=1 diff --git a/tests/rm/rm3 b/tests/rm/rm3 index 9ec07e416..cfa1b02a7 100755 --- a/tests/rm/rm3 +++ b/tests/rm/rm3 @@ -1,7 +1,7 @@ #!/bin/sh # exercise another small part of remove.c -# Copyright (C) 2002, 2003, 2004, 2006 Free Software Foundation, Inc. +# Copyright (C) 2002, 2003, 2004, 2006, 2007 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 @@ -21,33 +21,20 @@ if test "$VERBOSE" = yes; then rm --version fi -. $srcdir/../envvar-check . $srcdir/../lang-default -PRIV_CHECK_ARG=require-non-root . $srcdir/../priv-check +. $srcdir/../test-lib.sh +skip_if_root_ -pwd=`pwd` -t0=`echo "$0"|sed 's,.*/,,'`.tmp; tmp=$t0/$$ -trap 'status=$?; cd "$pwd" && chmod -R u+rwx $t0 && rm -rf $t0 && exit $status' 0 -trap '(exit $?); exit' 1 2 13 15 - -framework_failure=0 -mkdir -p $tmp || framework_failure=1 -cd $tmp || framework_failure=1 -mkdir -p z || framework_failure=1 -cd z || framework_failure=1 -touch empty empty-u || framework_failure=1 +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=1 -chmod u-w fu du empty-u || framework_failure=1 +mkdir d du || framework_failure +chmod u-w fu du empty-u || framework_failure cd .. -if test $framework_failure = 1; then - echo "$0: failure in testing framework" 1>&2 - (exit 1); exit 1 -fi - fail=0 cat <<EOF > in @@ -85,8 +72,7 @@ rm: remove write-protected directory \`z/du' rm: remove directory \`z' EOF -cmp out exp || fail=1 -test $fail = 1 && diff -u out exp 2> /dev/null +compare out exp || fail=1 test -d z && fail=1 diff --git a/tests/rm/rm4 b/tests/rm/rm4 index 25a5c7b52..c158e6905 100755 --- a/tests/rm/rm4 +++ b/tests/rm/rm4 @@ -1,7 +1,7 @@ #!/bin/sh # ensure that `rm dir' fails without --recursive -# Copyright (C) 2002, 2004, 2006 Free Software Foundation, Inc. +# Copyright (C) 2002, 2004, 2006, 2007 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 @@ -21,24 +21,11 @@ if test "$VERBOSE" = yes; then rm --version fi -. $srcdir/../envvar-check . $srcdir/../lang-default -PRIV_CHECK_ARG=require-non-root . $srcdir/../priv-check +. $srcdir/../test-lib.sh +skip_if_root_ -pwd=`pwd` -t0=`echo "$0"|sed 's,.*/,,'`.tmp; tmp=$t0/$$ -trap 'status=$?; cd "$pwd" && chmod -R u+rwx $t0 && rm -rf $t0 && exit $status' 0 -trap '(exit $?); exit' 1 2 13 15 - -framework_failure=0 -mkdir -p $tmp || framework_failure=1 -cd $tmp || framework_failure=1 -mkdir dir || framework_failure=1 - -if test $framework_failure = 1; then - echo "$0: failure in testing framework" 1>&2 - (exit 1); exit 1 -fi +mkdir dir || framework_failure fail=0 diff --git a/tests/rm/rm5 b/tests/rm/rm5 index d7d72f40f..c3243233e 100755 --- a/tests/rm/rm5 +++ b/tests/rm/rm5 @@ -1,7 +1,7 @@ #!/bin/sh # a basic test of rm -ri -# Copyright (C) 2002, 2003, 2004, 2006 Free Software Foundation, Inc. +# Copyright (C) 2002-2004, 2006-2007 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 @@ -21,36 +21,23 @@ if test "$VERBOSE" = yes; then rm --version fi -. $srcdir/../envvar-check . $srcdir/../lang-default -PRIV_CHECK_ARG=require-non-root . $srcdir/../priv-check +. $srcdir/../test-lib.sh +skip_if_root_ -pwd=`pwd` -t0=`echo "$0"|sed 's,.*/,,'`.tmp; tmp=$t0/$$ -trap 'status=$?; cd "$pwd" && chmod -R u+rwx $t0 && rm -rf $t0 && exit $status' 0 -trap '(exit $?); exit' 1 2 13 15 - -framework_failure=0 -mkdir -p $tmp || framework_failure=1 -cd $tmp || framework_failure=1 -mkdir -p d/e || framework_failure=1 -cat <<EOF > in || framework_failure=1 +mkdir -p d/e || framework_failure +cat <<EOF > in || framework_failure y y y EOF -cat <<\EOF > exp || framework_failure=1 +cat <<\EOF > exp || framework_failure rm: descend into directory `d' rm: remove directory `d/e' rm: remove directory `d' EOF -if test $framework_failure = 1; then - echo "$0: failure in testing framework" 1>&2 - (exit 1); exit 1 -fi - fail=0 rm -ir d < in > out 2>&1 || fail=1 @@ -66,7 +53,6 @@ mv o2 out # Make sure it's been removed. test -d d && fail=1 -cmp out exp || fail=1 -test $fail = 1 && diff -u out exp 2> /dev/null +compare out exp || fail=1 (exit $fail); exit $fail diff --git a/tests/rm/sunos-1 b/tests/rm/sunos-1 index b1d2a6965..a0e431287 100755 --- a/tests/rm/sunos-1 +++ b/tests/rm/sunos-1 @@ -26,19 +26,7 @@ if test "$VERBOSE" = yes; then rm --version fi -pwd=`pwd` -t0=`echo "$0"|sed 's,.*/,,'`.tmp; tmp=$t0/$$ -trap 'status=$?; cd "$pwd" && rm -rf $t0 && exit $status' 0 -trap '(exit $?); exit' 1 2 13 15 - -framework_failure=0 -mkdir -p $tmp || framework_failure=1 -cd $tmp || framework_failure=1 - -if test $framework_failure = 1; then - echo "$0: failure in testing framework" 1>&2 - (exit 1); exit 1 -fi +. $srcdir/../test-lib.sh fail=0 rm -r '' > /dev/null 2>&1 && fail=1 diff --git a/tests/rm/unread2 b/tests/rm/unread2 index 7ba63512f..966bfa1b8 100755 --- a/tests/rm/unread2 +++ b/tests/rm/unread2 @@ -1,7 +1,7 @@ #!/bin/sh # exercise one small part of remove.c -# Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc. +# Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007 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 @@ -21,26 +21,13 @@ if test "$VERBOSE" = yes; then rm --version fi -. $srcdir/../envvar-check . $srcdir/../lang-default -PRIV_CHECK_ARG=require-non-root . $srcdir/../priv-check +. $srcdir/../test-lib.sh +skip_if_root_ -pwd=`pwd` -t0=`echo "$0"|sed 's,.*/,,'`.tmp; tmp=$t0/$$ -trap 'status=$?; cd "$pwd" && chmod -R u+rwx $t0 && rm -rf $t0 && exit $status' 0 -trap '(exit $?); exit' 1 2 13 15 - -framework_failure=0 -mkdir -p $tmp || framework_failure=1 -cd $tmp || framework_failure=1 -mkdir -p a/b || framework_failure=1 +mkdir -p a/b || framework_failure chmod u-r a -if test $framework_failure = 1; then - echo "$0: failure in testing framework" 1>&2 - (exit 1); exit 1 -fi - fail=0 # This should fail. @@ -49,7 +36,6 @@ cat <<\EOF > exp rm: cannot remove `a': Permission denied EOF -cmp out exp || fail=1 -test $fail = 1 && diff out exp 2> /dev/null +compare out exp || fail=1 (exit $fail); exit $fail diff --git a/tests/rm/unread3 b/tests/rm/unread3 index 6fb13d950..71089f5d6 100755 --- a/tests/rm/unread3 +++ b/tests/rm/unread3 @@ -1,7 +1,7 @@ #!/bin/sh # Ensure that rm works even from an unreadable working directory. -# Copyright (C) 2004, 2006 Free Software Foundation, Inc. +# Copyright (C) 2004, 2006, 2007 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 @@ -21,28 +21,16 @@ if test "$VERBOSE" = yes; then rm --version fi -PRIV_CHECK_ARG=require-non-root . $srcdir/../priv-check +. $srcdir/../test-lib.sh +skip_if_root_ -pwd=`pwd` -t0=`echo "$0"|sed 's,.*/,,'`.tmp; tmp=$t0/$$ -trap 'status=$?; cd "$pwd" && chmod -R u+rwx $t0 && rm -rf $t0 && exit $status' 0 -trap '(exit $?); exit $?' 1 2 13 15 - -framework_failure=0 -mkdir -p $tmp || framework_failure=1 -cd $tmp || framework_failure=1 -mkdir -p a/1 b c d/2 e/3 || framework_failure=1 - -if test $framework_failure = 1; then - echo "$0: failure in testing framework" 1>&2 - (exit 1); exit 1 -fi +mkdir -p a/1 b c d/2 e/3 || framework_failure fail=0 +t=`pwd` cd c chmod u=x,go= . -t=$pwd/$tmp # With coreutils-5.2.1, this would get a failed assertion. rm -r "$t/a" "$t/b" || fail=1 diff --git a/tests/rm/v-slash b/tests/rm/v-slash index ad20d5141..7e1fb3d47 100755 --- a/tests/rm/v-slash +++ b/tests/rm/v-slash @@ -21,21 +21,10 @@ if test "$VERBOSE" = yes; then rm --version fi -pwd=`pwd` -t0=`echo "$0"|sed 's,.*/,,'`.tmp; tmp=$t0/$$ -trap 'status=$?; cd "$pwd" && chmod -R u+rwx $t0 && rm -rf $t0 && exit $status' 0 -trap '(exit $?); exit $?' 1 2 13 15 - -framework_failure=0 -mkdir -p $tmp || framework_failure=1 -cd $tmp || framework_failure=1 -mkdir a || framework_failure=1 -touch a/x || framework_failure=1 - -if test $framework_failure = 1; then - echo "$0: failure in testing framework" 1>&2 - (exit 1); exit 1 -fi +. $srcdir/../test-lib.sh + +mkdir a || framework_failure +touch a/x || framework_failure fail=0 @@ -45,7 +34,6 @@ removed `a/x' removed directory: `a' EOF -cmp out exp || fail=1 -test $fail = 1 && diff out exp 2> /dev/null +compare out exp || fail=1 (exit $fail); exit $fail diff --git a/tests/rmdir/Makefile.am b/tests/rmdir/Makefile.am index eadbaba33..54e305142 100644 --- a/tests/rmdir/Makefile.am +++ b/tests/rmdir/Makefile.am @@ -9,3 +9,5 @@ TESTS_ENVIRONMENT = \ CU_TEST_NAME=`basename $(abs_srcdir)`,$$tst \ PATH="$(VG_PATH_PREFIX)`pwd`/../../src$(PATH_SEPARATOR)$$PATH" \ PROG=rmdir + +include $(top_srcdir)/tests/check.mk diff --git a/tests/rmdir/fail-perm b/tests/rmdir/fail-perm index acc5fe556..51e4cf7f7 100755 --- a/tests/rmdir/fail-perm +++ b/tests/rmdir/fail-perm @@ -2,7 +2,7 @@ # For unwritable directory `d', `rmdir -p d d/e/f' would emit # diagnostics but would not fail. Fixed in 5.1.2. -# Copyright (C) 2004, 2006 Free Software Foundation, Inc. +# Copyright (C) 2004, 2006, 2007 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 @@ -22,23 +22,10 @@ if test "$VERBOSE" = yes; then rmdir --version fi -PRIV_CHECK_ARG=require-non-root . $srcdir/../priv-check +. $srcdir/../test-lib.sh -pwd=`pwd` -t0=`echo "$0"|sed 's,.*/,,'`.tmp; tmp=$t0/$$ -trap 'status=$?; cd "$pwd" && chmod -R u+rwx $t0 && rm -rf $t0 && exit $status' 0 -trap '(exit $?); exit $?' 1 2 13 15 - -framework_failure=0 -mkdir -p $tmp || framework_failure=1 -cd $tmp || framework_failure=1 -mkdir d d/e d/e/f || framework_failure=1 -chmod a-w d || framework_failure=1 - -if test $framework_failure = 1; then - echo "$0: failure in testing framework" 1>&2 - (exit 1); exit 1 -fi +mkdir d d/e d/e/f || framework_failure +chmod a-w d || framework_failure fail=0 diff --git a/tests/rmdir/ignore b/tests/rmdir/ignore index 5b6a6bc3e..5acc786cb 100755 --- a/tests/rmdir/ignore +++ b/tests/rmdir/ignore @@ -1,7 +1,7 @@ #!/bin/sh # make sure rmdir's --ignore-fail-on-non-empty option works -# Copyright (C) 1999 Free Software Foundation, Inc. +# Copyright (C) 1999, 2007 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 @@ -21,23 +21,17 @@ if test "$VERBOSE" = yes; then rmdir --version fi -tmp=rmdir.$$ -trap "rm -rf $tmp" 0 1 2 3 15 +. $srcdir/../test-lib.sh -test_failure=0 -mkdir -p $tmp/a/b $tmp/x || test_failure=1 - -if test $test_failure = 1; then - echo "$0: failure in testing framework" 1>&2 - exit 1 -fi +cwd=`pwd` +mkdir -p $cwd/a/b $cwd/x || framework_failure fail=0 -rmdir -p --ignore-fail-on-non-empty $tmp/a/b || fail=1 -# $tmp/x should remain -test -d $tmp/x || fail=1 -# $tmp/{a,b} should be gone -test -d $tmp/a && fail=1 -test -d $tmp/a/b && fail=1 +rmdir -p --ignore-fail-on-non-empty $cwd/a/b || fail=1 +# $cwd/x should remain +test -d $cwd/x || fail=1 +# $cwd/{a,b} should be gone +test -d $cwd/a && fail=1 +test -d $cwd/a/b && fail=1 exit $fail diff --git a/tests/rmdir/t-slash b/tests/rmdir/t-slash index e85cbd081..4453f1606 100755 --- a/tests/rmdir/t-slash +++ b/tests/rmdir/t-slash @@ -1,7 +1,7 @@ #!/bin/sh # make sure rmdir -p works on a directory specified with a trailing slash -# Copyright (C) 2002, 2006 Free Software Foundation, Inc. +# Copyright (C) 2002, 2006, 2007 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 @@ -21,20 +21,9 @@ if test "$VERBOSE" = yes; then rmdir --version fi -pwd=`pwd` -t0=`echo "$0"|sed 's,.*/,,'`.tmp; tmp=$t0/$$ -trap 'status=$?; cd "$pwd" && chmod -R u+rwx $t0 && rm -rf $t0 && exit $status' 0 -trap '(exit $?); exit $?' 1 2 13 15 +. $srcdir/../test-lib.sh -framework_failure=0 -mkdir -p $tmp || framework_failure=1 -cd $tmp || framework_failure=1 -mkdir dir || framework_failure=1 - -if test $framework_failure = 1; then - echo "$0: failure in testing framework" 1>&2 - (exit 1); exit 1 -fi +mkdir dir || framework_failure fail=0 diff --git a/tests/sample-test b/tests/sample-test index ca9429345..e5e54e483 100644 --- a/tests/sample-test +++ b/tests/sample-test @@ -24,8 +24,8 @@ fi # FIXME: . $srcdir/../envvar-check # FIXME: . $srcdir/../lang-default # FIXME: PRIV_CHECK_ARG=require-root . $srcdir/../priv-check -# FIXME: PRIV_CHECK_ARG=require-non-root . $srcdir/../priv-check . $srcdir/../test-lib.sh +# FIXME skip_if_root_ # If used, these must *follow* test-lib.sh. # FIXME: cleanup_() { rm -rf "$other_partition_tmpdir"; } diff --git a/tests/test-lib.sh b/tests/test-lib.sh index 10571a1e6..9d47242e4 100644 --- a/tests/test-lib.sh +++ b/tests/test-lib.sh @@ -8,12 +8,41 @@ if test $? != 11; then (exit 77); exit 77 fi -framework_failure() +skip_test_() { - echo "$0: failure in testing framework" 1>&2 - (exit 1); exit 1 + echo "$0: skipping test: $@" 1>&2 + (exit 77); exit 77 +} + +uid_is_privileged_() +{ + # Make sure id -u succeeds. + my_uid=$(id -u) \ + || { echo "$0: cannot run \`id -u'" 1>&2; return 1; } + + # Make sure it gives valid output. + case $my_uid in + 0) ;; + *[!0-9]*) + echo "$0: invalid output (\`$my_uid') from \`id -u'" 1>&2 + return 1 ;; + *) return 1 ;; + esac } +skip_if_() +{ + case $1 in + root) skip_test_ must be run as root ;; + non-root) skip_test_ must be run as non-root ;; + *) ;; # FIXME? + esac +} + +skip_if_root_() { uid_is_privileged_ && skip_test_ "must be run as non-root"; } +error_() { echo "$0: $@" 1>&2; (exit 1); exit 1; } +framework_failure() { error_ 'failure in testing framework'; } + test_dir_=$(pwd) this_test_() { echo "./$0" | sed 's,.*/,,'; } @@ -27,7 +56,7 @@ this_test=$(this_test_) cleanup_() { :; } t_=$($abs_top_srcdir/tests/mkdtemp $test_dir_ cu-$this_test.XXXXXXXXXX) \ - || error "failed to create temporary directory in $test_dir_" + || error_ "failed to create temporary directory in $test_dir_" # Run each test from within a temporary sub-directory named after the # test itself, and arrange to remove it upon exception or normal exit. @@ -35,7 +64,7 @@ trap 'st=$?; cleanup_; d='"$t_"'; cd '"$test_dir_"' && chmod -R u+rwx "$d" && rm -rf "$d" && exit $st' 0 trap '(exit $?); exit $?' 1 2 13 15 -cd $t_ || error "failed to cd to $t_" +cd $t_ || error_ "failed to cd to $t_" if ( diff --version < /dev/null 2>&1 | grep GNU ) 2>&1 > /dev/null; then compare() { diff -u "$@"; } diff --git a/tests/touch/empty-file b/tests/touch/empty-file index 013d93f99..296faae27 100755 --- a/tests/touch/empty-file +++ b/tests/touch/empty-file @@ -38,16 +38,15 @@ fail=0 : ${TOUCH_DIR_LIST=.} -framework_failure=0 for d in $TOUCH_DIR_LIST; do rm -rf $d/a $d/b $d/c - > $d/a || framework_failure=1 - test -f $d/a || framework_failure=1 - > $d/b || framework_failure=1 - test -f $d/b || framework_failure=1 - > $d/c || framework_failure=1 - test -f $d/c || framework_failure=1 + > $d/a || framework_failure + test -f $d/a || framework_failure + > $d/b || framework_failure + test -f $d/b || framework_failure + > $d/c || framework_failure + test -f $d/c || framework_failure done echo sleeping for $SLEEP_SECONDS seconds... diff --git a/tests/touch/fail-diag b/tests/touch/fail-diag index b1abdba37..018d191e5 100755 --- a/tests/touch/fail-diag +++ b/tests/touch/fail-diag @@ -21,23 +21,14 @@ if test "$VERBOSE" = yes; then touch --version fi -. $srcdir/../envvar-check . $srcdir/../lang-default -PRIV_CHECK_ARG=require-non-root . $srcdir/../priv-check - . $srcdir/../test-lib.sh - -framework_failure=0 +skip_if_root_ d1=no-$$ dir=/$d1/such-dir # Ensure that $d1 doesn't already exist. -ls -d $d1 2> /dev/null && framework_failure=1 - -if test $framework_failure = 1; then - echo 'failure in testing framework' 1>&2 - (exit 1); exit 1 -fi +ls -d $d1 2> /dev/null && framework_failure fail=0 diff --git a/tests/touch/fifo b/tests/touch/fifo index 0e841a06c..796d330d9 100755 --- a/tests/touch/fifo +++ b/tests/touch/fifo @@ -23,13 +23,7 @@ fi . $srcdir/../test-lib.sh -framework_failure=0 - -tmp=fifo-$$ -rm -rf $tmp -mkfifo $tmp || framework_failure=1 - -if test $framework_failure = 1; then +if ! mkfifo fifo; then # Make an exception of this case -- usually we interpret framework-creation # failure as a test failure. However, in this case, when running on a SunOS # system using a disk NFS mounted from OpenBSD, the above fails like this: @@ -42,6 +36,6 @@ fi fail=0 -touch $tmp || fail=1 +touch fifo || fail=1 exit $fail diff --git a/tests/touch/no-rights b/tests/touch/no-rights index 72c3caad7..7fe9d29c6 100755 --- a/tests/touch/no-rights +++ b/tests/touch/no-rights @@ -25,17 +25,11 @@ fi . $srcdir/../test-lib.sh # Make sure t2 is newer than t1. -touch -d '2000-01-01 00:00' t1 || framework_failure=1 -touch -d '2000-01-02 00:00' t2 || framework_failure=1 +touch -d '2000-01-01 00:00' t1 || framework_failure +touch -d '2000-01-02 00:00' t2 || framework_failure -framework_failure=0 set x `ls -t t1 t2` -test "$*" = "x t2 t1" || framework_failure=1 - -if test $framework_failure = 1; then - echo "$0: failure in testing framework" 1>&2 - (exit 1); exit 1 -fi +test "$*" = "x t2 t1" || framework_failure fail=0 diff --git a/tests/touch/not-owner b/tests/touch/not-owner index a7496a006..9abb36ba1 100755 --- a/tests/touch/not-owner +++ b/tests/touch/not-owner @@ -23,7 +23,6 @@ if test "$VERBOSE" = yes; then fi . $srcdir/../lang-default -PRIV_CHECK_ARG=require-non-root . $srcdir/../priv-check test=../../src/test if $test -w /; then @@ -37,6 +36,7 @@ if $test -O / || $test -G /; then fi . $srcdir/../test-lib.sh +skip_if_root_ fail=0 diff --git a/tests/touch/read-only b/tests/touch/read-only index 771eca4af..e1389c280 100755 --- a/tests/touch/read-only +++ b/tests/touch/read-only @@ -21,18 +21,11 @@ if test "$VERBOSE" = yes; then touch --version fi -PRIV_CHECK_ARG=require-non-root . $srcdir/../priv-check - . $srcdir/../test-lib.sh +skip_if_root_ -framework_failure=0 -: > read-only || framework_failure=1 -chmod 444 read-only || framework_failure=1 - -if test $framework_failure = 1; then - echo "$0: failure in testing framework" 1>&2 - (exit 1); exit 1 -fi +: > read-only || framework_failure +chmod 444 read-only || framework_failure fail=0 diff --git a/tests/touch/relative b/tests/touch/relative index 02dfe9c6c..910a3782c 100755 --- a/tests/touch/relative +++ b/tests/touch/relative @@ -24,13 +24,7 @@ fi . $srcdir/../test-lib.sh -framework_failure=0 -TZ=UTC0 touch --date='2004-01-16 12:00 +0000' f || framework_failure=1 - -if test $framework_failure = 1; then - echo "$0: failure in testing framework" 1>&2 - (exit 1); exit 1 -fi +TZ=UTC0 touch --date='2004-01-16 12:00 +0000' f || framework_failure fail=0 |