Merge branch 'maint'
authorStefano Lattarini <stefano.lattarini@gmail.com>
Fri, 22 Jun 2012 16:55:01 +0000 (18:55 +0200)
committerStefano Lattarini <stefano.lattarini@gmail.com>
Fri, 22 Jun 2012 16:55:01 +0000 (18:55 +0200)
* maint:
  tests: prefer using 'is_newest' over 'ls -t' hacks
  tests: implement is_newest as an auxiliary script, not shell function
  tests: fix some spurious failures in VPATH setup
  tests: work in VPATH setup again

20 files changed:
Makefile.am
defs
syntax-checks.mk
t/acloca13.sh
t/acloca14.sh
t/aclocal7.sh
t/autohdr4.sh
t/ax/is_newest [new file with mode: 0755]
t/ax/test-init.sh
t/extradep.sh
t/extradep2.sh
t/lex-depend-cxx.sh
t/lex-depend.sh
t/lex-pr204.sh
t/maken.sh
t/self-check-cleanup.tap
t/self-check-reexec.tap
t/yacc-depend2.sh
t/yacc-pr204.sh
t/yacc8.sh

index d9f0ae2..872714e 100644 (file)
@@ -322,7 +322,7 @@ TAP_LOG_DRIVER = AM_TAP_AWK='$(AWK)' $(SHELL) $(srcdir)/lib/tap-driver.sh
 
 AM_TAP_LOG_DRIVER_FLAGS = --merge
 
-EXTRA_DIST += t/README t/ax/is
+EXTRA_DIST += t/README t/ax/is t/ax/is_newest
 
 TESTS = ## Will be updated later.
 
diff --git a/defs b/defs
index bef8b23..d16758c 100644 (file)
--- a/defs
+++ b/defs
 # might be just a Bourne shell, non POSIX-conforming, like on Solaris
 # up to version 11 at least).
 
-# Ensure we are running from the right directory.
-for f in defs-static t/ax/test-init.sh; do
-  if test ! -f ./$f; then
-   echo "$0: ./$f: not found in current directory" >&2
-   exit 99
-  fi
-done
-
 # Source the shell static setup and variable definitions.
 . ./defs-static
 test $? -eq 0 || exit 99
index 81d01af..d9302da 100644 (file)
@@ -63,6 +63,7 @@ sc_tests_automake_fails \
 sc_tests_required_after_defs \
 sc_tests_overriding_macros_on_cmdline \
 sc_tests_plain_sleep \
+sc_tests_ls_t \
 sc_m4_am_plain_egrep_fgrep \
 sc_tests_no_configure_in \
 sc_tests_PATH_SEPARATOR \
@@ -366,6 +367,16 @@ sc_tests_overriding_macros_on_cmdline:
          exit 1; \
        fi
 
+## Prefer use of our 'is_newest' auxiliary script over the more hacky
+## idiom "test $(ls -1t new old | sed 1q) = new", which is both more
+## cumbersome and more fragile.
+sc_tests_ls_t:
+       @if LC_ALL=C grep -E '\bls(\s+-[a-zA-Z0-9]+)*\s+-[a-zA-Z0-9]*t' \
+           $(xtests); then \
+         echo "Use 'is_newest' rather than hacks based on 'ls -t'" 1>&2; \
+         exit 1; \
+       fi
+
 ## Never use 'sleep 1' to create files with different timestamps.
 ## Use '$sleep' instead.  Some filesystems (e.g., Windows) have only
 ## a 2sec resolution.
index aab2daf..6d6f6c0 100755 (executable)
@@ -59,9 +59,8 @@ grep version1 aclocal.m4
 $sleep
 # aclocal.m4 should change if we touch otherfile.m4
 touch m4/otherfile.m4
-$sleep
 $ACLOCAL -I m4
-test $(ls -1t aclocal.m4 m4/otherfile.m4 | sed 1q) = aclocal.m4
+is_newest aclocal.m4 m4/otherfile.m4
 
 $AUTOCONF
 $AUTOMAKE
index c36538f..2ba8b78 100755 (executable)
@@ -81,31 +81,21 @@ $AUTOMAKE
 ./configure
 $MAKE testdist1
 
-cp aclocal.m4 stamp
+cp aclocal.m4 aclocal.old
 $sleep
