]> git.draconx.ca Git - dxcommon.git/commitdiff
DX_PROG_AUTOTEST: Modernize.
authorNick Bowler <nbowler@draconx.ca>
Sat, 23 Dec 2023 21:41:03 +0000 (16:41 -0500)
committerNick Bowler <nbowler@draconx.ca>
Sat, 23 Dec 2023 21:51:33 +0000 (16:51 -0500)
This macro can use some rework to behave a bit more like other program
probing macros in this package.

In particular, if Autotest is not found, configure now prints

  checking for autotest... no

rather than "... false", and configure no longer prints the next line
"checking if autotest works..." in this case.

Additionally, extra code to support snippet/autotest.mk is moved to
a new macro, DX_PROG_AUTOTEST_AM which also defines the necessary
conditional.

Finally, this macro now has coverage in the test suite.

configure.ac
m4/autotest.m4
snippet/autotest.mk
t/autotest.sh
tests/programs.at
tests/snippets.at

index efac42f1defaa0d06ba7c922ec0bbb68ad0eb8b8..1910c73b18f611f86a86d42c3131c1050d2dcbd1 100644 (file)
@@ -30,8 +30,7 @@ AC_CHECK_FUNCS_ONCE([wcwidth])
 AM_CONDITIONAL([HAVE_WCWIDTH], [test x"$ac_cv_func_wcwidth" = x"yes"])
 
 AC_CONFIG_TESTDIR([.])
