autoconf/tests
Zack Weinberg d330dd6273 AC_REPLACE_FUNCS: invoke _AH_CHECK_FUNC and AC_LIBSOURCE unconditionally.
While investigating something else, I noticed that AC_REPLACE_FUNCS
calls _AH_CHECK_FUNC and AC_LIBSOURCE in the success branch of an
AC_CHECK_FUNC.  This doesn’t work; both of those are marker macros
that need to be expanded unconditionally at m4 time so that traces
(placed by autoheader and automake, respectively) will fire.  In order
to fix this while keeping the code readable, I would up doing a major
refactor.  There are now four internal macros implementing AC_REPLACE_FUNCS.

_AC_REPLACE_FUNC_U is called unconditionally for every shell word in
the list passed to AC_REPLACE_FUNCS, and does _AH_CHECK_FUNC +
AC_LIBSOURCE if it can, or issues a warning if it can’t.  (It could
make sense to make this a public function, if we think shell variables
in the AC_REPLACE_FUNCS list need to be supported long-term.  I dunno
if there’s a use case that can’t be handled by AC_REPLACE_FUNCS inside
a shell conditional just as well.)

_AC_REPLACE_FUNC_L and _AC_REPLACE_FUNC_NL implement the actual test
performed for each function to be replaced; the difference is that _L
(for literal) can only be used on a function whose name is known at m4
expansion time, _NL (nonliteral) works regardless.  _AC_REPLACE_FUNCS,
which already existed, handles looping either at m4 time or shell time
as appropriate.  AC_REPLACE_FUNCS remains a thin wrapper that runs
_AC_REPLACE_FUNCS(m4_flatten([$1])).

The _bulk_ of the patch is changes to the testsuite so that it notices
the original bug.  Specifically, AT_CHECK_AUTOHEADER now takes an
argument which is a whitespace-separated list of preprocessor macro
names that ought to appear in the generated config.h.in.  This can be
set to ‘ignore’ to skip the test, and unfortunately that’s what the
“trivial” per-macro tests have to do (AT_CHECK_MACRO and friends), so
coverage is not ideal, but it’s better than what we had.  Also,
AT_CHECK_M4 now normalizes the backtrace lines that appear in the
output of an AC_DIAGNOSE, e.g.

    configure.ac:6: warning: The macro `AC_LANG_SAVE' is obsolete.
    configure.ac:6: You should run autoupdate.
    ../../lib/autoconf/lang.m4:125: AC_LANG_SAVE is expanded from...
    configure.ac:6: the top level

becomes

    configure.ac:6: warning: The macro `AC_LANG_SAVE' is obsolete.
    configure.ac:6: You should run autoupdate.
    lang.m4: AC_LANG_SAVE is expanded from...
    configure.ac:6: the top level

This allows us to write tests for these diagnostics that don’t depend
on the relationship between the source and build directories, and
won’t break when unrelated patches change the line number of a macro
definition.

	* lib/autoconf/functions.m4 (AC_REPLACE_FUNCS, _AC_REPLACE_FUNCS)
        (_AC_REPLACE_FUNC): Refactor into AC_REPLACE_FUNCS,
        _AC_REPLACE_FUNCS, _AC_REPLACE_FUNC_U, _AC_REPLACE_FUNC_L,
        _AC_REPLACE_FUNC_NL.  Ensure that _AH_CHECK_FUNC and
        AC_LIBSOURCE are invoked unconditionally at m4 expansion
        time for each literal function name in the argument to
        AC_CHECK_FUNCS.  Issue warnings about non-literal names.

        * tests/local.at (AT_CHECK_M4): Normalize backtrace lines from
        the output of AC_DIAGNOSE / m4_warn.
        (AT_CHECK_AUTOHEADER): Add arg EXPECTED-TMPLS
        giving a list of preprocessor macro names that should appear
        in the generated config.h.in.  Use AT_CHECK_M4 to invoke autoheader.
        (_AT_CHECK_AC_MACRO, AT_CHECK_MACRO, AT_CHECK_AU_MACRO):
        Update uses of AT_CHECK_AUTOHEADER.
        * tests/fortran.at, tests/semantics.at, tests/tools.at
        * tests/torture.at: Update all uses of AT_CHECK_AUTOHEADER.

        * tests/semantics.at (AC_REPLACE_FUNCS test): Make somewhat
        more thorough, using new functionality of AT_CHECK_M4 and
        AT_CHECK_AUTOHEADER.

Signed-off-by: Zack Weinberg <zackw@panix.com>
2020-06-29 23:17:15 -07:00
..
atlocal.in Look harder for a shell whose -n is known to work. 2020-06-29 23:17:15 -07:00
autoscan.at maint: make update-copyright 2020-01-01 11:45:50 -08:00
autotest.at maint: make update-copyright 2020-01-01 11:45:50 -08:00
base.at maint: make update-copyright 2020-01-01 11:45:50 -08:00
c.at maint: make update-copyright 2020-01-01 11:45:50 -08:00
compile.at maint: make update-copyright 2020-01-01 11:45:50 -08:00
erlang.at maint: make update-copyright 2020-01-01 11:45:50 -08:00
foreign.at maint: make update-copyright 2020-01-01 11:45:50 -08:00
fortran.at AC_REPLACE_FUNCS: invoke _AH_CHECK_FUNC and AC_LIBSOURCE unconditionally. 2020-06-29 23:17:15 -07:00
go.at maint: make update-copyright 2020-01-01 11:45:50 -08:00
local.at AC_REPLACE_FUNCS: invoke _AH_CHECK_FUNC and AC_LIBSOURCE unconditionally. 2020-06-29 23:17:15 -07:00
local.mk maint: make update-copyright 2020-01-01 11:45:50 -08:00
m4sh.at Define $as_echo and $as_echo_n for backward compatibility. 2020-03-13 14:50:50 -04:00
m4sugar.at maint: make update-copyright 2020-01-01 11:45:50 -08:00
mktests.sh maint: make update-copyright 2020-01-01 11:45:50 -08:00
semantics.at AC_REPLACE_FUNCS: invoke _AH_CHECK_FUNC and AC_LIBSOURCE unconditionally. 2020-06-29 23:17:15 -07:00
statesave.m4 maint: make update-copyright 2020-01-01 11:45:50 -08:00
suite.at maint: make update-copyright 2020-01-01 11:45:50 -08:00
tools.at AC_REPLACE_FUNCS: invoke _AH_CHECK_FUNC and AC_LIBSOURCE unconditionally. 2020-06-29 23:17:15 -07:00
torture.at AC_REPLACE_FUNCS: invoke _AH_CHECK_FUNC and AC_LIBSOURCE unconditionally. 2020-06-29 23:17:15 -07:00
wrapper.as maint: make update-copyright 2020-01-01 11:45:50 -08:00