Parallel "make check" support.
authorJim Meyering <jim@meyering.net>
Thu, 16 Aug 2007 14:28:11 +0000 (16:28 +0200)
committerJim Meyering <jim@meyering.net>
Sat, 15 Sep 2007 06:40:38 +0000 (08:40 +0200)
* build-aux/check.mk: New file, from The Vaucanson Group.
* .x-sc_GPL_version: New file, to allow "version 2 or later"
in build-aux/check.mk.
* Makefile.am (EXTRA_DIST): Add .x-sc_GPL_version.
* tests/check.mk: New file.
* tests/Makefile.am (EXTRA_DIST): Add check.mk, mkdtemp and test-lib.sh.

Begin factoring "sample-test" out of test scripts.
* tests/test-lib.sh: New file, to be sourced by all tests that
were previously derived from the "sample-test" template.
* tests/mkdtemp: New file.
* tests/touch/dir-1: Use test-lib.sh.
* tests/touch/empty-file: Likewise.
* tests/touch/fail-diag: Likewise.
* tests/touch/fifo: Likewise.
* tests/touch/no-create-missing: Likewise.
* tests/touch/no-rights: Likewise.  Also, don't sleep.
* tests/touch/not-owner: Likewise.
* tests/touch/obsolescent: Likewise.
* tests/touch/read-only: Likewise.
* tests/touch/relative: Likewise.
* tests/touch/Makefile.am: Include $(top_srcdir)/tests/check.mk,
to get the parallel-"make check" bits.

Move a slow test into tests/misc.

* tests/check.mk: Wrapper.
* tests/ls/time-1: Move this file to tests/misc/ls-time.
* tests/misc/ls-time: New file.  From tests/ls/time-1.
* tests/ls/Makefile.am (TESTS): Remove time-1.
* tests/misc/Makefile.am (TESTS): Add ls-time.

25 files changed:
.x-sc_GPL_version [new file with mode: 0644]
ChangeLog
Makefile.am
build-aux/check.mk
tests/Makefile.am
tests/check.mk [new file with mode: 0644]
tests/du/Makefile.am
tests/ls/Makefile.am
tests/misc/Makefile.am
tests/misc/cut
tests/misc/ls-time [moved from tests/ls/time-1 with 100% similarity]
tests/mkdtemp [new file with mode: 0755]
tests/test-lib.sh [new file with mode: 0644]
tests/touch/Makefile.am
tests/touch/dangling-symlink
tests/touch/dir-1
tests/touch/empty-file
tests/touch/fail-diag
tests/touch/fifo
tests/touch/no-create-missing
tests/touch/no-rights
tests/touch/not-owner
tests/touch/obsolescent
tests/touch/read-only
tests/touch/relative

diff --git a/.x-sc_GPL_version b/.x-sc_GPL_version
new file mode 100644 (file)
index 0000000..d496afa
--- /dev/null
@@ -0,0 +1 @@
+^build-aux/check\.mk$
index 5d537cf..3a499f3 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
        * src/install.c (main): Likewise.
        * NEWS: Document the fix.
 
+2007-08-20  Jim Meyering  <jim@meyering.net>
+
+       Parallel "make check" support.
+       * build-aux/check.mk: New file, from The Vaucanson Group.
+       * .x-sc_GPL_version: New file, to allow "version 2 or later"
+       in build-aux/check.mk.
+       * Makefile.am (EXTRA_DIST): Add .x-sc_GPL_version.
+       * tests/check.mk: New file.
+       * tests/Makefile.am (EXTRA_DIST): Add check.mk, mkdtemp and test-lib.sh.
+
+       Begin factoring "sample-test" out of test scripts.
+       * tests/test-lib.sh: New file, to be sourced by all tests that
+       were previously derived from the "sample-test" template.
+       * tests/mkdtemp: New file.
+       * tests/touch/dir-1: Use test-lib.sh.
+       * tests/touch/empty-file: Likewise.
+       * tests/touch/fail-diag: Likewise.
+       * tests/touch/fifo: Likewise.
+       * tests/touch/no-create-missing: Likewise.
+       * tests/touch/no-rights: Likewise.  Also, don't sleep.
+       * tests/touch/not-owner: Likewise.
+       * tests/touch/obsolescent: Likewise.
+       * tests/touch/read-only: Likewise.
+       * tests/touch/relative: Likewise.
+       * tests/touch/Makefile.am: Include $(top_srcdir)/tests/check.mk,
+       to get the parallel-"make check" bits.
+
 2007-08-18  Jim Meyering  <jim@meyering.net>
 
        Use new "idcache.h" header.
 
 2007-08-15  Jim Meyering  <jim@meyering.net>
 
