autoconf-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] tests: New helper macro AT_CHECK_MAKE.


From: Zack Weinberg
Subject: [PATCH] tests: New helper macro AT_CHECK_MAKE.
Date: Thu, 20 Aug 2020 13:21:17 -0400

This macro factors out some repeated code surrounding tests that run
make, such as honoring $MAKE, *not* honoring $MAKEFLAGS, and
normalizing the exit status.  Partially addresses bug #110267
(problems with Sun’s make barfing on GNU make options from
$MAKEFLAGS).

Also addresses some unrelated problems I noticed while changing all
the tests that run make to use this macro:

The shtool test is now properly skipped if shtool is not available on
the host system.

Some of the Fortran tests would create an executable and then run it,
others would create an executable and then the AT_CHECK operation that
would run it was commented out.  There’s no evidence in the changelog
or the git history for why this was done.  I uncommented all of the
commented-out cases; this can be undone easily if it causes
problems.  (It can’t be an issue with cross-compilation because some
of the tests do run the executable.)

It seems like it ought to be possible to put the three lines

  : "${MAKE=make}"
  export MAKE
  unset MAKEFLAGS

somewhere near the top of the testsuite script and not have to repeat
them for every invocation of AT_CHECK_MAKE, but I couldn’t figure out
the right way to do that in an autotest suite.  Suggestions would be
welcome.

OK for trunk?

zw


* tests/local.at (AT_CHECK_MAKE): New macro wrapping an AT_CHECK
  invocation of make.  All tests that run make updated to use this macro.
* tests/fortran.at: Uncomment all AT_CHECKs that run the just-compiled
  program.
* tests/foreign.at (shtool): Skip the test if shtool is not available
  from the host system.  Simplify shell logic.
---
 tests/autotest.at | 21 ++++-------
 tests/c.at        | 24 ++++++------
 tests/foreign.at  | 16 ++++----
 tests/fortran.at  | 93 ++++++++++++++++++++---------------------------
 tests/local.at    | 26 +++++++++++++
 tests/torture.at  | 15 ++++----
 6 files changed, 99 insertions(+), 96 deletions(-)

diff --git a/tests/autotest.at b/tests/autotest.at
index 5519e9c7..2892b1dd 100644
--- a/tests/autotest.at
+++ b/tests/autotest.at
@@ -1599,20 +1599,13 @@ for signal in 2 15; do
   # AT_CHECK([[grep '[iI]nterrupt[      ]' stderr]], [1])
 
   # Ditto with `make' in the loop.
-  : "${MAKE=make}"
-  unset MAKEFLAGS
-  # Need to eliminate outer TESTSUITEFLAGS here.
-  # Need to normalize exit status here: some make implementations
-  # exit 1 (BSD make), some exit 2 (GNU make).
-  AT_CHECK([$MAKE check TESTSUITEFLAGS=; ]dnl
-          [case $? in 1|2) exit 1;; *) exit $?;; esac],
-          [1], [ignore], [stderr])
+  # Explicitly setting TESTSUITEFLAGS to empty...
+  AT_CHECK_MAKE([TESTSUITEFLAGS=], [], [1], [ignore], [stderr])
   AT_CHECK([grep 'bailing out' stderr], [], [ignore])
   AT_CHECK([grep 'bailing out' micro-suite.log], [], [ignore])
-  # Ditto, parallel case.
-  AT_CHECK([$MAKE check TESTSUITEFLAGS=--jobs=3; ]dnl
-          [case $? in 1|2) exit 1;; *) exit $?;; esac],
-          [1], [ignore], [stderr])
+
+  # ... and explicitly requesting 3-fold parallelism.
+  AT_CHECK_MAKE([TESTSUITEFLAGS=--jobs=3], [], [1], [ignore], [stderr])
   AT_CHECK([grep 'bailing out' stderr], [], [ignore])
   AT_CHECK([grep 'bailing out' micro-suite.log], [], [ignore])
 done