-
-cat >>c.m4 <<\EOF
-AC_DEFUN([FOO], [ANOTHER_MACRO])
-EOF
-
+echo 'AC_DEFUN([FOO], [ANOTHER_MACRO])' >> c.m4
 $MAKE
-
 # Because c.m4 has changed, aclocal.m4 must have been rebuilt.
-test $(ls -1t aclocal.m4 stamp | sed 1q) = aclocal.m4
+is_newest aclocal.m4 aclocal.old
 # However, since FOO is not used, f.m4 should not be included
 # and the contents of aclocal.m4 should remain the same
-diff aclocal.m4 stamp
+diff aclocal.m4 aclocal.old
 
-# If FOO where to be used, that would be another story, of course.
-cat >>configure.ac <<EOF
-FOO
-EOF
-
-cp aclocal.m4 stamp
+# If FOO where to be used, that would be another story, of course:
+# f.m4 should be included
 $sleep
-
+echo FOO >> configure.ac
 $MAKE
-
 $FGREP defs/f.m4 aclocal.m4
 $MAKE testdist2
 
index ce84983..936d4ea 100755 (executable)
@@ -37,70 +37,64 @@ END
 mkdir m4
 echo 'AC_DEFUN([SOME_DEFS], [])' > m4/somedefs.m4
 
-$sleep
-
-$ACLOCAL -I m4
-
 # Automake will take aclocal.m4 to be newer if it has the same timestamp
 # as Makefile.in.  Avoid the confusing by sleeping.
-$sleep
-
-$AUTOMAKE --no-force
+AUTOMAKE_after_aclocal ()
+{
+  $sleep
+  $AUTOMAKE --no-force
+}
 
-$sleep
+$ACLOCAL -I m4
+AUTOMAKE_after_aclocal
 
 touch foo
+$sleep
 $ACLOCAL -I m4
-$AUTOMAKE --no-force
-
+AUTOMAKE_after_aclocal
 # aclocal.m4 and Makefile.in should not have been updated, so 'foo'
 # should be younger
-test $(ls -1t aclocal.m4 Makefile.in sub/Makefile.in foo | sed 1q) = foo
+is_newest foo aclocal.m4 Makefile.in sub/Makefile.in
 
 $sleep
 $ACLOCAL -I m4 --force
-test $(ls -1t aclocal.m4 foo | sed 1q) = aclocal.m4
+is_newest aclocal.m4 foo
 # We still use --no-force for automake, but since aclocal.m4 has
 # changed all Makefile.ins should be updated.
-$sleep
-$AUTOMAKE --no-force
-test $(ls -1t Makefile.in foo | sed 1q) = Makefile.in
-test $(ls -1t sub/Makefile.in foo | sed 1q) = sub/Makefile.in
+AUTOMAKE_after_aclocal
+is_newest Makefile.in aclocal.m4 foo
+is_newest sub/Makefile.in aclocal.m4 foo
 
-touch m4/somedefs.m4
 $sleep
-touch foo
+touch m4/somedefs.m4
 $sleep
 $ACLOCAL -I m4
-$sleep
-$AUTOMAKE --no-force
-
-# aclocal.m4 should have been updated, although its contents haven't changed.
-test $(ls -1t aclocal.m4 foo | sed 1q) = aclocal.m4
-test $(ls -1t Makefile.in foo | sed 1q) = Makefile.in
-test $(ls -1t sub/Makefile.in foo | sed 1q) = sub/Makefile.in
+AUTOMAKE_after_aclocal
+# aclocal.m4 should have been updated, although its contents haven't
+# changed.
+is_newest aclocal.m4 m4/somedefs.m4
+is_newest Makefile.in m4/somedefs.m4
+is_newest sub/Makefile.in m4/somedefs.m4
 
-touch fragment.inc
 $sleep
-touch foo
+touch fragment.inc
 $sleep
 $ACLOCAL -I m4
-$AUTOMAKE --no-force
+AUTOMAKE_after_aclocal
 # Only ./Makefile.in should change.
-test $(ls -1t aclocal.m4 foo | sed 1q) = foo
-test $(ls -1t Makefile.in foo | sed 1q) = Makefile.in
-test $(ls -1t sub/Makefile.in foo | sed 1q) = foo
+is_newest Makefile.in fragment.inc
+is_newest fragment.inc aclocal.m4
+is_newest fragment.inc sub/Makefile.in
 
 grep README Makefile.in && Exit 1
 