+       Move a slow test into tests/misc.
+       * tests/ls/time-1: Move this file to tests/misc/ls-time.
+       * tests/misc/ls-time: New file.  From tests/ls/time-1.
+       * tests/ls/Makefile.am (TESTS): Remove time-1.
+       * tests/misc/Makefile.am (TESTS): Add ls-time.
+
        od --skip (-j) works even on files in /proc, when the kernel lies
        * src/od.c (skip): Don't let kernel misinformation (nonempty files
        in /proc with stat.st_size == 0) make "od -j N" misbehave.
index 8136526..7ff2e0b 100644 (file)
@@ -20,6 +20,7 @@ EXTRA_DIST = Makefile.cfg Makefile.maint GNUmakefile \
   .prev-version THANKS-to-translators THANKStt.in \
   .vg-suppressions \
   .x-po-check \
+  .x-sc_GPL_version \
   .x-sc_file_system .x-sc_obsolete_symbols \
   .x-sc_prohibit_atoi_atof \
   .x-sc_prohibit_strcmp \
index 0674f23..aee0370 100644 (file)
@@ -42,7 +42,7 @@ max < length($$0) {                                           \
   final= final (final ? "\n" : "") " " $$0;                    \
   max = length($$0);                                           \
 }                                                              \
-END {                                                          \
+END {                                                          \
   for (i = 0; i < max + 2 ; ++i)                               \
     line = line "=";                                           \
   print line;                                                  \
@@ -53,10 +53,11 @@ END {                                                               \
 # If stdout is a tty, use colors.  If test -t is not supported, then
 # this fails; a conservative approach.  Of course do not redirect
 # stdout here, just stderr...
-am__tty_colors =                               \
+am__tty_colors =                               \
 if test -t 1 2>/dev/null; then                 \
   red='\e[0;31m';                               \
   grn='\e[0;32m';                               \
+  lgn='\e[1;32m';                               \
   blu='\e[1;34m';                               \
   std='\e[m';                                   \
 fi
@@ -79,7 +80,7 @@ case $$estatus:" $(XFAIL_TESTS) " in                  \
     0:*" $$(basename $<) "*) col=$$red; res=XPASS;;    \
     0:*)                     col=$$grn; res=PASS ;;    \
     77:*)                    col=$$blu; res=SKIP ;;    \
-    *:*" $$(basename $<) "*) col=$$grn; res=XFAIL;;    \
+    *:*" $$(basename $<) "*) col=$$lgn; res=XFAIL;;    \
     *:*)                     col=$$red; res=FAIL ;;    \
 esac;                                                  \
 echo "$${col}$$res$${std}: $$(basename $<)";           \
@@ -109,24 +110,29 @@ $(TEST_SUITE_LOG): $(TEST_LOGS)
        skip=$$(echo "$$results" | grep -c '^SKIP');                    \
        xfail=$$(echo "$$results" | grep -c '^XFAIL');                  \
        xpass=$$(echo "$$results" | grep -c '^XPASS');                  \
-       case fail=$$fail:xfail=$$xfail:xpass=$$xpass in                 \
-         fail=0:xfail=0:xpass=*)                                       \
-           msg="All $$all tests passed.  ";;                           \
-         fail=0:xfail=*:xpass=*)                                       \
+       failures=$$(expr $$fail + $$xpass);                             \
+       case fail=$$fail:xpass=$$xpass:xfail=$$xfail in                 \
+         fail=0:xpass=0:xfail=0)                                       \
+           msg="All $$all tests passed.  ";                            \
+           exit=true;;                                                 \
+         fail=0:xpass=0:xfail=*)                                       \
            msg="All $$all tests behaved as expected";                  \