@@ -1926,7 +1919,7 @@ rm t/atconfig
 AT_CHECK_AUTOCONF
 AT_CHECK_CONFIGURE
 AT_CHECK([grep '^EXEEXT='\''.*'\' t/atconfig], [], [ignore])
-AT_CHECK([${MAKE-make}], [], [ignore])
+AT_CHECK_MAKE
 AT_CHECK([cd t && $CONFIG_SHELL ./suite], [], [ignore])
 AT_CHECK([grep 1.*successful t/suite.log], [], [ignore])
 AT_CLEANUP
@@ -1978,7 +1971,7 @@ rm t/atconfig
 AT_CHECK_AUTOCONF
 AT_CHECK_CONFIGURE
 AT_CHECK([grep '^EXEEXT='\''.*'\' t/atconfig], [], [ignore])
-AT_CHECK([${MAKE-make}], [], [ignore])
+AT_CHECK_MAKE
 AT_CHECK([cd t && $CONFIG_SHELL ./suite], [], [ignore])
 AT_CHECK([grep 1.*successful t/suite.log], [], [ignore])
 AT_CLEANUP
diff --git a/tests/c.at b/tests/c.at
index b1dabd14..d13b321e 100644
--- a/tests/c.at
+++ b/tests/c.at
@@ -326,11 +326,11 @@ class foo { int x; };
 class foo foobar;
 ]])
 
-AT_CHECK([autoconf])
-AT_CHECK([autoheader])
-AT_CHECK([./configure $configure_options], [], [ignore], [ignore])
-AT_CHECK([${MAKE-make} cpp-works || exit 77], [], [ignore], [ignore])
-AT_CHECK([${MAKE-make}], [], [ignore], [ignore])
+AT_CHECK_AUTOCONF
+AT_CHECK_AUTOHEADER([], [restrict])
+AT_CHECK_CONFIGURE
+AT_CHECK_MAKE([cpp-works || exit 77])
+AT_CHECK_MAKE
 
 AT_CLEANUP
 
@@ -381,10 +381,9 @@ int main (void)
 }
 ]])
 
-: "${MAKE=make}"
-AT_CHECK([env ACLOCAL=true autoreconf -vi], [], [ignore], [ignore])
-AT_CHECK([./configure $configure_options], [], [ignore], [ignore])
-AT_CHECK([$MAKE], [], [ignore], [ignore])
+AT_CHECK_AUTOCONF
+AT_CHECK_CONFIGURE
+AT_CHECK_MAKE
 
 AT_CLEANUP
 
@@ -424,9 +423,8 @@ AT_DATA([foo.cpp],
 }
 ]])
 
-: "${MAKE=make}"
-AT_CHECK([env ACLOCAL=true autoreconf -vi], [], [ignore], [ignore])
-AT_CHECK([./configure $configure_options], [], [ignore], [ignore])
-AT_CHECK([$MAKE], [], [ignore], [ignore])
+AT_CHECK_AUTOCONF
+AT_CHECK_CONFIGURE
+AT_CHECK_MAKE
 
 AT_CLEANUP
diff --git a/tests/foreign.at b/tests/foreign.at
index d8280743..7a49333a 100644
--- a/tests/foreign.at
+++ b/tests/foreign.at
@@ -122,20 +122,22 @@ copy-shtool:
 : >file1
 : >file2
 chmod +x file1
-: "${MAKE=make}"
 mkdir build-aux inst
 instdir=`pwd`/inst
 AT_CHECK_AUTOCONF
 cp "$abs_top_srcdir/build-aux/install-sh" build-aux
 AT_CHECK_CONFIGURE
-AT_CHECK([$MAKE copy-shtool], [], [ignore], [ignore],
-        [AT_CHECK([: >build-aux/shtool])])
+AT_SKIP_IF([grep 'SHTOOL = false' Makefile > /dev/null 2>&1])
+
+AT_CHECK_MAKE([copy-shtool])
+AT_CHECK([test -s build-aux/shtool])
+
+# AC_PROG_INSTALL should pick up shtool from build-aux, even though
+# we're forcing AC_PATH_PROG not to find it on the host system.
 rm -f build-aux/install-sh
 AT_CHECK_CONFIGURE([--prefix="$instdir" ac_cv_path_SHTOOL=false])
 AT_CHECK([grep '^ac_install_sh = .*shtool install -c' Makefile], [], [ignore])
