From 9060b3e8d2ac9296abb97f159895718cd233f3bc Mon Sep 17 00:00:00 2001 From: Nick Bowler Date: Sat, 23 Dec 2023 16:41:03 -0500 Subject: [PATCH] DX_PROG_AUTOTEST: Modernize. 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 | 3 +- m4/autotest.m4 | 96 +++++++++++++++++++++++++-------------------- snippet/autotest.mk | 15 +++---- t/autotest.sh | 5 ++- tests/programs.at | 53 ++++++++++++++++++++++++- tests/snippets.at | 3 +- 6 files changed, 116 insertions(+), 59 deletions(-) diff --git a/configure.ac b/configure.ac index efac42f..1910c73 100644 --- a/configure.ac +++ b/configure.ac @@ -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 ], [dx_cv_have_struct_option], [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include ], diff --git a/m4/autotest.m4 b/m4/autotest.m4 index 063144a..854295f 100644 --- a/m4/autotest.m4 +++ b/m4/autotest.m4 @@ -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])])]) diff --git a/snippet/autotest.mk b/snippet/autotest.mk index 5b3764b..4e02f0b 100644 --- a/snippet/autotest.mk +++ b/snippet/autotest.mk @@ -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. diff --git a/t/autotest.sh b/t/autotest.sh index d563ab2..bbb8360 100755 --- a/t/autotest.sh +++ b/t/autotest.sh @@ -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)'" diff --git a/tests/programs.at b/tests/programs.at index b02d9ab..e482fcb 100644 --- a/tests/programs.at +++ b/tests/programs.at @@ -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 diff --git a/tests/snippets.at b/tests/snippets.at index 3794c7e..8e2f242 100644 --- a/tests/snippets.at +++ b/tests/snippets.at @@ -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 -- 2.43.2