-           msg="$$msg ($$xfail expected failures).  ";;                \
-         fail=*:xfail=*:xpass=0)                                       \
-           msg="$$fail of $$all tests failed.  ";;                     \
-         fail=*:xfail=*:xpass=*)                                       \
-           msg="$$fail of $$all tests did not behave as expected";     \
-           msg="$$msg ($$xpass unexpected passes).  ";;                \
+           msg="$$msg ($$xfail expected failures).  ";                 \
+           exit=true;;                                                 \
+         fail=*:xpass=0:xfail=*)                                       \
+           msg="$$fail of $$all tests failed.  ";                      \
+           exit=false;;                                                \
+         fail=*:xpass=*:xfail=*)                                       \
+           msg="$$failures of $$all tests did not behave as expected"; \
+           msg="$$msg ($$xpass unexpected passes).  ";                 \
+           exit=false;;                                                \
          *)                                                            \
             echo >&2 "incorrect case"; exit 4;;                                \
        esac;                                                           \
        if test "$$skip" -ne 0; then                                    \
          msg="$$msg($$skip tests were not run).  ";                    \
        fi;                                                             \
-       if test "$$fail" -ne 0; then                                    \
+       if test "$$failures" -ne 0; then                                \
          {                                                             \
            echo "$(PACKAGE_STRING): $(subdir)/$(TEST_SUITE_LOG)" |     \
              $(am__rst_title);                                         \
@@ -149,13 +155,13 @@ $(TEST_SUITE_LOG): $(TEST_LOGS)
          fi;                                                           \
        fi;                                                             \
        $(am__tty_colors);                                              \
-       if test "$$fail" -eq 0; then echo $$grn; else echo $$red; fi;   \
+       if $$exit; then echo $$grn; else echo $$red; fi;                \
          echo "$$msg" | $(am__text_box);                               \
        echo $$std;                                                     \
-       if test x"$$VERBOSE" != x && test "$$fail" -ne 0; then          \
-         cat $(TEST_SUITE_LOG);                                        \
-       fi;                                                             \
-       test "$$fail" -eq 0
+       test x"$$VERBOSE" = x || $$exit || cat $(TEST_SUITE_LOG);       \
+       $$exit
+
+# if test x"$$VERBOSE" != x && ! $exit; then
 
 # Run all the tests.
 check-TESTS:
@@ -183,13 +189,13 @@ TEST_SUITE_HTML = $(TEST_SUITE_LOG:.log=.html)
          exit 2;                                                       \
        fi;                                                             \
        $$R2H $< >$@.tmp
-       mv $@.tmp $@
+       @mv $@.tmp $@
 
 # Be sure to run check-TESTS first, and then to convert the result.
 # Beware of concurrent executions.  And expect check-TESTS to fail.
 check-html:
        @if $(MAKE) $(AM_MAKEFLAGS) check-TESTS; then :; else   \
-         rv=$?;                                                \
+         rv=$$?;                                               \
          $(MAKE) $(AM_MAKEFLAGS) $(TEST_SUITE_HTML);           \
          exit $$rv;                                            \
        fi
index b39e5f2..5d91f59 100644 (file)
@@ -14,13 +14,32 @@ TESTS_ENVIRONMENT = \
   CU_TEST_NAME=`basename $(abs_srcdir)`,$$tst \
   PATH="$(VG_PATH_PREFIX)`pwd`/../src$(PATH_SEPARATOR)$$PATH"
 
-EXTRA_DIST = \
-  $(TESTS) Coreutils.pm CuTmpdir.pm Makefile.am.in README acl envvar-check \
-  expensive group-names input-tty lang-default mk-script \
-  other-fs-tmpdir priv-check \
-  rwx-to-mode sample-test selinux setgid-check sparse-file \
-  strace \
-  umask-check very-expensive
+EXTRA_DIST =           \
+  $(TESTS)             \
+  Coreutils.pm         \
+  CuTmpdir.pm          \
+  Makefile.am.in       \
+  README               \
+  acl                  \
+  check.mk             \
+  envvar-check         \
+  expensive            \
+  group-names          \
+  input-tty            \
+  lang-default         \
+  mk-script            \
+  mkdtemp              \
+  other-fs-tmpdir      \
+  priv-check           \
+  rwx-to-mode          \
+  sample-test          \
+  selinux              \
+  setgid-check         \
+  sparse-file          \
+  strace               \
+  test-lib.sh          \
+  umask-check          \
+  very-expensive
 
 ## N O T E :: Please do not add new tests/ directories.
 ## There are too many already.  Put new tests in misc/.
diff --git a/tests/check.mk b/tests/check.mk
new file mode 100644 (file)
index 0000000..f5c08a2
--- /dev/null
@@ -0,0 +1,22 @@
+# FIXME: add comment
+
+# Ensure that all version-controlled executable files are listed in TESTS.
+_v = TESTS
+FIXME_hook_this_to_make_distcheck:
+       sed -n '/^$(_v) =/,/[^\]$$/p' $(srcdir)/Makefile.am \
+         | sed 's/^  *//;/^\$$.*/d;/^$(_v) =/d' \
+         | tr -s '\012\\' '  ' | fmt -1 | sort -u > t1
+       find `$(top_srcdir)/build-aux/vc-list-files $(srcdir)` \
+           -type f -perm -111 -printf '%f\n'|sort -u \
+         | diff -u t1 -
+
+# Append this, because automake does the same.
+TESTS_ENVIRONMENT +=                   \
+  abs_top_srcdir=$(abs_top_srcdir)     \
+  srcdir=$(srcdir)
+
+TEST_LOGS = $(TESTS:=.log)
+
+# Parallel replacement of Automake's check-TESTS target.
+# Include it last.
+include $(top_srcdir)/build-aux/check.mk
index 71ef3f3..badc0c9 100644 (file)
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 TESTS = \
+  2g \
   inacc-dir \
   one-file-system \
   inacc-dest \
   long-from-unreadable \
   long-sloop \
-  2g \
   files0-from \
   inaccessible-cwd \
   deref-args \
@@ -34,3 +34,5 @@ TESTS_ENVIRONMENT = \
   PERL="$(PERL)" \
   CU_TEST_NAME=`basename $(abs_srcdir)`,$$tst \
   PATH="$(VG_PATH_PREFIX)`pwd`/../../src$(PATH_SEPARATOR)$$PATH"
+
+include $(top_srcdir)/tests/check.mk
index 2d6e0cd..b2aca8b 100644 (file)
@@ -22,7 +22,7 @@ TESTS = \
   stat-failed \
   stat-dtype \
   inode dangle file-type recursive dired infloop \
-  rt-1 time-1 symlink-slash follow-slink no-arg m-option \
+  rt-1 symlink-slash follow-slink no-arg m-option \
   stat-vs-dirent x-option
 
 EXTRA_DIST = $(TESTS)
index 236fb7f..98951d8 100644 (file)
@@ -25,7 +25,6 @@ TESTS_ENVIRONMENT = \
   top_srcdir=$(top_srcdir) \
   abs_top_builddir=$(abs_top_builddir) \
   abs_top_srcdir=$(abs_top_srcdir) \
-  srcdir=$(srcdir) \
   PACKAGE_VERSION=$(PACKAGE_VERSION) \
   PERL="$(PERL)" \
   BUILD_SRC_DIR="`pwd`/../../src" \
@@ -43,6 +42,7 @@ TESTS_ENVIRONMENT = \
 
 TESTS = \
   head-elide-tail \
+  ls-time \
   date \
   xstrtol \
   od \
@@ -97,8 +97,4 @@ TESTS = \
   test-diag \
   tty-eof
 
-TEST_LOGS = $(TESTS:=.log)
-
-# Parallel replacement of Automake's check-TESTS target.
-# Include it last: TEST_LOGS has a default value there.
-include $(top_srcdir)/build-aux/check.mk
+include $(top_srcdir)/tests/check.mk
index be23782..4475834 100755 (executable)
@@ -26,7 +26,7 @@ $PERL -e 1 > /dev/null 2>&1 || {
 }
 
 me=`echo $0|sed 's,.*/,,'`
-exec $PERL -w -I$srcdir/.. -MCoreutils -M"CuTmpdir qw($me)" -- - <<\FILE_EOF
+exec $PERL -w -I$srcdir/.. -MCoreutils -M"CuTmpdir qw($me)" -- - <<\EOF
 require 5.003;
 use strict;
 
similarity index 100%
rename from tests/ls/time-1
rename to tests/misc/ls-time
diff --git a/tests/mkdtemp b/tests/mkdtemp
new file mode 100755 (executable)
index 0000000..48fe054
--- /dev/null
@@ -0,0 +1,107 @@
+#!/bin/sh
+# Create a temporary directory, sort of like mktemp -d does.
+# Usage: mkdtemp /tmp phoey.XXXXXXXXXX
+
+# First, try to use the mktemp program.
+# Failing that, we'll roll our own mktemp-like function:
+#  - try to get random bytes from /dev/urandom
+#  - failing that, generate output from a combination of quickly-varying
+#      sources and gzip.  Ignore non-varying gzip header, and extract
+#      "random" bits from there.
+#  - given those bits, map to file-name bytes using tr, and try to create
+#      the desired directory.
+#  - make only $MAX_TRIES attempts
+
+ME=$(basename "$0")
+die() { echo >&2 "$ME: $@"; exit 1; }
+
+MAX_TRIES=4
+
+rand_bytes()
+{
+  n=$1
+
+  chars=abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789
+
+  dev_rand=/dev/urandom
+  if test -r "$dev_rand"; then
+    # Note: 256-length($chars) == 194; 3 copies of $chars is 186 + 8 = 194.
+    head -c$n "$dev_rand" | tr -c $chars 01234567$chars$chars$chars
+    return
+  fi
+
+  cmds='date; date +%N; free; who -a; w; ps auxww; ps ef; netstat -n'
+  data=$( (eval "$cmds") 2>&1 | gzip )
+
+  n_plus_50=$(expr $n + 50)
+
+  # Ensure that $data has length at least 50+$n
+  while :; do
+    len=$(echo "$data"|wc -c)
+    test $n_plus_50 -le $len && break;
+    data=$( (echo "$data"; eval "$cmds") 2>&1 | gzip )
+  done
+
+  echo "$data" \
+    | dd bs=1 skip=50 count=$n 2>/dev/null \
+    | tr -c $chars 01234567$chars$chars$chars
+}
+
+mkdtemp()
+{
+  case $# in
+  2);;
+  *) die "Usage: $ME DIR TEMPLATE";;
+  esac
+
+  destdir=$1
+  template=$2
+
+  case $template in
+  *XXXX) ;;
+  *) die "invalid template: $template (must have a suffix of at least 4 X's)";;
+  esac
+
+  fail=0
+
+  # First, try to use mktemp.
+  d=$(env -u TMPDIR mktemp -d -t -p "$destdir" "$template" 2>/dev/null) \
+    || fail=1
+
+  # The resulting name must be in the specified directory.
+  case $d in "$destdir"*);; *) fail=1;; esac
+
+  # It must have created the directory.
+  test -d "$d" || fail=1
+
+  # It must have 0700 permissions.
+  perms=$(ls -dgo "$d" 2>/dev/null) || fail=1
+  case $perms in drwx------*) ;; *) fail=1;; esac
+
+  test $fail = 0 && {
+    echo "$d"
+    return
+  }
+
+  # If we reach this point, we'll have to create a directory manually.
+
+  # Get a copy of the template without its suffix of X's.
+  base_template=$(echo "$template"|sed 's/XX*$//')
+
+  # Calculate how many X's we've just removed.
+  nx=$(expr length "$template" - length "$base_template")
+
+  err=
+  i=1
+  while :; do
+    X=$(rand_bytes $nx)
+    candidate_dir="$destdir/$base_template$X"
+    err=$(mkdir -m 0700 "$candidate_dir" 2>&1) \
+      && { echo "$candidate_dir"; return; }
+    test $MAX_TRIES -le $i && break;
+    i=$(expr $i + 1)
+  done
+  die "$err"
+}
+
+mkdtemp "$@"
diff --git a/tests/test-lib.sh b/tests/test-lib.sh
new file mode 100644 (file)
index 0000000..79d0ef2
--- /dev/null
@@ -0,0 +1,40 @@
+# source this file; set up for tests
+
+# Skip this test if the shell lacks support for functions.
+unset function_test
+eval 'function_test() { return 11; }; function_test'
+if test $? != 11; then
+  echo "$0: /bin/sh lacks support for functions; skipping this test." 1>&2
+  (exit 77); exit 77
+fi
+
+test_dir_=$(pwd)
+
+this_test_() { echo "./$0" | sed 's,.*/,,'; }
+this_test=$(this_test_)
+
+. $srcdir/../envvar-check
+
+# This is a stub function that is run upon trap (upon regular exit and
+# interrupt).  Override it with a per-test function, e.g., to unmount
+# a partition, or to undo any other global state changes.
+cleanup_() { :; }
+
+t_=$($abs_top_srcdir/tests/mkdtemp $test_dir_ cu-$this_test.XXXXXXXXXX) \
+    || 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.
+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_"
+
+if ( diff --version < /dev/null 2>&1 | grep GNU ) 2>&1 > /dev/null; then
+  compare() { diff -u "$@"; }
+elif ( cmp --version < /dev/null 2>&1 | grep GNU ) 2>&1 > /dev/null; then
+  compare() { cmp -s "$@"; }
+else
+  compare() { cmp "$@"; }
+fi
index e772f38..6978a51 100644 (file)
@@ -26,3 +26,5 @@ TESTS_ENVIRONMENT = \
   host_triplet=$(host_triplet) \
   CU_TEST_NAME=`basename $(abs_srcdir)`,$$tst \
   PATH="$(VG_PATH_PREFIX)`pwd`/../../src$(PATH_SEPARATOR)$$PATH"
