Allow absolute names in AT_TESTED.
[autoconf.git] / tests / local.at
blob37ed3ea3b5bc7f2ec90273b970a7465b6af304e3
1 # M4 macros used in building Autoconf test suites.        -*- Autotest -*-
3 # Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
4 # 2009 Free Software Foundation, Inc.
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 m4_version_prereq([2.57])
21 # Used in many tests.
22 m4_pattern_allow([^AS_EXIT$])
23 m4_pattern_allow([^m4_(define|shift)$])
25 # Programs this package provides
26 AT_TESTED([autom4te autoconf autoheader autoupdate autoreconf ifnames])
29 ## ---------------- ##
30 ## Utility macros.  ##
31 ## ---------------- ##
33 # AT_CMP(FILE-1, FILE-2)
34 # ----------------------
35 # Check FILE-1 and FILE-2 for equality, like `cmp FILE-1 FILE-2'.
36 m4_define([AT_CMP],
37 [m4_ifval([$2],, [m4_fatal([AT_CMP takes two arguments.])])[]dnl
38 AT_CHECK([$at_diff "$1" "$2"])
39 ])# AT_CMP
42 ## ---------------- ##
43 ## Testing syntax.  ##
44 ## ---------------- ##
46 # AT_CHECK_SHELL_SYNTAX(PROGRAM)
47 # ------------------------------
48 # If the shell handles `-n' well, use it to check the syntax of PROGRAM;
49 # otherwise, do nothing.
50 m4_define([AT_CHECK_SHELL_SYNTAX],
51 [AT_SKIP_IF([test "$ac_cv_sh_n_works" != yes])
52 AT_CHECK([/bin/sh -n $1])])
54 m4_define([AT_CHECK_PERL_SYNTAX],
55 [AT_CHECK([autom4te_perllibdir=$abs_top_srcdir/lib $PERL -c "$abs_top_builddir"/bin/$1],
56           0, [], [ignore])])
58 ## ------------------ ##
59 ## Testing autom4te.  ##
60 ## ------------------ ##
63 # AT_CHECK_M4(COMMAND, [EXIT-STATUS = 0], STDOUT, STDERR)
64 # -------------------------------------------------------
65 # If stderr is specified, normalize the observed stderr.
66 # This (using GNU M4 1.4.6)
68 #  /usr/local/bin/m4:script.4s:1: cannot open `foo': No such file or directory
69 #  autom4te: /usr/local/bin/m4 failed with exit status: 1
71 # or this (GNU M4 1.4.11)
73 #  /usr/local/bin/m4:script.4s:1: include: cannot open `foo': No such file or directory
74 #  autom4te: /usr/local/bin/m4 failed with exit status: 1
76 # or this (GNU M4 1.4 installed as gm4)
78 #  script.4s:1: /usr/local/bin/gm4: Cannot open foo: No such file or directory
79 #  autom4te: /usr/local/bin/gm4 failed with exit status: 1
81 # becomes
83 #  m4:script.4s:1: cannot open `foo': No such file or directory
84 #  autom4te: m4 failed with exit status: 1
86 # We use the following sed patterns:
88 #     (m4): ?(file): ?(line):
89 # or  (file): ?(line): ?(m4):
90 # to  m4:(file):(line):
92 # and
93 #     m4:(file):(line): Cannot open foo:
94 # or  m4:(file):(line): include: cannot open `foo':
95 # to  m4:(file):(line): cannot open `foo':
97 # and
98 #     autom4te: [^ ]m4
99 # or  autom4te: [^ ]m4.exe
100 # to  autom4te: m4
102 # Moreover, DJGPP error messages include the error code in brackets;
103 # remove the error code during normalization.
105 m4_define([AT_CHECK_M4],
106 [AT_CHECK([$1], [$2], [$3],
107           m4_case([$4], [], [], [ignore], [ignore], [stderr]))
108 m4_case([$4], [], [], [ignore], [],
109 [AT_CHECK([[sed 's/^[^:]*m4[.ex]*: *\([^:]*:\) *\([0-9][0-9]*: \)/m4:\1\2/
110         s/^\([^:]*:\) *\([0-9][0-9]*:\)[^:]*m4[.ex]*: /m4:\1\2 /
111         s/: C\(annot open \)\([^`:]*\):/: c\1`\2'\'':/
112         s/: include:\( cannot open\)/:\1/
113         s/^autom4te: [^ ]*m4[.ex]* /autom4te: m4 /
114         s/ (E[A-Z]*)$//
115     ' stderr >&2]], [0], [], [$4])])
118 # AT_CHECK_AUTOM4TE(FLAGS, [EXIT-STATUS = 0], STDOUT, STDERR)
119 # -----------------------------------------------------------
120 m4_define([AT_CHECK_AUTOM4TE],
121 [AT_CHECK_M4([autom4te $1], [$2], [$3], [$4])])
125 ## ----------------- ##
126 ## Testing M4sugar.  ##
127 ## ----------------- ##
130 # AT_DATA_M4SUGAR(FILE-NAME, CONTENTS)
131 # ------------------------------------
132 # Escape the invalid tokens with @&t@.
133 m4_define([AT_DATA_M4SUGAR],
134 [AT_DATA([$1],
135 [m4_bpatsubst([$2], [\(@.\)\(.@\)\|\(m4\)\(_\)\|\(d\)\(nl\)],
136               [\1\3\5@&t@\2\4\6])])])
139 # AT_CHECK_M4SUGAR(FLAGS, [EXIT-STATUS = 0], STDOUT, STDERR)
140 # ----------------------------------------------------------
141 m4_define([AT_CHECK_M4SUGAR],
142 [AT_KEYWORDS([m4sugar])
143 AT_CHECK_AUTOM4TE([--language=m4sugar script.4s -o script $1],
144                    [$2], [$3], [$4])])
148 ## -------------- ##
149 ## Testing M4sh.  ##
150 ## -------------- ##
153 # AT_DATA_M4SH(FILE-NAME, CONTENTS)
154 # ---------------------------------
155 # Escape the invalid tokens with @&t@.
156 m4_define([AT_DATA_M4SH],
157 [AT_DATA([$1],
158 [m4_bpatsubst([$2], [\(@.\)\(.@\)\|\(m4\|AS\)\(_\)\|\(d\)\(nl\)],
159               [\1\3\5@&t@\2\4\6])])])
162 # AT_CHECK_M4SH(FLAGS, [EXIT-STATUS = 0], STDOUT, STDERR)
163 # -------------------------------------------------------
164 m4_define([AT_CHECK_M4SH],
165 [AT_CHECK_AUTOM4TE([--language=m4sh script.as -o script $1],
166                    [$2], [$3], [$4])])
170 ## ------------------ ##
171 ## Testing Autoconf.  ##
172 ## ------------------ ##
175 # AT_DATA_AUTOCONF(FILE-NAME, CONTENTS)
176 # -------------------------------------
177 # Escape the invalid tokens with @&t@.
178 m4_define([AT_DATA_AUTOCONF],
179 [AT_DATA([$1],
180 [m4_bpatsubst([$2], [\(@.\)\(.@\)\|\(m4\|AS\|AC\)\(_\)\|\(d\)\(nl\)],
181               [\1\3\5@&t@\2\4\6])])])
185 # AT_CONFIGURE_AC(BODY)
186 # ---------------------
187 # Create a full configure.ac running BODY, with a config header set up,
188 # AC_OUTPUT, and environment checking hooks.
189 m4_define([AT_CONFIGURE_AC],
190 [AT_DATA([configure.ac],
191 [[AC_INIT
192 AC_CONFIG_HEADERS(config.h:config.hin)
193 AC_STATE_SAVE(before)]
195 [AC_OUTPUT
196 AC_STATE_SAVE(after)
198 cp "$abs_top_srcdir/build-aux/install-sh" \
199    "$abs_top_srcdir/build-aux/config.guess" \
200    "$abs_top_srcdir/build-aux/config.sub" .
201 cp "$abs_top_srcdir/tests/statesave.m4" aclocal.m4
202 ])# AT_CONFIGURE_AC
205 # AT_CHECK_AUTOCONF(ARGS, [EXIT-STATUS = 0], STDOUT, STDERR)
206 # ----------------------------------------------------------
207 # We always use "--force", to prevent problems with timestamps if the testsuite
208 # were running too fast.
209 m4_define([AT_CHECK_AUTOCONF],
210 [AT_CHECK_M4([autoconf --force $1], [$2], [$3], [$4])
211 if test -s configure && test "$ac_cv_sh_n_works" = yes; then
212   AT_CHECK_SHELL_SYNTAX([configure])
217 # AT_CHECK_AUTOHEADER(ARGS, [EXIT-STATUS = 0], STDOUT, STDERR)
218 # ------------------------------------------------------------
219 m4_define([AT_CHECK_AUTOHEADER],
220 [AT_CHECK([autoheader $1], [$2], [$3], [$4])
224 # AT_CHECK_CONFIGURE(END-COMMAND,
225 #                    [EXIT-STATUS = 0],
226 #                    [STDOUT = IGNORE], STDERR)
227 # --------------------------------------------
228 # `abs_top_srcdir' is needed so that `./configure' finds install-sh.
229 # Using --srcdir is more expensive.
230 m4_define([AT_CHECK_CONFIGURE],
231 [AT_CAPTURE_FILE([config.log])[]dnl
232  AT_CHECK([./configure $configure_options $1],
233           [$2],
234           m4_default([$3], [ignore]), [$4])])
237 # AT_CHECK_ENV
238 # ------------
239 # Check that the full configure run remained in its variable name space,
240 # and cleaned up tmp files.
242 # Perhaps grep -E is not supported, or perhaps it chokes on such a big regex.
243 # In this case just don't pay attention to the env.  It would be great
244 # to keep the error message but we can't: that would break AT_CHECK.
246 # Some tests might exit prematurely when they find a problem, in
247 # which case `env-after' is probably missing.  Don't check it then.
249 # Here are the variables `configure' may modify during execution:
250 # - ^as_
251 #   M4sh's shell name space.
252 # - ^ac_
253 #   Autoconf's shell name space.
254 # - prefix and exec_prefix
255 #   are kept undefined (NONE) until AC_OUTPUT which then sets them to
256 #   `/usr/local' and `${prefix}' for make.
257 # - (host|build|target)(_(alias|cpu|vendor|os))?
258 #   Set by AC_CANONICAL_(HOST|BUILD|TARGET).
259 # - cross_compiling
260 #   Set by AC_INIT.
261 # - interpval
262 #   Set by AC_SYS_INTERPRETER.
263 # - CONFIG_STATUS and DEFS
264 #   Set by AC_OUTPUT.
265 # - AC_SUBST'ed variables
266 #   (FIXME: Generate a list of these automatically.)
267 # - _|@|.[*#?$].|argv|ARGC|LINENO|OLDPWD|PIPESTATUS|RANDOM|SECONDS
268 #   Some variables some shells use and change.
269 #   `.[*#?$].' catches `$#' etc. which are displayed like this:
270 #      | '!'=18186
271 #      | '#'=0
272 #      | '$'=6908
274 m4_define([AT_CHECK_ENV],
275 [m4_divert_once([PREPARE_TESTS], [_AT_CHECK_ENV])dnl
276 AT_CHECK([at_check_env])])
277 m4_define([_AT_CHECK_ENV],
278 [AS_FUNCTION_DESCRIBE([at_check_env], [],
279 [Compare the directory and environment state both before and after a run,
280 and return non-zero status if they differ inappropriately.])
281 at_check_env ()
283 # Compare directory listings.
284 test -f state-ls.before ||
285   AS_ERROR([state-ls.before not present])
286 test -f state-ls.after \
287   && { $at_diff state-ls.before state-ls.after || return 1; }
288 # Compare variable space dumps.
289 if test -f state-env.before && test -f state-env.after; then
290   for act_file in state-env.before state-env.after
291   do
292     $EGREP -v '^(m4_join([|],
293       [a[cs]_.*],
294       [(exec_)?prefix|DEFS|CONFIG_STATUS],
295       [CC|CFLAGS|CPP|GCC|CXX|CXXFLAGS|CXXCPP|GXX|F77|FFLAGS|FLIBS|G77],
296       [ERL|ERLC|ERLCFLAGS|ERLANG_PATH_ERL|ERLANG_ROOT_DIR|ERLANG_LIB_DIR],
297       [ERLANG_LIB_DIR_.*|ERLANG_LIB_VER_.*|ERLANG_INSTALL_LIB_DIR],
298       [ERLANG_INSTALL_LIB_DIR_.*|ERLANG_ERTS_VER|OBJC|OBJCPP|OBJCFLAGS],
299       [OBJCXX|OBJCXXCPP|OBJCXXFLAGS],
300       [OPENMP_CFLAGS],
301       [LIBS|LIB@&t@OBJS|LTLIBOBJS|LDFLAGS],
302       [INSTALL(_(DATA|PROGRAM|SCRIPT))?],
303       [CYGWIN|ISC|MINGW32|MINIX|EMXOS2|XENIX|EXEEXT|OBJEXT],
304       [X_(CFLAGS|(EXTRA_|PRE_)?LIBS)|x_(includes|libraries)|(have|no)_x],
305       [(host|build|target)(_(alias|cpu|vendor|os))?],
306       [cross_compiling],
307       [interpval|PATH_SEPARATOR],
308       [F77_DUMMY_MAIN|f77_(case|underscore)],
309       [FC(_DUMMY_MAIN|FLAGS|LIBS|FLAGS_f)?],
310       [ALLOCA|GETLOADAVG_LIBS|KMEM_GROUP|NEED_SETGID|POW_LIB],
311       [AWK|LEX|LEXLIB|LEX_OUTPUT_ROOT|LN_S|M4|MKDIR_P|RANLIB|SET_MAKE|YACC],
312       [GREP|[EF]GREP|SED],
313       [[_@]|.[*#?$].],
314       [argv|ARGC|LINENO|OLDPWD|PIPESTATUS|RANDOM|SECONDS]))=' \
315      $act_file 2>/dev/null |
316       # There may be variables spread on several lines; remove latter lines.
317       $GREP '^m4_defn([m4_re_word])=' >clean-$act_file
318   done
319   $at_diff clean-state-env.before clean-state-env.after
321 } [#]at_check_env])
324 # AT_CONFIG_CMP(VAR-FILE-A, VAR-FILE-B)
325 # -------------------------------------
326 # Check the outcomes of two configure runs for equality by comparing dumps of
327 # their shell variables.  VAR-FILE-A and VAR-FILE-B are two `set'-style shell
328 # variable space dumps.
330 # We permit variance between runs in the following shell variables:
331 # - ^as_
332 #   M4sh's shell name space.
333 # - ^ac_, excluding ^ac_cv_
334 #   Autoconf's private shell name space.
335 # - PPID [bash, zsh]
336 # - RANDOM [zsh]
337 # - SECONDS [zsh]
338 # - '$' [zsh]
339 # - argv [zsh]
340 # - ARGC [zsh]
342 # Furthermore, it is okay for a non-cache variable initialized to empty in one
343 # run to be unset in another run.  This happens when, for example, cache update
344 # code tries a number of values in LIBS and eventually restores LIBS to its
345 # original value. If LIBS was previously unset, it will have become set and
346 # empty.  (OTOH, cache variables indicate the result of the test even if they
347 # are empty, so we have to be strict about them.)
349 # Lines that do not look like `foo=bar' are probably latter lines of
350 # multiline values; trim them.
352 m4_define([AT_CONFIG_CMP],
353 [for act_file in $1 $2
355   $SED '/^ac_cv_/ b
356         /^m4_defn([m4_re_word])=./ !d
357         /^[[^=]]*='\'''\''$/ d
358         /^a[[cs]]_/ d
359         /^PPID=/ d
360         /^RANDOM=/ d
361         /^SECONDS=/ d
362         /'\'\\\$\''=/ d
363         /^argv=/ d
364         /^ARGC=/ d
365         ' $act_file >at_config_vars-$act_file
366 done
367 AT_CMP([at_config_vars-$1], [at_config_vars-$2])[]dnl
368 ])# AT_CONFIG_CMP
371 # AT_CHECK_DEFINES(CONTENT)
372 # -------------------------
373 # Verify that config.h, once stripped, is CONTENT.
374 # Stripping consists of keeping CPP lines (i.e. containing a hash),
375 # but those of automatically checked features (STDC_HEADERS etc.)
376 # and symbols (PACKAGE_...).
377 # AT_CHECK_HEADER is a better name, but too close from AC_CHECK_HEADER.
378 m4_define([AT_CHECK_DEFINES],
379 [AT_CHECK([[sed '/#/!d
380 /INTTYPES/d
381 /MEMORY/d
382 /PACKAGE_/d
383 /STDC_HEADERS/d
384 /STDINT/d
385 /STDLIB/d
386 /STRING/d
387 /SYS_STAT/d
388 /SYS_TYPES/d
389 /UNISTD/d' config.h]],,
390           [$1])])
393 # AT_CHECK_AUTOUPDATE
394 # -------------------
395 m4_define([AT_CHECK_AUTOUPDATE],
396 [AT_CHECK([autoupdate $1], [$2], [$3], [$4])
400 # _AT_CHECK_AC_MACRO(AC-BODY, PRE-TESTS)
401 # --------------------------------------
402 # Create a minimalist configure.ac running the macro named
403 # NAME-OF-THE-MACRO, check that autoconf runs on that script,
404 # and that the shell runs correctly the configure.
405 m4_define([_AT_CHECK_AC_MACRO],
406 [AT_CONFIGURE_AC([$1])
408 AT_CHECK_AUTOCONF
409 AT_CHECK_AUTOHEADER
410 AT_CHECK_CONFIGURE
411 AT_CHECK_ENV
412 ])# _AT_CHECK_AC_MACRO
415 # AT_CHECK_MACRO(MACRO, [MACRO-USE], [ADDITIONAL-CMDS],
416 #                [AUTOCONF-FLAGS = -W obsolete])
417 # -----------------------------------------------------
418 # Create a minimalist configure.ac running the macro named
419 # NAME-OF-THE-MACRO, check that autoconf runs on that script,
420 # and that the shell runs correctly the configure.
422 # We run `configure' twice, both times with a cache, and compare
423 # the environment after each run to detect inconsistencies.
425 # New macros are not expected to depend upon obsolete macros.
426 m4_define([AT_CHECK_MACRO],
427 [AT_SETUP([$1])
429 AT_CONFIGURE_AC([m4_default([$2], [$1])])
431 AT_CHECK_AUTOCONF([m4_default([$4], [-W obsolete])])
432 AT_CHECK_AUTOHEADER
434 for at_run in r1 r2
436     AT_CHECK_CONFIGURE([-C])
437     cp -f state-env.after state-env.$at_run
438     cp -f config.h config-h.$at_run
439     AT_CHECK_ENV
440 done
442 AT_CMP([config-h.r1], [config-h.r2])
443 AT_CONFIG_CMP([state-env.r1], [state-env.r2])
447 AT_CLEANUP[]dnl
448 ])# AT_CHECK_MACRO
451 # AT_CHECK_MACRO_CROSS(MACRO, [MACRO-USE], [ADDITIONAL-CMDS],
452 #                      [AUTOCONF-FLAGS = -W obsolete])
453 # -----------------------------------------------------------
454 # Like the previous one, but creates two checks: for native
455 # compile and for cross-compile.
456 m4_define([AT_CHECK_MACRO_CROSS],
457 [AT_CHECK_MACRO($@)
458 AT_CHECK_MACRO([$1 (cross compile)],
459   [AT_KEYWORDS([cross])
460   # Exercise the code used when cross-compiling.
461   cross_compiling=yes
462   ac_tool_warned=yes
463   m4_default([$2], [$1])],
464   [$3], [$4])
468 # AT_CHECK_AU_MACRO(MACRO)
469 # ------------------------
470 # Create a minimalist configure.ac running the macro named
471 # NAME-OF-THE-MACRO, autoupdate this script, check that autoconf runs
472 # on that script, and that the shell runs correctly the configure.
474 # Updated configure.ac shall not depend upon obsolete macros, which votes
475 # in favor of `-W obsolete', but since many of these macros leave a message
476 # to be removed by the user once her code is adjusted, let's not check.
478 # Remove config.hin to avoid `autoheader: config.hin is unchanged'.
479 m4_define([AT_CHECK_AU_MACRO],
480 [AT_SETUP([$1])
481 AT_KEYWORDS([autoupdate])
483 AT_CONFIGURE_AC([$1])
485 AT_CHECK_AUTOCONF
486 AT_CHECK_AUTOHEADER
487 AT_CHECK_CONFIGURE
488 AT_CHECK_ENV
490 rm config.hin
491 AT_CHECK_AUTOUPDATE([], 0, [], ignore)
492 AT_CHECK([grep '^$1$' configure.ac], 1)
494 AT_CHECK_AUTOCONF
495 AT_CHECK_AUTOHEADER
496 AT_CHECK_CONFIGURE
497 AT_CHECK_ENV
499 AT_CLEANUP[]dnl
500 ])# AT_CHECK_AU_MACRO
504 ## ----------------------- ##
505 ## Launch the test suite.  ##
506 ## ----------------------- ##
508 AT_INIT