-if test -s build-aux/shtool; then
-  AT_CHECK([$MAKE install], [], [ignore], [ignore])
-  AT_CHECK([test -f inst/file1 && test -f inst/file2 && test -x inst/file1])
-fi
+AT_CHECK_MAKE([install])
+AT_CHECK([test -f inst/file1 && test -f inst/file2 && test -x inst/file1])
 
 AT_CLEANUP
diff --git a/tests/fortran.at b/tests/fortran.at
index 241d9b0d..cf4d9fef 100644
--- a/tests/fortran.at
+++ b/tests/fortran.at
@@ -109,10 +109,9 @@ AT_DATA([foo.f],
       end
 ]])
 
-: "${MAKE=make}"
 AT_CHECK([env ACLOCAL=true autoreconf -vi], [], [ignore], [ignore])
 AT_CHECK_CONFIGURE
-AT_CHECK([$MAKE], [], [ignore], [ignore])
+AT_CHECK_MAKE
 
 AT_CLEANUP
 
@@ -149,10 +148,9 @@ AT_DATA([foo.f],
       end
 ]])
 
-: "${MAKE=make}"
 AT_CHECK([env ACLOCAL=true autoreconf -vi], [], [ignore], [ignore])
 AT_CHECK_CONFIGURE
-AT_CHECK([$MAKE], [], [ignore], [ignore])
+AT_CHECK_MAKE
 
 AT_CLEANUP
 
@@ -244,9 +242,8 @@ AT_CHECK_AUTOHEADER([], [
   FC_DUMMY_MAIN_EQ_F77
 ])
 AT_CHECK_CONFIGURE
-: "${MAKE=make}"
-AT_CHECK([$MAKE], [], [ignore], [ignore])
-dnl AT_CHECK([./cprogram])
+AT_CHECK_MAKE
+AT_CHECK([./cprogram])
 
 AT_CLEANUP
 
@@ -327,9 +324,8 @@ AT_CHECK_AUTOHEADER([], [
   FC_FUNC_
 ])
 AT_CHECK_CONFIGURE
-: "${MAKE=make}"
-AT_CHECK([$MAKE], [], [ignore], [ignore])
-dnl AT_CHECK([./cprogram])
+AT_CHECK_MAKE
+AT_CHECK([./cprogram])
 
 AT_CLEANUP
 
@@ -409,12 +405,11 @@ AT_CHECK_AUTOHEADER([], [
   FC_DUMMY_MAIN_EQ_F77
 ])
 AT_CHECK_CONFIGURE
-: "${MAKE=make}"
-AT_CHECK([$MAKE], [], [ignore], [ignore])
-dnl AT_CHECK([./cprogram], [], [output from C main
-dnl  some output from Fortran sources
-dnl more output from C main
-dnl ])
+AT_CHECK_MAKE
+AT_CHECK([./cprogram], [], [output from C main
+ some output from Fortran sources
+more output from C main
+])
 
 AT_CLEANUP
 
@@ -494,12 +489,11 @@ AT_CHECK_AUTOHEADER([], [
   FC_MAIN
 ])
 AT_CHECK_CONFIGURE
-: "${MAKE=make}"
-AT_CHECK([$MAKE], [], [ignore], [ignore])
-dnl AT_CHECK([./cprogram], [], [output from C main
-dnl  some output from Fortran sources
-dnl more output from C main
-dnl ])
+AT_CHECK_MAKE
+AT_CHECK([./cprogram], [], [output from C main
+ some output from Fortran sources
+more output from C main
+])
 
 AT_CLEANUP
 
@@ -574,9 +568,8 @@ AT_CHECK_AUTOHEADER([], [
   FC_DUMMY_MAIN_EQ_F77
 ])
 AT_CHECK_CONFIGURE
-: "${MAKE=make}"
-AT_CHECK([$MAKE], [], [ignore], [ignore])
-dnl AT_CHECK([./cprogram])
+AT_CHECK_MAKE
+AT_CHECK([./cprogram])
 
 AT_CLEANUP
 
@@ -651,9 +644,9 @@ AT_CHECK_AUTOHEADER([], [
   FC_DUMMY_MAIN_EQ_F77
 ])
 AT_CHECK_CONFIGURE