+
+include $(top_srcdir)/tests/check.mk
index c3c00e9..908f30a 100755 (executable)
@@ -2,7 +2,7 @@
 # Make sure touch can create a file through a dangling symlink.
 # This was broken in the 4.0[e-i] test releases.
 
-# Copyright (C) 1999, 2000 Free Software Foundation, Inc.
+# Copyright (C) 1999, 2000, 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,6 +22,8 @@ if test "$VERBOSE" = yes; then
   touch --version
 fi
 
+. $srcdir/../test-lib.sh
+
 rm -f touch-target t-symlink
 ln -s touch-target t-symlink
 fail=0
index bbfbd68..383e00d 100755 (executable)
@@ -7,6 +7,8 @@ if test "$VERBOSE" = yes; then
   touch --version
 fi
 
+. $srcdir/../test-lib.sh
+
 fail=0
 touch . || fail=1
 exit $fail
index 6ab07e3..013d93f 100755 (executable)
@@ -1,7 +1,7 @@
 #!/bin/sh
 # Make sure touch can set the mtime on an empty file.
 
-# Copyright (C) 1998, 1999, 2000, 2005, 2006 Free Software Foundation, Inc.
+# Copyright (C) 1998, 1999, 2000, 2005-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
@@ -26,7 +26,7 @@ if test "$VERBOSE" = yes; then
   touch --version
 fi
 