-DX_PROG_AUTOTEST
-AM_CONDITIONAL([HAVE_AUTOTEST], [test x"$dx_cv_autotest_works" = x"yes"])
+DX_PROG_AUTOTEST_AM
 
 AC_CACHE_CHECK([for struct option in <getopt.h>], [dx_cv_have_struct_option],
   [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <getopt.h>],
index 063144a19039688feb1dbf6d4486ae51047a3cab..854295f1e940f8203e8d2c9b4f784b233a1a0412 100644 (file)
@@ -1,47 +1,57 @@
-dnl Copyright © 2015 Nick Bowler
-dnl
-dnl Macro to find an working autotest installation.
-dnl
-dnl License WTFPL2: Do What The Fuck You Want To Public License, version 2.
-dnl This is free software: you are free to do what the fuck you want to.
-dnl There is NO WARRANTY, to the extent permitted by law.
+# Copyright © 2015, 2021, 2023 Nick Bowler
+#
+# Macro to find an working autotest installation.
+#
+# License WTFPL2: Do What The Fuck You Want To Public License, version 2.
+# This is free software: you are free to do what the fuck you want to.
+# There is NO WARRANTY, to the extent permitted by law.
 
-m4_define([_DX_PROG_AUTOTEST_SRC], [cat >conftest.at <<'EOF'
-m4@&t@_define(@<:@AT_PACKAGE_STRING@:>@,    @<:@AC_PACKAGE_STRING@:>@)
-m4@&t@_define(@<:@AT_PACKAGE_BUGREPORT@:>@, @<:@AC_PACKAGE_BUGREPORT@:>@)
-AT_INIT
-EOF])
-
-m4_define([_DX_PROG_AUTOTEST_CHECK_OUT],
-  [AS_IF([$FGREP "$PACKAGE_STRING" conftest.out >/dev/null 2>&1],
-    [DX_DO([dx_cv_autotest_works=yes],
-      [AS_VAR_SET([dx_cv_autotest_cmd], ["$1"])])])])
+# DX_PROG_AUTOTEST
+#
+# Determine a command which works to compile Autotest testsuites.
+#
+# If found, the AUTOTEST variable (which is substituted by AC_SUBST)
+# is set with the result, and the cache variable dx_cv_autotest_works
+# is set to "yes".  Otherwise, dx_cv_autotest_works is set to "no".
+AC_DEFUN_ONCE([DX_PROG_AUTOTEST],
+[AC_ARG_VAR([AUTOTEST], [command to compile Autotest testsuites])dnl
+_DX_PROG_AUTOTEST
+AS_IF([$dx_cv_autotest_found],
+  [AC_CACHE_CHECK([whether $AUTOTEST works],
+    [dx_cv_autotest_works], [_DX_PROG_AUTOTEST_CHECK])])])
 
-m4_define([_DX_PROG_AUTOTEST_CHECK_CMD],
-  [AS_IF([test x"$dx_cv_autotest_cmd" = x"false"],
-    [AS_IF([AC_RUN_LOG([$1 conftest.at >conftest.sh])],
-      [AS_IF([AC_RUN_LOG([$SHELL conftest.sh --version >conftest.out])],
-        [_DX_PROG_AUTOTEST_CHECK_OUT($@)])])])])
+# DX_PROG_AUTOTEST_AM
+#
+# Like DX_PROG_AUTOTEST, but also define various additional things
+# needed to use the autotest.mk snippet.
+AC_DEFUN_ONCE([DX_PROG_AUTOTEST_AM],
+[AC_REQUIRE([DX_PROG_AUTOTEST])AC_REQUIRE([DX_AUTOMAKE_COMPAT])dnl
+AM_CONDITIONAL([HAVE_AUTOTEST], [test x"$dx_cv_autotest_works" = xyes])])
 
-m4_define([_DX_PROG_AUTOTEST_SET_VAR],
-  [DX_DO([AC_CACHE_CHECK([for autotest], [dx_cv_autotest_cmd],
-            [AS_VAR_SET_IF([AUTOTEST],
-              [dx_cv_autotest_cmd=$AUTOTEST],
-              [DX_DO([dx_cv_autotest_works=no dx_cv_autotest_cmd=false],
-                [AS_VAR_SET_IF([AUTOTEST],
-                  [_DX_PROG_AUTOTEST_CHECK_CMD([$AUTOTEST])])],
-                [AS_VAR_SET_IF([AUTOM4TE],
-                  [_DX_PROG_AUTOTEST_CHECK_CMD([$AUTOM4TE -l autotest])])],
-                [_DX_PROG_AUTOTEST_CHECK_CMD([autom4te -l autotest])])])])],
-    [AUTOTEST=$dx_cv_autotest_cmd])])
+m4_define([_DX_PROG_AUTOTEST],
+[AC_CACHE_CHECK([for autotest], [dx_cv_autotest_cmd],
+[dx_cv_autotest_found=false
+AS_VAR_SET_IF([AUTOTEST],
+  [dx_cv_autotest_cmd=$AUTOTEST dx_cv_autotest_found=:],
+[for dx_cv_autotest_cmd
+in ${AUTOM4TE:+"$AUTOM4TE -l autotest"} "autom4te -l autotest"
+do
+  _DX_PROG_AUTOTEST_CHECK([dx_cv_autotest_found=:; break])
+done])
+$dx_cv_autotest_found || dx_cv_autotest_cmd=no])
+$dx_cv_autotest_found && AUTOTEST=$dx_cv_autotest_cmd])
 
-AC_DEFUN([DX_PROG_AUTOTEST],
-  [m4_do([AC_REQUIRE([AC_PROG_FGREP])AC_REQUIRE([DX_AUTOMAKE_COMPAT])],
-    [AC_ARG_VAR([AUTOTEST], [command to compile autotest programs])],
-    [DX_DO([_DX_PROG_AUTOTEST_SRC],
-      [_DX_PROG_AUTOTEST_SET_VAR],
-      [AC_CACHE_CHECK([whether autotest works],
-        [dx_cv_autotest_works],
-        [DX_DO([dx_cv_autotest_works=no],
-          [_DX_PROG_AUTOTEST_CHECK_CMD([$AUTOTEST])])])])],
-    [AC_SUBST([AUTOTEST])])])
+m4_define([_DX_PROG_AUTOTEST_CHECK],
+[cat >conftest.at <<'EOF'
+[m4@&t@_define([AT_PACKAGE_STRING], [mypackage])]
+[m4@&t@_define([AT_PACKAGE_BUGREPORT], [nobody])]
+AT_INIT
+EOF
+dx_cv_autotest_works=no
+AS_IF(
+  [DX_RUN_LOG([$dx_cv_autotest_cmd conftest.at >conftest.sh &&
+    $SHELL conftest.sh --version >conftest.out &&
+      grep '[(]mypackage[)]' conftest.out >/dev/null 2>&1])],
+  [dx_cv_autotest_works=yes])
+rm -f conftest.at conftest.sh conftest.out[]m4_ifnblank([$1], [
+AS_CASE([$dx_cv_autotest_works], [yes], [$1])])])
index 5b3764bbaa82b2624c276c6293669e6a6c8cea5d..4e02f0be045fd0defa28fd62e0618ffe04f8b627 100644 (file)
@@ -1,21 +1,18 @@
-# Copyright © 2015,2019-2022 Nick Bowler
+# Copyright © 2015,2019-2023 Nick Bowler
 #
 # Automake fragment to hook up a basic Autotest test suite into the
 # build.  It is expected that a testsuite.at file exists in $(srcdir).
 # The testsuite will be output to $(builddir)/testsuite.
 #
 # The DX_AUTOMAKE_COMPAT macro must be expanded by configure.ac to
-# provide necessary substitutions.  If DX_PROG_AUTOTEST is used, this
-# will be included automatically.
+# provide necessary substitutions.
 #
 # You must define the AUTOTEST variable to the Autotest program (normally,
-# this is autom4te -l autotest).  The DX_PROG_AUTOTEST macro can be used
-# to set this automatically.  You must also define the HAVE_AUTOTEST Automake
-# conditional which controls whether the testsuite-generating rules are
-# enabled.  If DX_PROG_AUTOTEST is used, this may be set like:
+# this is autom4te -l autotest).  You must also define the HAVE_AUTOTEST
+# Automake conditional which controls whether the testsuite-generating
+# rules are enabled (that is, if Autotest is available and works).
 #
-#   DX_PROG_AUTOTEST
-#   AM_CONDITIONAL([HAVE_AUTOTEST], [test x"$dx_cv_autotest_works" = x"yes"])
+# The DX_PROG_AUTOTEST_AM macro may be used to set all of the above.
 #
 # License WTFPL2: Do What The Fuck You Want To Public License, version 2.
 # This is free software: you are free to do what the fuck you want to.
index d563ab2c80687d8f5c20c1df4ce27c19dd5b762d..bbb8360976b3c49f25d274e8edfba183634d5162 100755 (executable)
@@ -1,8 +1,8 @@
 #!/bin/sh
 #
-# Copyright © 2022 Nick Bowler
+# Copyright © 2022-2023 Nick Bowler
 #
-# Fake autotest program for testing the autotest snippets.
+# Fake autotest program for testing the autotest macros and snippets.
 #
 # License WTFPL2: Do What The Fuck You Want To Public License, version 2.
 # This is free software: you are free to do what the fuck you want to.
@@ -27,3 +27,4 @@ do
 done
 
 test x"$outfile" = x || exec 1>"$outfile"
+echo "echo 'testsuite (mypackage)'"
index b02d9abc7e94c3a965ab4932576842f74dabde6d..e482fcbdd775a0efbf7809044619f356b33d7450 100644 (file)
@@ -1,4 +1,4 @@
-dnl Copyright © 2020-2022 Nick Bowler
+dnl Copyright © 2020-2023 Nick Bowler
 dnl
 dnl License WTFPL2: Do What The Fuck You Want To Public License, version 2.
 dnl This is free software: you are free to do what the fuck you want to.
@@ -230,3 +230,54 @@ dx_cv_join_works=yes
 ])
 
 AT_CLEANUP
