To verify that a file 'new' is newer than the file 'old', it's much cleaner to use "is_newest new old" rather than the more clumsy "ls -t". Adjust several of our tests accordingly.
* syntax-checks.mk (sc_tests_ls_t): New check, guard against uses of "ls -t" and similar. (syntax_check_rules): Add it. * t/maken.sh: Adjust. * t/autohdr4.sh: Likewise. * t/extradep2.sh: Likewise. * t/lex-depend-cxx.sh: Likewise. * t/extradep.sh: Likewise. * t/yacc-depend2.sh: Likewise. * t/yacc-pr204.sh: Likewise. * t/lex-pr204.sh: Likewise. * t/yacc8.sh: Likewise. * t/acloca13.sh: Likewise. * t/lex-depend.sh: Likewise, and enhance. * t/acloca14.sh: Likewise. * t/aclocal7.sh: Likewise. Signed-off-by: Stefano Lattarini <stefano.lattar...@gmail.com> --- syntax-checks.mk | 11 ++++++++ t/acloca13.sh | 3 +-- t/acloca14.sh | 24 +++++------------ t/aclocal7.sh | 72 ++++++++++++++++++++++++--------------------------- t/autohdr4.sh | 8 +++--- t/extradep.sh | 4 +-- t/extradep2.sh | 4 +-- t/lex-depend-cxx.sh | 6 ++--- t/lex-depend.sh | 12 ++++++--- t/lex-pr204.sh | 5 ++-- t/maken.sh | 4 +-- t/yacc-depend2.sh | 15 ++++------- t/yacc-pr204.sh | 5 ++-- t/yacc8.sh | 6 ++--- 14 files changed, 81 insertions(+), 98 deletions(-) diff --git a/syntax-checks.mk b/syntax-checks.mk index f610a25..0549bc8 100644 --- a/syntax-checks.mk +++ b/syntax-checks.mk @@ -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 \ @@ -416,6 +417,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. diff --git a/t/acloca13.sh b/t/acloca13.sh index aab2daf..6d6f6c0 100755 --- a/t/acloca13.sh +++ b/t/acloca13.sh @@ -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 diff --git a/t/acloca14.sh b/t/acloca14.sh index c36538f..2ba8b78 100755 --- a/t/acloca14.sh +++ b/t/acloca14.sh @@ -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 diff --git a/t/aclocal7.sh b/t/aclocal7.sh index ce84983..936d4ea 100755 --- a/t/aclocal7.sh +++ b/t/aclocal7.sh @@ -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 + +: diff --git a/t/autohdr4.sh b/t/autohdr4.sh index 9acbab1..9bdfd13 100755 --- a/t/autohdr4.sh +++ b/t/autohdr4.sh @@ -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/extradep.sh b/t/extradep.sh index 77b806a..8398ea6 100755 --- a/t/extradep.sh +++ b/t/extradep.sh @@ -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 diff --git a/t/extradep2.sh b/t/extradep2.sh index 91722bd..011a0d4 100755 --- a/t/extradep2.sh +++ b/t/extradep2.sh @@ -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 diff --git a/t/lex-depend-cxx.sh b/t/lex-depend-cxx.sh index 7bdfdf9..ec592f7 100755 --- a/t/lex-depend-cxx.sh +++ b/t/lex-depend-cxx.sh @@ -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 diff --git a/t/lex-depend.sh b/t/lex-depend.sh index fce198d..be7da7f 100755 --- a/t/lex-depend.sh +++ b/t/lex-depend.sh @@ -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 : diff --git a/t/lex-pr204.sh b/t/lex-pr204.sh index c12113f..1fc64ad 100755 --- a/t/lex-pr204.sh +++ b/t/lex-pr204.sh @@ -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 : diff --git a/t/maken.sh b/t/maken.sh index 86c40c3..1257e4a 100755 --- a/t/maken.sh +++ b/t/maken.sh @@ -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 : diff --git a/t/yacc-depend2.sh b/t/yacc-depend2.sh index df48a0b..5d9aa38 100755 --- a/t/yacc-depend2.sh +++ b/t/yacc-depend2.sh @@ -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 diff --git a/t/yacc-pr204.sh b/t/yacc-pr204.sh index 791066a..f1c8cac 100755 --- a/t/yacc-pr204.sh +++ b/t/yacc-pr204.sh @@ -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 : diff --git a/t/yacc8.sh b/t/yacc8.sh index 5dead21..6640d32 100755 --- a/t/yacc8.sh +++ b/t/yacc8.sh @@ -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. -- 1.7.9.5