-. $srcdir/../envvar-check
+. $srcdir/../test-lib.sh
 
 DEFAULT_SLEEP_SECONDS=2
 SLEEP_SECONDS=${SLEEP_SECONDS=$DEFAULT_SLEEP_SECONDS}
@@ -50,11 +50,6 @@ for d in $TOUCH_DIR_LIST; do
   test -f $d/c || framework_failure=1
 done
 
-if test $framework_failure = 1; then
-  echo 'failure in testing framework'
-  exit 1
-fi
-
 echo sleeping for $SLEEP_SECONDS seconds...
 sleep $SLEEP_SECONDS
 for d in $TOUCH_DIR_LIST; do
index a43b0d9..b1abdba 100755 (executable)
@@ -1,7 +1,7 @@
 #!/bin/sh
 # make sure touch gives reasonable diagnostics
 
-# Copyright (C) 2001, 2002, 2003, 2004, 2006 Free Software Foundation, Inc.
+# Copyright (C) 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,14 +25,9 @@ fi
 . $srcdir/../lang-default
 PRIV_CHECK_ARG=require-non-root . $srcdir/../priv-check
 
-pwd=`pwd`
-tmp=fail-diag.$$
-trap 'status=$?; cd "$pwd" && rm -rf $tmp && exit $status' 0
-trap '(exit $?); exit' 1 2 13 15
+. $srcdir/../test-lib.sh
 
 framework_failure=0