-: > README
 $sleep
-touch foo
+: > README
 $sleep
 $AUTOMAKE --no-force
 # Even if no dependency change, the content changed.
-test $(ls -1t Makefile.in foo | sed 1q) = Makefile.in
-test $(ls -1t sub/Makefile.in foo | sed 1q) = foo
+is_newest Makefile.in README
+is_newest README sub/Makefile.in
 
 grep README Makefile.in
 
@@ -111,6 +105,8 @@ $sleep
 $ACLOCAL -I m4
 $AUTOMAKE --no-force
 # Only sub/Makefile.in should change.
-test $(ls -1t aclocal.m4 foo | sed 1q) = foo
-test $(ls -1t Makefile.in foo | sed 1q) = foo
-test $(ls -1t sub/Makefile.in foo | sed 1q) = sub/Makefile.in
+is_newest foo aclocal.m4
+is_newest foo Makefile.in
+is_newest sub/Makefile.in foo
+
+:
index 9acbab1..9bdfd13 100755 (executable)
@@ -38,8 +38,7 @@ cat > Makefile.am <<'END'
 SUBDIRS = sub3
 .PHONY: test-prog-updated
 test-prog-updated:
-       stat older sub3/run$(EXEEXT) || : For debugging.
-       test `ls -t older sub3/run$(EXEEXT) | sed 1q` = sub3/run$(EXEEXT)
+       is_newest sub3/run$(EXEEXT) sub2/config.bot
 END
 
 cat > sub3/Makefile.am <<'END'
@@ -68,13 +67,12 @@ $AUTOMAKE
 ./configure --enable-dependency-tracking
 $MAKE
 # Sanity check.
-cross_compiling || { sub3/run | grep grepme1; }
+cross_compiling || sub3/run | grep grepme1 || Exit 1
 
-: > older
 $sleep
 echo '#define NAME "grepme2"' > sub2/config.bot
 $MAKE
-cross_compiling || { sub3/run | grep grepme2; }
+cross_compiling || sub3/run | grep grepme2 || Exit 1
 $MAKE test-prog-updated
 
 $MAKE distcheck
diff --git a/t/ax/is_newest b/t/ax/is_newest
new file mode 100755 (executable)
index 0000000..f52a1a8
--- /dev/null
@@ -0,0 +1,40 @@
+#! /bin/sh
+# Copyright (C) 2012 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+# Usage: is_newest FILE FILES
+# Fail if any file in FILES is newer than FILE, and print the list of
+# such files on the standard error.
+# Resolve ties in favor of FILE.
+
+set -u
+
+me=is_newest
+
+if test $# -lt 2; then
+  echo "$me: too few arguments" >&2
+  exit 2
+fi
+
+file=$1; shift
+newer_files=$(find "$@" -prune -newer "$file") || exit $?
+
+if test -n "$newer_files"; then
+  echo "$me: these files are newer than '$file':" >&2
+  for f in $newer_files; do echo "* $f" >&2; done
+  exit 1
+fi
+
+exit 0
index b4c8e4d..9d19621 100644 (file)
@@ -200,16 +200,6 @@ cross_compiling ()
   test x"$host_alias" != x && test x"$build_alias" != x"$host_alias"
 }
 
-# is_newest FILE FILES
-# --------------------
-# Return false if any file in FILES is newer than FILE.
-# Resolve ties in favor of FILE.
-is_newest ()
-{
-  is_newest_files=$(find "$@" -prune -newer "$1")
-  test -z "$is_newest_files"
-}
-
 # is_blocked_signal SIGNAL-NUMBER
 # --------------------------------
 # Return success if the given signal number is blocked in the shell,
index 77b806a..8398ea6 100755 (executable)
@@ -48,8 +48,7 @@ EXTRA_DIST = foodep bardep
 
 .PHONY: bar-has-been-updated
 bar-has-been-updated:
-       stat older bar$(EXEEXT) libfoo.a || : For debugging.
-       test `ls -t bar$(EXEEXT) older | sed q` = bar$(EXEEXT)
+       is_newest bar$(EXEEXT) libfoo.a
 END
 
 cat >libfoo.c <<'END'
@@ -96,7 +95,6 @@ $MAKE && Exit 1
 : >bardep
 
 $MAKE