-: "${MAKE=make}"
-AT_CHECK([$MAKE], [], [ignore], [ignore])
-dnl AT_CHECK([./cprogram])
+AT_CHECK_MAKE
+AT_CHECK([./cprogram])
+
 AT_CLEANUP
 
 
@@ -736,8 +729,7 @@ end
 
 AT_CHECK_AUTOCONF
 AT_CHECK_CONFIGURE
-: "${MAKE=make}"
-AT_CHECK([$MAKE], [], [ignore], [ignore])
+AT_CHECK_MAKE
 
 AT_CLEANUP
 
@@ -836,8 +828,8 @@ this is not correct fortran
 
 AT_CHECK_AUTOCONF
 AT_CHECK_CONFIGURE
-: "${MAKE=make}"
-AT_CHECK([$MAKE], [], [ignore], [ignore])
+AT_CHECK_MAKE
+AT_CHECK([./prog])
 
 AT_CLEANUP
 
@@ -872,9 +864,8 @@ end
 
 AT_CHECK_AUTOCONF
 AT_CHECK_CONFIGURE
-: "${MAKE=make}"
-AT_CHECK([$MAKE], [], [ignore], [ignore])
-dnl AT_CHECK([./prog])
+AT_CHECK_MAKE
+AT_CHECK([./prog])
 
 AT_CLEANUP
 
@@ -910,9 +901,8 @@ end
 
 AT_CHECK_AUTOCONF
 AT_CHECK_CONFIGURE
-: "${MAKE=make}"
-AT_CHECK([$MAKE], [], [ignore], [ignore])
-dnl AT_CHECK([./prog])
+AT_CHECK_MAKE
+AT_CHECK([./prog])
 
 AT_CLEANUP
 
@@ -948,9 +938,8 @@ C      fixed-form style comment
 
 AT_CHECK_AUTOCONF
 AT_CHECK_CONFIGURE
-: "${MAKE=make}"
-AT_CHECK([$MAKE], [], [ignore], [ignore])
-dnl AT_CHECK([./prog])
+AT_CHECK_MAKE
+AT_CHECK([./prog])
 
 AT_CLEANUP
 
@@ -987,9 +976,8 @@ C      fixed-form style comment
 
 AT_CHECK_AUTOCONF
 AT_CHECK_CONFIGURE
-: "${MAKE=make}"
-AT_CHECK([$MAKE], [], [ignore], [ignore])
-dnl AT_CHECK([./prog])
+AT_CHECK_MAKE
+AT_CHECK([./prog])
 
 AT_CLEANUP
 
@@ -1056,10 +1044,9 @@ EOF
 
     AT_CHECK_AUTOCONF
     AT_CHECK_CONFIGURE
-    : "${MAKE=make}"
-    AT_CHECK([$MAKE], [], [ignore], [ignore])
-    dnl AT_CHECK([./prog])
-    AT_CHECK([$MAKE clean], [], [ignore], [ignore])
+    AT_CHECK_MAKE
+    AT_CHECK([./prog])
+    AT_CHECK_MAKE([clean])
 
   done
 done