-mkdir $tmp || framework_failure=1
-cd $tmp || framework_failure=1
 
 d1=no-$$
 dir=/$d1/such-dir
@@ -51,7 +46,6 @@ cat <<EOF > exp
 touch: cannot touch \`$dir': No such file or directory
 EOF
 
-cmp out exp || fail=1
-test $fail = 1 && diff out exp 2> /dev/null
+compare out exp || fail=1
 
 (exit $fail); exit $fail
index 335b0c2..0e841a0 100755 (executable)
@@ -1,7 +1,7 @@
 #!/bin/sh
 # Make sure touch works on fifos without hanging.
 
-# Copyright (C) 2000 Free Software Foundation, Inc.
+# Copyright (C) 2000, 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,6 +21,8 @@ if test "$VERBOSE" = yes; then
   touch --version
 fi
 
+. $srcdir/../test-lib.sh
+
 framework_failure=0
 
 tmp=fifo-$$
@@ -41,6 +43,5 @@ fi
 fail=0
 
 touch $tmp || fail=1
-rm -rf $tmp
 
 exit $fail
index c18db48..79a2452 100755 (executable)
@@ -1,7 +1,7 @@
 #!/bin/sh
 # Ensure that touch -c no-such-file no longer fails (it did in 4.1.8).
 
-# Copyright (C) 2002, 2004, 2005, 2006 Free Software Foundation, Inc.
+# Copyright (C) 2002, 2004-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,19 +21,7 @@ if test "$VERBOSE" = yes; then
   touch --version
 fi
 
-pwd=`pwd`
-tmp=`echo "$0"|sed 's,.*/,,'`.tmp
-trap 'status=$?; cd "$pwd" && rm -rf $tmp && exit $status' 0
-trap '(exit $?); exit' 1 2 13 15
-
-framework_failure=0
-mkdir $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
 
@@ -41,11 +29,13 @@ touch -c no-file > /dev/null 2>&1 || fail=1
 touch -cm no-file > /dev/null 2>&1 || fail=1
 touch -ca no-file > /dev/null 2>&1 || fail=1
 
+test="$abs_top_builddir/src/test"
+
 # If >&- works, test "touch -c -" etc.
 # >&- apparently does not work in HP-UX 11.23.
 # This test is ineffective unless /dev/stdout also works.
-if "$pwd/../../src/test" -w /dev/stdout >/dev/null &&
-   "$pwd/../../src/test" ! -w /dev/stdout >&-; then
+if "$test" -w /dev/stdout >/dev/null &&
+   "$test" ! -w /dev/stdout >&-; then
   touch -c - >&- 2> /dev/null || fail=1
   touch -cm - >&- 2> /dev/null || fail=1
   touch -ca - >&- 2> /dev/null || fail=1
index e867d30..72c3caa 100755 (executable)
@@ -2,7 +2,7 @@
 # Make sure touch can update the times on a file that is neither
 # readable nor writable.
 
-# Copyright (C) 1999, 2000, 2002, 2006 Free Software Foundation, Inc.
+# Copyright (C) 1999, 2000, 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
@@ -22,34 +22,30 @@ if test "$VERBOSE" = yes; then
   touch --version
 fi
 
-. $srcdir/../envvar-check
+. $srcdir/../test-lib.sh
 
-DEFAULT_SLEEP_SECONDS=2
-SLEEP_SECONDS=${SLEEP_SECONDS=$DEFAULT_SLEEP_SECONDS}
+# 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
 
-t1=no-rw1
-t2=no-rw2
-rm -rf $t1 $t2
-: > $t1
+framework_failure=0
+set x `ls -t t1 t2`
+test "$*" = "x t2 t1" || framework_failure=1
 
-# Make sure $t2 is two seconds newer than $t1.
-echo sleeping for $SLEEP_SECONDS seconds...
-sleep $SLEEP_SECONDS
-: > $t2
-fail=0
+if test $framework_failure = 1; then
+  echo "$0: failure in testing framework" 1>&2
+  (exit 1); exit 1
+fi
 
-set x `ls -t $t1 $t2`
-test "$*" = "x $t2 $t1" || fail=1
+fail=0
 
-chmod 0 $t1
-touch -d tomorrow -c $t1 || fail=1
+chmod 0 t1
+touch -d '2000-01-03 00:00' -c t1 || fail=1
 
-set x `ls -t $t1 $t2`
-test "$*" = "x $t1 $t2" || fail=1
+set x `ls -t t1 t2`
+test "$*" = "x t1 t2" || fail=1
 
 # Also test the combination of --no-create and -a.
-touch -a --no-create $t1 || fail=1
-
-rm -f $t1 $t2
+touch -a --no-create t1 || fail=1
 
 exit $fail
index 3719eb2..a7496a0 100755 (executable)
@@ -2,7 +2,7 @@
 # Make sure that touch gives reasonable diagnostics when applied
 # to an unwritable directory owned by some other user.
 
-# Copyright (C) 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
+# Copyright (C) 2003-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
   touch --version
 fi
 
-. $srcdir/../envvar-check
 . $srcdir/../lang-default
 PRIV_CHECK_ARG=require-non-root . $srcdir/../priv-check
 
@@ -37,19 +36,7 @@ if $test -O / || $test -G /; 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
-
-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
 
index a1504f3..dc1008d 100755 (executable)
@@ -1,7 +1,7 @@
 #!/bin/sh
 # Test touch with obsolescent 8- or 10-digit time stamps.
 
-# Copyright (C) 2000, 2004, 2005, 2006 Free Software Foundation, Inc.
+# Copyright (C) 2000, 2004-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
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-_POSIX2_VERSION=199209; export _POSIX2_VERSION
-POSIXLY_CORRECT=1; export POSIXLY_CORRECT
-
 if test "$VERBOSE" = yes; then
   set -x
   touch --version
 fi
 
-pwd=`pwd`
-tmp=obsol.$$
-trap 'status=$?; cd "$pwd" && rm -rf $tmp && exit $status' 0
-trap '(exit $?); exit' 1 2 13 15
-
-framework_failure=0
-mkdir $tmp || framework_failure=1
-cd $tmp || framework_failure=1
+. $srcdir/../test-lib.sh
 
-if test $framework_failure = 1; then
-  echo 'failure in testing framework'
-  (exit 1); exit 1
-fi
+_POSIX2_VERSION=199209; export _POSIX2_VERSION
+POSIXLY_CORRECT=1; export POSIXLY_CORRECT
 
 fail=0
 
index e0daef6..771eca4 100755 (executable)
@@ -1,7 +1,7 @@
 #!/bin/sh
 # ensure that touch can operate on read-only files
 
-# Copyright (C) 2005, 2006 Free Software Foundation, Inc.
+# Copyright (C) 2005-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,15 +23,9 @@ 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
+. $srcdir/../test-lib.sh
 
 framework_failure=0
-mkdir -p $tmp || framework_failure=1
-cd $tmp || framework_failure=1
-
 : > read-only || framework_failure=1
 chmod 444 read-only || framework_failure=1
 
index 925c834..02dfe9c 100755 (executable)
@@ -2,7 +2,7 @@
 # Demonstrate using a combination of --reference and --date to
 # set the time of a file back by an arbitrary amount.
 
-# 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,16 +22,9 @@ if test "$VERBOSE" = yes; then
   touch --version
 fi
 
-. $srcdir/../envvar-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
+. $srcdir/../test-lib.sh
 
 framework_failure=0
-mkdir -p $tmp || framework_failure=1
-cd $tmp || framework_failure=1
 TZ=UTC0 touch --date='2004-01-16 12:00 +0000' f || framework_failure=1
 
 if test $framework_failure = 1; then
@@ -51,7 +44,6 @@ cat <<\EOF > exp || fail=1
 2004-01-11
 EOF
 
-cmp out exp || fail=1
-test $fail = 1 && diff out exp 2> /dev/null
+compare out exp || fail=1
 
 (exit $fail); exit $fail