+
+AT_SETUP([autotest probes])
+AT_KEYWORDS([DX_PROG_BISON program])dnl
+
+AT_DATA([test.in],
+[[@AUTOTEST@
+@dx_cv_autotest_works@
+]])
+
+TEST_CONFIGURE_AC([[DX_PROG_AUTOTEST
+AC_SUBST([dx_cv_autotest_works])
+
+set x conftest*; shift
+if test -f $[]1; then
+  AC_MSG_ERROR([$[]1 left behind by [D@@&t@&t@X_PROG_AUTOTEST]])
+fi
+AC_CONFIG_FILES([test])]])
+TEST_AUTORECONF
+
+# Check the search via path lookup for autom4te
+mkdir bin
+cp -P "$srcdir/t/autotest.sh" bin/autom4te
+
+save_PATH=$PATH
+PATH=`pwd`/bin${PATH:+":$PATH"}
+TEST_CONFIGURE
+PATH=$save_PATH
+
+AT_CHECK([cat test], [0], [[autom4te -l autotest
+yes
+]])
+
+# Check that we can assign AUTOTEST directly
+TEST_CONFIGURE([AUTOTEST="$srcdir/t/autotest.sh"])
+AT_CHECK_UNQUOTED([cat test], [0], [[$srcdir/t/autotest.sh
+yes
+]])
+
+# Check that we can assign AUTOM4TE directly
+TEST_CONFIGURE([AUTOM4TE="$srcdir/t/autotest.sh"])
+AT_CHECK_UNQUOTED([cat test], [0], [[$srcdir/t/autotest.sh -l autotest
+yes
+]])
+
+# Check that a bogus program doesn't come back as valid
+TEST_CONFIGURE([AUTOTEST=true])
+AT_CHECK([cat test], [0], [[true
+no
+]])
+
+AT_CLEANUP
index 3794c7ee006be0da78a744d15c3edc73e316ae82..8e2f2429ccaa55f7a727809a5ede99cb53e17227 100644 (file)
@@ -10,8 +10,7 @@ m4_define([TEST_DEPFILES_INIT],
 [TEST_CONFIGURE_AC(
 [[AM_INIT_AUTOMAKE([foreign])
 
-DX_PROG_AUTOTEST
-AM_CONDITIONAL([HAVE_AUTOTEST], [test x"$dx_cv_autotest_works" = x"yes"])
+DX_PROG_AUTOTEST_AM
 
 AM_SET_DEPDIR
 AM_OUTPUT_DEPENDENCY_COMMANDS