@@ -1118,10 +1105,9 @@ AT_DATA([prog.f],
 
 AT_CHECK_AUTOCONF
 AT_CHECK_CONFIGURE
-: "${MAKE=make}"
-AT_CHECK([$MAKE], [], [ignore], [ignore])
+AT_CHECK_MAKE
 AT_CHECK([./prog || exit 1], [1], [ignore], [ignore])
-AT_CHECK([$MAKE clean], [], [ignore], [ignore])
+AT_CHECK_MAKE([clean])
 
 AT_CLEANUP
 
@@ -1186,12 +1172,11 @@ AT_DATA([prog.f],
 
 AT_CHECK_AUTOCONF
 AT_CHECK_CONFIGURE
-: "${MAKE=make}"
-AT_CHECK([$MAKE], [], [stdout], [stderr])
+AT_CHECK_MAKE([], [], [], [stdout], [stderr])
 # Both the FCFLAGS setting from configure.ac, and the Makefile rule
 # should add to the module search path.
 AT_CHECK([grep 'sub .*sub ' stdout stderr], [], [ignore])
 AT_CHECK([./prog], [], [ignore], [ignore])
-AT_CHECK([$MAKE clean], [], [ignore], [ignore])
+AT_CHECK_MAKE([clean])
 
 AT_CLEANUP
diff --git a/tests/local.at b/tests/local.at
index d667d630..3b6ebf86 100644
--- a/tests/local.at
+++ b/tests/local.at
@@ -479,6 +479,32 @@ m4_define([AT_CHECK_AUTOUPDATE],
 ])
 
 
+# AT_CHECK_MAKE(MAKEARGS, DIRECTORY, EXIT-STATUS,
+#               [STDOUT = IGNORE], [STDERR = IGNORE])
+# ---------------------------------------------------------------
+# Run make in DIRECTORY (default `.'), passing MAKEARGS on the command
+# line.  EXIT-STATUS, STDOUT, and STDERR are as for AT_CHECK.
+# The environment variable MAKE is honored if present.
+# The environment variable MAKEFLAGS is *cleared*.
+# If EXIT-STATUS is 1, an exit status of either 1 or 2 is considered
+# an acceptable result, because there are situations where BSD make will
+# exit with status 1 but GNU make will instead exit with status 2.
+m4_define([AT_CHECK_MAKE],
+[: "${MAKE=make}"
+export MAKE
+unset MAKEFLAGS
+AT_CHECK(
+  m4_if(m4_default([$2], [.]), [.], [], [cd "$2" &&])dnl
+  [$][MAKE]m4_ifnblank([$1],[ $1])
+  m4_if([$3], [1],
+  [[dnl pacify editors that don't understand sh case: ((
+  case $? in 1|2) exit 1;; *) exit $?;; esac]]),
+  [$3],
+  m4_default([$4], [ignore]),
+  m4_default([$5], [ignore]))
+])
+
+
 # _AT_CHECK_AC_MACRO(AC-BODY, PRE-TESTS)
 # --------------------------------------
 # Create a minimalist configure.ac running the macro named
diff --git a/tests/torture.at b/tests/torture.at
index 37deef25..616e051c 100644
--- a/tests/torture.at
+++ b/tests/torture.at
@@ -1248,14 +1248,12 @@ all: f f1 f2
 
 AT_CHECK_AUTOCONF
 
-: "${MAKE=make}"
-
 # In place.
 AT_CHECK([./configure $configure_options], [], [ignore])
 # Treat BSD make separately, afterwards, for maximal coverage.
 dirs='at paren brace'
 for dir in $dirs; do
-  AT_CHECK([cd $dir && $MAKE], [], [ignore], [ignore])
+  AT_CHECK_MAKE([], [$dir])
 done
 
 rm -f config.status
@@ -1264,20 +1262,21 @@ mkdir build absbuild
 # Relative name.
 AT_CHECK([cd build && ../configure $configure_options], [], [ignore])
 for dir in $dirs; do
-  AT_CHECK([cd build/$dir && $MAKE], [], [ignore], [ignore])
+  AT_CHECK_MAKE([], [build/$dir])
 done
 
 # Absolute name.
 at_here=`pwd`
 AT_CHECK([cd absbuild && "$at_here/configure" $configure_options], [], 
[ignore])
 for dir in $dirs; do
-  AT_CHECK([cd absbuild/$dir && $MAKE], [], [ignore], [ignore])
+  AT_CHECK_MAKE([], [absbuild/$dir])
 done
 
 # These will not pass with BSD make.
-AT_CHECK([cd space && { $MAKE || exit 77; }], [], [ignore], [ignore])
-AT_CHECK([cd build/space && $MAKE], [], [ignore], [ignore])
-AT_CHECK([cd absbuild/space && $MAKE], [], [ignore], [ignore])
+AT_CHECK_MAKE([|| exit 77], [space])
+AT_CHECK_MAKE([], [build/space])
+AT_CHECK_MAKE([], [absbuild/space])
+
 
 AT_CLEANUP
 
-- 
2.28.0




reply via email to

[Prev in Thread] Current Thread [Next in Thread]