-: > older
 $sleep
 touch libfoo.a
 $MAKE
index 91722bd..011a0d4 100755 (executable)
@@ -43,8 +43,7 @@ EXTRA_DIST = bardep
 
 .PHONY: bar-has-been-updated
 bar-has-been-updated:
-       stat older bar$(EXEEXT) libfoo.la || : For debugging.
-       test `ls -t bar$(EXEEXT) older | sed q` = bar$(EXEEXT)
+       is_newest bar$(EXEEXT) libfoo.la
 END
 
 cat >libfoo.c <<'END'
@@ -77,7 +76,6 @@ $MAKE && Exit 1
 : >bardep
 
 $MAKE
-: > older
 $sleep
 touch libfoo.la
 $MAKE
index 7bdfdf9..ec592f7 100755 (executable)
@@ -40,9 +40,8 @@ test-deps-exist:
 
 .PHONY: test-obj-updated
 test-obj-updated: joe.$(OBJEXT) moe.$(OBJEXT)
-       stat older my-hdr.hxx joe.$(OBJEXT) moe.$(OBJEXT) || :
-       test `ls -t older joe.$(OBJEXT) | sed 1q` = joe.$(OBJEXT)
-       test `ls -t older moe.$(OBJEXT) | sed 1q` = moe.$(OBJEXT)
+       is_newest joe.$(OBJEXT) my-hdr.hxx
+       is_newest moe.$(OBJEXT) my-hdr.hxx
 END
 
 cat > joe.ll << 'END'
@@ -86,7 +85,6 @@ $AUTOCONF
 $MAKE test-deps-exist
 $MAKE
 
-: > older
 $sleep
 touch my-hdr.hxx
 $MAKE test-obj-updated
index fce198d..be7da7f 100755 (executable)
@@ -38,8 +38,7 @@ test-deps-exist:
 
 .PHONY: test-obj-updated
 test-obj-updated: joe.$(OBJEXT)
-       stat older my-hdr.h joe.$(OBJEXT) || : For debugging.
-       test `ls -t older joe.$(OBJEXT) | sed 1q` = joe.$(OBJEXT)
+       is_newest joe.$(OBJEXT) my-hdr.h
 END
 
 cat > joe.l << 'END'
@@ -80,10 +79,15 @@ $AUTOCONF
 
 $MAKE test-deps-exist
 $MAKE
+cross_compiling || test "$(./zoo)" = 'Hello, World!' || Exit 1
 
-: > older
 $sleep
-touch my-hdr.h
+cat >> my-hdr.h << 'END'
+#undef MESSAGE
+#define MESSAGE "Howdy, Earth!"
+END
 $MAKE test-obj-updated
+$MAKE
+cross_compiling || test "$(./zoo)" = 'Howdy, Earth!' || Exit 1
 
 :
index c12113f..1fc64ad 100755 (executable)
@@ -82,8 +82,7 @@ $sleep
 touch lexer.l lexer2.l
 $sleep
 $MAKE lexer.c lexer2.c
-stat lexer.c lexer.l lexer2.c lexer2.l || : # For debugging.
-test $(ls -t lexer.c lexer.l | sed 1q) = lexer.c
-test $(ls -t lexer2.c lexer2.l | sed 1q) = lexer2.c
+is_newest lexer.c lexer.l
+is_newest lexer2.c lexer2.l
 
 :
index 86c40c3..1257e4a 100755 (executable)
@@ -47,7 +47,6 @@ $AUTOCONF
 $AUTOMAKE
 ./configure
 
-$sleep
 echo stamp > stampfile
 $sleep
 for target in dist distcheck; do
@@ -56,7 +55,8 @@ for target in dist distcheck; do
     $MAKE -n $target | grep stamp-sub-dist-hook || Exit 1
   fi
   $MAKE test-no-distdir
-  test $(ls -1t | sed 1q) = stampfile
+  # No file has been actually touched or created.
+  is_newest stampfile $(find .)
 done
 
 :
index 01636f4..d379c43 100755 (executable)
@@ -48,8 +48,6 @@ do_clean_setup ()
     test ! -d $d || chmod u+rwx $d || :
   done
   rm -rf t
-  mkdir -p t/ax
-  cp "$am_top_builddir"/t/ax/test-init.sh t/ax
 }
 
 do_clean_setup
@@ -67,7 +65,7 @@ do_clean_setup
 
 # Check that pre-test cleanup works also with directories with
 # "null" permissions, and containing broken symlinks.
-mkdir t/dummy.dir t/dummy.dir/sub
+mkdir t t/dummy.dir t/dummy.dir/sub
 (
   cd t/dummy.dir
   touch file sub/file
@@ -124,7 +122,7 @@ if test $have_symlinks = yes; then
   : > file
   chmod 000 file
 
-  mkdir t/dummy.dir
+  mkdir t t/dummy.dir
   (cd t/dummy.dir && ln -s ../../dir ../../file .)
 
   command_ok_ "pre-cleanup with testdir with zero-perms symlinks" \
index 3a4bcda..3feeb62 100755 (executable)
@@ -25,15 +25,7 @@ plan_ 32
 
 unset AM_TESTS_REEXEC BASH_VERSION || :
 
-get_test_init_sh ()
-{
-  mkdir -p ${1-.}/t/ax
-  cp "$am_top_builddir"/t/ax/test-init.sh ${1-.}/t/ax \
-    || fatal_ "fetching 't/ax/test-init.sh' from top_builddir"
-}
-
 cwd=$(pwd) || fatal_ "getting current working directory"
-get_test_init_sh
 cp "$am_top_builddir"/defs . || fatal_ "fetching 'defs' from top_builddir"
 
 #
@@ -173,7 +165,6 @@ sed -e "s|^am_top_builddir=.*|am_top_builddir='$cwd'|" \
     <  "$am_top_builddir"/defs-static > defs-static
 sed -e "s|^am_top_builddir=.*|am_top_builddir='$cwd/sub'|" \
     <  "$am_top_builddir"/defs-static > sub/defs-static
-get_test_init_sh sub
 
 check_preserve_args ()
 {
index df48a0b..5d9aa38 100755 (executable)
@@ -32,14 +32,11 @@ bin_PROGRAMS = foo
 AM_YFLAGS = -d
 foo_SOURCES = foo.y main.c
 BUILT_SOURCES = foo.h
-.PHONY: debug-info test-time-unchanged test-time-changed
-debug-info:
-       ls -l
-       stat *.[ch] *.$(OBJEXT) my-timestamp || :
-test-time-unchanged: debug-info
-       test `ls -1t main.$(OBJEXT) my-timestamp | sed 1q` = my-timestamp
-test-time-changed: debug-info
-       test `ls -1t main.$(OBJEXT) my-timestamp | sed 1q` = main.$(OBJEXT)
+.PHONY: test-time-unchanged test-time-changed
+test-time-unchanged:
+       is_newest foo.y foo.h main.$(OBJEXT)
+test-time-changed:
+       is_newest main.$(OBJEXT) foo.y foo.h
 END
 
 cat > foo.y << 'END'
@@ -72,8 +69,6 @@ $MAKE
 ls -l # For debugging.
 
 $sleep
-: > my-timestamp
-$sleep
 touch foo.y
 $MAKE
 $MAKE test-time-unchanged
index 791066a..f1c8cac 100755 (executable)
@@ -77,8 +77,7 @@ $sleep
 touch parse.y parse2.y
 $sleep
 $MAKE parse.c parse2.c
-stat parse.c parse.y parse2.c parse2.y || : # For debugging.
-test $(ls -t parse.c parse.y | sed 1q) = parse.c
-test $(ls -t parse2.c parse2.y | sed 1q) = parse2.c
+is_newest parse.c parse.y
+is_newest parse2.c parse2.y
 
 :
index 5dead21..6640d32 100755 (executable)
@@ -75,16 +75,14 @@ test -f foo/parse.h
 
 # Make sure foo/parse.h is not updated, unless when needed.
 $sleep
-: > z
-$sleep
 touch ../foo/parse.y
 $MAKE obj
-test $(ls -1t foo/parse.h z | sed 1q) = z
+is_newest ../foo/parse.y foo/parse.h
 $sleep
 sed 's/%%/%token TOKEN\n%%/g' ../foo/parse.y >../foo/parse.yt
 mv -f ../foo/parse.yt ../foo/parse.y
 $MAKE obj
-test $(ls -1t foo/parse.h z | sed 1q) = foo/parse.h
+is_newest foo/parse.h ../foo/parse.y
 
 # Now, adds another parser to test ylwrap.