Improve wording for Y2038 and largefile probes
[autoconf.git] / tests / autotest.at
blob71cfe544c745f031eef325d4ee2bfa75526aa10b
1 #                                                       -*- Autotest -*-
3 AT_BANNER([Autotest.])
5 # Copyright (C) 2004-2017, 2020-2024 Free Software Foundation, Inc.
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program.  If not, see <https://www.gnu.org/licenses/>.
21 # AT_DATA_AUTOTEST(FILE-NAME, CONTENTS)
22 # -------------------------------------
23 # Escape the invalid tokens with @&t@.
24 m4_define([AT_DATA_AUTOTEST],
25 [AT_DATA([$1],
26 [m4_bpatsubst([$2], [\(@.\)\(.@\)\|\(m4\|AS\|AT\)\(_\)\|\(d\)\(nl\)],
27               [\1\3\5@&t@\2\4\6])])])
30 # AT_CHECK_AT_PREP(NAME, SUITE-CODE, [STATUS = 0], [STDOUT], [STDERR],
31 #                  [DIR = .])
32 # --------------------------------------------------------------------
33 # Create a new testsuite named NAME that runs a minimal Autotest test suite,
34 # SUITE-CODE.  Do not use 'testsuite' for NAME, or the log file it generates
35 # will overwrite the log that the Autoconf test produces when managing
36 # this test case.  STATUS, STDOUT, and STDERR pass directly to the AT_CHECK
37 # that compiles the testsuite.  DIR can specify a particular subdirectory
38 # where the testsuite should live.
39 m4_define([AT_CHECK_AT_PREP],
40 [AT_KEYWORDS([autotest])dnl
41 dnl overquote AT_dir, to make it easier to use
42 m4_pushdef([AT_dir], m4_ifval([$6], [[[$6]]], [.]))dnl
43 dnl
44 AT_CAPTURE_FILE(AT_dir[/$1.log])dnl
45 dnl
46 AT_DATA_AUTOTEST(AT_dir[/package.m4],
47 [[m4_define([AT_PACKAGE_NAME],      [GNU Nonsense])
48 m4_define([AT_PACKAGE_TARNAME],   [nonsense])
49 m4_define([AT_PACKAGE_VERSION],   [1.0])
50 m4_define([AT_PACKAGE_STRING],    [GNU Nonsense 1.0])
51 m4_define([AT_PACKAGE_BUGREPORT], [bug-autoconf@gnu.org])
52 ]])
53 dnl
54 AT_DATA_AUTOTEST(AT_dir[/$1.at], [$2])
55 AT_CHECK([cat >m4_default([$6], [.])/atconfig <<EOF
56 at_testdir=m4_default([$6], [.])
57 abs_builddir='`pwd`'
58 at_srcdir=.
59 abs_srcdir='`pwd`'
60 at_top_srcdir=.
61 abs_top_srcdir='`pwd`'
62 at_top_build_prefix=
63 abs_top_builddir='`pwd`'
64 EOF])
65 m4_ifval([$6], [(cd AT_dir])
66 AT_CHECK_AUTOM4TE([--language=autotest -o $1 $1.at], [$3], [$4], [$5])
67 m4_ifval([$6], [)])
68 m4_popdef([AT_dir])dnl
69 ]) # AT_CHECK_AT_PREP
71 # AT_CHECK_AT(TITLE, SUITE-CODE, [XFAIL-CONDITION], [STATUS = 0],
72 #             [STDOUT = ignore], STDERR, [PRE-TEST-CODE],
73 #             [POST-TEST-CODE], [SUITE-ARGS])
74 # ---------------------------------------------------------------
75 # Create a new test named TITLE that runs a minimal Autotest test suite,
76 # SUITE-CODE with additional SUITE-ARGS, once without and once with
77 # '-v -x' added.  Call AT_XFAIL_IF with XFAIL-CONDITION.  Pass STDERR
78 # directly to the AT_CHECK that calls the minimal test suite, STDOUT to
79 # the AT_CHECK without '-v -x'; ignore stdout for the latter.
80 # Run PRE-TEST-CODE at the top level after the micro-suite is created, but
81 # before it is run, and POST-TEST-CODE after the micro-suite has been run.
82 m4_define([AT_CHECK_AT],
83 [AT_SETUP([$1])
84 AT_XFAIL_IF([$3])
85 AT_CHECK_AT_PREP([micro-suite], [$2])
87 AT_CHECK([$CONFIG_SHELL ./micro-suite $9],       m4_default([$4], 0),
88          m4_default([$5], [ignore]), [$6])
89 AT_CHECK([$CONFIG_SHELL ./micro-suite -v -x $9], m4_default([$4], 0),
90          [ignore], [$6])
92 AT_CLEANUP
93 ])# AT_CHECK_AT
95 # AT_CHECK_AT_TEST(TITLE, SUITE-SNIPPET, ...)
96 # -------------------------------------------
97 # Wrapper for AT_CHECK_AT that surrounds SUITE-SNIPPET with a boilerplate
98 # AT_INIT, AT_SETUP, and AT_CLEANUP and passes other arguments verbatim.
99 m4_define([AT_CHECK_AT_TEST],
100 [AT_CHECK_AT([$1],
102 AT_INIT([artificial test suite])
103 AT_SETUP([my only test])
105 AT_CLEANUP
106 ]], m4_shift2($@))]) # AT_CHECK_AT_TEST
108 # AT_CHECK_AT_SYNTAX(TITLE, SUITE, MESSAGE)
109 # -----------------------------------------
110 # Create a test named TITLE that tries compiling SUITE with syntax
111 # errors with autotest.  Expect a failed compilation, and grep for
112 # MESSAGE occurring within the error output.
113 m4_define([AT_CHECK_AT_SYNTAX],
114 [AT_SETUP([$1])
115 AT_CHECK_AT_PREP([micro-suite], [$2], [1], [], [stderr])
116 AT_CHECK([grep '$3' stderr], [0], [ignore])
117 AT_CLEANUP
118 ])# AT_CHECK_AT_SYNTAX
121 # AT_NO_CMDSUBST
122 # --------------
123 m4_define([AT_NO_CMDSUBST],
124 [if (eval 'foo=$(echo bar) && test "$foo" = bar') >/dev/null 2>&1; then ]dnl
125 [false; else :; fi])
127 # AT_CHECK_EGREP(PATTERN, STATUS, COUNT)
128 # --------------------------------------
129 # Run grep -E, counting how many times PATTERN occurs in the file 'stdout',
130 # and expecting exit STATUS and output COUNT.
131 m4_define([AT_CHECK_EGREP],
132 [AT_CHECK([$EGREP -c '$1' stdout], [$2], [$3
133 ], [ignore])
137 ## -------------- ##
138 ## AT_COPYRIGHT.  ##
139 ## -------------- ##
141 # Ensure the FSF notice as well as the user-provided one are present
142 # in the head of the testsuite as well as the --version output.
144 AT_CHECK_AT([AT@&t@_COPYRIGHT],
145 [[AT_INIT([Testing AT@&t@_COPYRIGHT])
146 AT_COPYRIGHT([[This is just a test notice, not a real one, so let's avoid
147 words that may be matched by scanners for legal things,
148 causing extra work for distributors.
149 Multi-line values should be supported.
151 ]], [], [], [stdout], [], [], [
152 AT_CHECK([grep 'Copyright.*Free Software Foundation' stdout], [], [ignore])
153 AT_CHECK([grep 'This is just a test notice' stdout], [], [ignore])
154 AT_CHECK([sed 50q micro-suite | grep 'Copyright.*Free Software Foundation'],
155          [], [ignore])
156 AT_CHECK([sed 50q micro-suite | grep 'This is just a test notice'],
157          [], [ignore])],
158 [--version])
161 ## --------- ##
162 ## AT_DATA.  ##
163 ## --------- ##
165 AT_CHECK_AT_TEST([AT@&t@_DATA], [
166 AT_CHECK([test -f file1], [1])
167 AT_DATA([file1])
168 AT_CHECK([test -f file1 && test ! -s file1])
169 AT_CHECK([echo hi > file1])
170 AT_DATA([file1], [[]])
171 AT_CHECK([test -f file1 && test ! -s file1])
172 file=file2
173 AT_DATA([$file], [[$file
175 AT_CHECK([echo '$file' > file3])
176 AT_CHECK([cmp file2 file3])
180 ## ------------------ ##
181 ## AT_DATA_UNQUOTED.  ##
182 ## ------------------ ##
184 AT_CHECK_AT_TEST([AT@&t@_DATA_UNQUOTED], [
185 AT_CHECK([test -f file1], [1])
186 AT_DATA([file1])
187 AT_CHECK([test -f file1 && test ! -s file1])
188 AT_CHECK([echo hi > file1])
189 AT_DATA([file1], [[]])
190 AT_CHECK([test -f file1 && test ! -s file1])
191 file=file2
192 AT_DATA_UNQUOTED([$file], [[$file
194 AT_CHECK([echo file2 > file3])
195 AT_CHECK([cmp file2 file3])
198 ## ----------------------------------------------------------- ##
199 ## AT_PREPARE_TESTS, AT_PREPARE_EACH_TEST, AT_TEST_HELPER_FN.  ##
200 ## ----------------------------------------------------------- ##
202 AT_CHECK_AT([AT@&t@_PREPARE_TESTS],
204 AT_INIT([artificial test suite])
205 AT_PREPARE_TESTS([FOO=foo; export FOO])
206 AT_SETUP([my only test])
207 AT_CHECK([test x"$FOO" = xfoo])
208 AT_CLEANUP
211 AT_CHECK_AT([AT@&t@_PREPARE_EACH_TEST],
213 AT_INIT([artificial test suite])
214 AT_PREPARE_EACH_TEST([
215 if test -z "$at_test_counter"
216 then at_test_counter=1
217 else at_test_counter=`expr $at_test_counter + 1`
220 AT_SETUP([test one])
221 AT_CHECK([test "$at_test_counter" -eq 1])
222 AT_CLEANUP
223 AT_SETUP([test two])
224 AT_CHECK([test "$at_test_counter" -eq 2])
225 AT_CLEANUP
228 AT_CHECK_AT([AT@&t@_TEST_HELPER_FN],
230 AT_INIT([artificial test suite])
231 AT_TEST_HELPER_FN([helper], [], [], [test x"$][1" = x"$][2"])
232 AT_SETUP([my only test])
233 AT_CHECK([ath_fn_helper same same])
234 AT_CHECK([ath_fn_helper same other], [1])
235 AT_CLEANUP
239 ## ------------------ ##
240 ## Empty test suite.  ##
241 ## ------------------ ##
243 # This is not a sensible thing to do, but the user should not get an unhelpful
244 # error message.
245 AT_CHECK_AT([Empty test suite],
246 [[AT_INIT([empty test suite])
249 AT_CHECK_AT([Banner-only test suite],
250 [[AT_INIT([empty test suite])
251 AT_BANNER([banner])
254 # Next level of emptiness.
255 AT_CHECK_AT_TEST([Empty test], [])
257 # And finally, an empty check should not cause a syntax error.
258 AT_CHECK_AT_TEST([Empty check], [AT_CHECK])
260 # Check for sensible error messages for common bugs.
261 AT_CHECK_AT_SYNTAX([AT@&t@_SETUP without AT@&t@_INIT],
262 [[AT_SETUP([only test])
263 AT_CHECK([:])
264 AT_CLEANUP
265 ]], [AT@&t@_SETUP: missing AT@&t@_INIT detected])
267 AT_CHECK_AT_SYNTAX([AT@&t@_BANNER without AT@&t@_INIT],
268 [[AT_BANNER([just a banner])
269 ]], [AT@&t@_BANNER: missing AT@&t@_INIT detected])
271 AT_CHECK_AT_SYNTAX([AT@&t@_CLEANUP without AT@&t@_INIT],
272 [[AT_CLEANUP
273 ]], [AT@&t@_CLEANUP: missing AT@&t@_INIT detected])
275 AT_CHECK_AT_SYNTAX([Missing AT@&t@_CLEANUP],
276 [[AT_INIT([incomplete test suite])
277 AT_SETUP([only test])
278 AT_CHECK([:])
279 ]], [missing AT@&t@_CLEANUP detected])
281 AT_CHECK_AT_SYNTAX([AT@&t@_FAIL_IF without AT@&t@_SETUP],
282 [[AT_INIT([incomplete test suite])
283 AT_FAIL_IF([:])
284 ]], [AT@&t@_FAIL_IF: missing AT@&t@_SETUP detected])
286 AT_CHECK_AT_SYNTAX([AT@&t@_SKIP_IF without AT@&t@_SETUP],
287 [[AT_INIT([incomplete test suite])
288 AT_SKIP_IF([:])
289 ]], [AT@&t@_SKIP_IF: missing AT@&t@_SETUP detected])
291 AT_CHECK_AT_SYNTAX([AT@&t@_CHECK without AT@&t@_SETUP],
292 [[AT_INIT([incomplete test suite])
293 AT_CHECK([:])
294 ]], [AT@&t@_CHECK: missing AT@&t@_SETUP detected])
296 AT_CHECK_AT_SYNTAX([AT@&t@_DATA without AT@&t@_SETUP],
297 [[AT_INIT([incomplete test suite])
298 AT_DATA([file])
299 ]], [AT@&t@_DATA: missing AT@&t@_SETUP detected])
301 AT_CHECK_AT_SYNTAX([AT@&t@_XFAIL_IF without AT@&t@_SETUP],
302 [[AT_INIT([incomplete test suite])
303 AT_XFAIL_IF([:])
304 ]], [AT@&t@_XFAIL_IF: missing AT@&t@_SETUP detected])
306 AT_CHECK_AT_SYNTAX([AT@&t@_KEYWORDS without AT@&t@_SETUP],
307 [[AT_INIT([incomplete test suite])
308 AT_KEYWORDS([keyword])
309 ]], [AT@&t@_KEYWORDS: missing AT@&t@_SETUP detected])
311 AT_CHECK_AT_SYNTAX([AT@&t@_CLEANUP without AT@&t@_SETUP],
312 [[AT_INIT([incomplete test suite])
313 AT_CLEANUP
314 ]], [AT@&t@_CLEANUP: missing AT@&t@_SETUP detected])
316 AT_CHECK_AT_SYNTAX([AT@&t@_BANNER inside AT@&t@_SETUP],
317 [[AT_INIT([incomplete test suite])
318 AT_SETUP([only test])
319 AT_BANNER([banner])
320 AT_CHECK([:])
321 AT_CLEANUP
322 ]], [AT@&t@_BANNER: nested AT@&t@_SETUP detected])
324 AT_CHECK_AT_SYNTAX([AT@&t@_SETUP inside AT@&t@_SETUP],
325 [[AT_INIT([incomplete test suite])
326 AT_SETUP([only test])
327  AT_SETUP([nested test])
328  AT_CHECK([:])
329  AT_CLEANUP
330 AT_CHECK([:])
331 AT_CLEANUP
332 ]], [AT@&t@_SETUP: nested AT@&t@_SETUP detected])
334 AT_CHECK_AT_SYNTAX([Multiple AT@&t@_INIT],
335 [[AT_INIT([[suite, take one]])
336 AT_INIT([repeat])
337 ]], [AT@&t@_INIT: invoked multiple times])
339 AT_CHECK_AT_SYNTAX([Invalid AT@&t@_TEST_HELPER_FN (spaces)],
340 [[AT_INIT([buggy test suite])
341 AT_TEST_HELPER_FN([bad name], [], [], [:])
342 AT_SETUP([only test])
343 AT_CHECK([:])
344 AT_CLEANUP
345 ]], [invalid shell function name "bad name"])
347 AT_CHECK_AT_SYNTAX([Invalid AT@&t@_TEST_HELPER_FN (substitutions)],
348 [[AT_INIT([buggy test suite])
349 AT_TEST_HELPER_FN([variable_${name}], [], [], [:])
350 AT_SETUP([only test])
351 AT_CHECK([:])
352 AT_CLEANUP
353 ]], [invalid shell function name "variable_${name}"])
355 AT_CHECK_AT_SYNTAX([Multiple AT@&t@_TEST_HELPER_FN],
356 [[AT_INIT([buggy test suite])
357 AT_TEST_HELPER_FN([repeated], [], [], [AS_ECHO([repeated 1])])
358 # The duplicate check only cares about the name.
359 AT_TEST_HELPER_FN([repeated], [args], [desc], [AS_ECHO([repeated 2])])
360 AT_SETUP([only test])
361 AT_CHECK([:])
362 AT_CLEANUP
363 ]], [helper function "repeated" defined twice])
365 # Check for tested programs.  autoconf should only appear once.
366 AT_CHECK_AT([Tested programs],
367 [[AT_INIT([programs test suite])
368 AT_TESTED([autoconf autom4te])
369 AT_TESTED([autoconf])
370 ]], [], [], [], [], [],
371 [AT_CHECK([[sed -n 's|.*/\([^ /]* --version\)|\1|p' micro-suite.log]], [],
372 [[autoconf --version
373 autom4te --version
374 ]])])
376 AT_CHECK_AT([Startup error messages],
377 [[AT_INIT([[suite]])
378 AT_SETUP([only test])
379 AT_CHECK([:])
380 AT_CLEANUP
381 ]], [], [], [], [], [],
382 [AT_CHECK([sed -n '/exec AS_MESSAGE_LOG_FD/q; />&AS_MESSAGE_LOG_FD/p' < micro-suite])])
384 ## ----------------- ##
385 ## Status handling.  ##
386 ## ----------------- ##
388 AT_CHECK_AT_TEST([Truth],
389   [AT_CHECK([:], 0, [], [])])
391 AT_CHECK_AT_TEST([Fallacy],
392   [AT_CHECK([false], [], [], [])],
393   [], [1], [], [ignore], [],
394   [AT_CHECK([grep failed micro-suite.log], [], [ignore])])
396 AT_CHECK_AT_TEST([Skip],
397   [AT_CHECK([echo output; echo irrelevant >&2; exit 77], 0, [mismatch], [])],
398   [], [], [], [], [],
399   [AT_CHECK([grep skipped micro-suite.log], [], [ignore])])
401 AT_CHECK_AT_TEST([Hard fail],
402   [AT_CHECK([exit 99])
403    AT_CLEANUP
404    AT_SETUP([another test])
405    AT_XFAIL_IF([:])
406    AT_CHECK([exit 99])],
407   [], [1], [], [ignore], [],
408   [AT_CHECK([grep '2 failed unexpectedly' micro-suite.log], [], [ignore])
409    AT_CHECK([grep '^[[12]].*ok' micro-suite.log], [1])])
411 AT_CHECK_AT_TEST([AT@&t@_FAIL_IF],
412   [AT_FAIL_IF([:])
413   AT_CLEANUP
414   AT_SETUP
415   AT_FAIL_IF([false])
416   AT_CLEANUP
417   AT_SETUP
418   AT_FAIL_IF([test x = y])
419   AT_CLEANUP
420   AT_SETUP
421   AT_FAIL_IF([bah])
422   AT_CLEANUP
423   AT_SETUP
424   AT_FAIL_IF([test x = x])
425   AT_CLEANUP
426   AT_SETUP
427   AT_FAIL_IF([test $foo = x])],
428   [], [1], [stdout], [ignore], [],
429   [AT_CHECK([grep '1 5 failed' stdout], [], [ignore], [ignore])])
431 AT_CHECK_AT_TEST([AT@&t@_SKIP_IF],
432   [AT_SKIP_IF([:])
433   AT_CLEANUP
434   AT_SETUP
435   AT_SKIP_IF([false])
436   AT_CLEANUP
437   AT_SETUP
438   AT_SKIP_IF([test x = y])
439   AT_CLEANUP
440   AT_SETUP
441   AT_SKIP_IF([bah])
442   AT_CLEANUP
443   AT_SETUP
444   AT_SKIP_IF([test x = x])
445   AT_CLEANUP
446   AT_SETUP
447   AT_SKIP_IF([test $foo = x])],
448   [], [], [], [], [],
449   [AT_CHECK([grep '2.*skipped' micro-suite.log], [], [ignore], [ignore])])
451 AT_CHECK_AT_TEST([Syntax error],
452   [AT_CHECK([:])
453    AT_CLEANUP
454    AT_SETUP([syntax])
455    AT_CHECK([if])
456    AT_CLEANUP
457    AT_SETUP([another test])
458    AT_CHECK([:])],
459   [], [0], [], [], [],
460   [dnl Until we can find a way to avoid catastrophic failure (ash) or
461    dnl lack of failure (zsh), skip the rest of this test on such shells.
462    echo 'if' > syntax
463    AT_CHECK([${CONFIG_SHELL-$SHELL} -c 'case `. ./syntax; echo $?` in
464                   0|"") exit 77;;
465                 esac'], [0], [ignore], [ignore])
466    AT_CHECK([${CONFIG_SHELL-$SHELL} ./micro-suite], [1], [ignore], [stderr])
467    AT_CHECK([grep "unable to parse test group: 2" stderr], [0], [ignore])],
468   [1 3])
470 AT_CHECK_AT_TEST([errexit],
471   [AT_CHECK([false])
472    AT_CLEANUP
473    AT_SETUP([test that should not be run])
474    AT_CHECK([:])
475    AT_CLEANUP
476    AT_SETUP([xpassing test])
477    AT_XFAIL_IF([:])
478    AT_CHECK([:])
479    AT_CLEANUP
480    AT_SETUP([another test that should not be run])
481    AT_CHECK([:])
482    AT_CLEANUP
483    AT_SETUP([skipping test])
484    AT_CHECK([exit 77])
485    AT_CLEANUP
486    AT_SETUP([xfailing test])
487    AT_XFAIL_IF([:])
488    AT_CHECK([false])
489    AT_CLEANUP
490    AT_SETUP([a test that should be run])
491    AT_CLEANUP
492    AT_SETUP([hard failure])
493    AT_XFAIL_IF([:])
494    AT_CHECK([exit 99])
495    AT_CLEANUP
496    AT_SETUP([yet another test that should not be run])],
497   [], [1], [stdout], [stderr], [],
498   [AT_CHECK([test -f micro-suite.log], [1])
499    touch micro-suite.log # shut up AT_CAPTURE_FILE.
500    AT_CHECK([grep "should not be run" stdout], [1])
501    AT_CHECK([grep "1 .* inhibited subsequent" stderr], [], [ignore])
502    AT_CHECK([$CONFIG_SHELL ./micro-suite --errexit 3-], [1], [stdout], [stderr])
503    AT_CHECK([grep "should not be run" stdout], [1])
504    AT_CHECK([grep "1 .* inhibited subsequent" stderr], [], [ignore])
505    AT_CHECK([$CONFIG_SHELL ./micro-suite --errexit 5-], [1], [stdout], [stderr])
506    AT_CHECK([grep "should be run" stdout], [0], [ignore])
507    AT_CHECK([grep "should not be run" stdout], [1])
508    AT_CHECK([grep "inhibited subsequent" stderr], [], [ignore])],
509   [--errexit])
512 AT_CHECK_AT_TEST([at_status],
513   [AT_CHECK([exit $mystatus], [$expected], [], [],
514             [AT_CHECK([echo run-if-fail: $at_status], [], [ignore])],
515             [AT_CHECK([echo run-if-pass: $at_status], [], [ignore])])
516    AT_CLEANUP
517    AT_SETUP([test with nested checks])
518    AT_CHECK([exit $mystatus], [$expected], [], [],
519             [AT_CHECK([exit $mystatus], [$expected], [], [],
520                       [AT_CHECK([echo inner run-if-fail: $at_status], [],
521                                 [ignore])])])],
522   [], [], [stdout], [],
523 [], [
524 AT_CHECK([grep 'inner run-if-fail: 42' stdout], [], [ignore])
525 AT_CHECK([$CONFIG_SHELL ./micro-suite -x -v 1 mystatus=0 expected=0], [], [stdout])
526 AT_CHECK([grep 'run-if-pass: 0' stdout], [], [ignore])
527 AT_CHECK([$CONFIG_SHELL ./micro-suite -x -v 1 mystatus=42 expected=0], [], [stdout])
528 AT_CHECK([grep 'run-if-fail: 42' stdout], [], [ignore])
529 AT_CHECK([$CONFIG_SHELL ./micro-suite -x -v 1 mystatus=0 expected=42], [], [stdout])
530 AT_CHECK([grep 'run-if-fail: 0' stdout], [], [ignore])
531 AT_CHECK([$CONFIG_SHELL ./micro-suite -x -v 1 mystatus=42 expected=42], [], [stdout])
532 AT_CHECK([grep 'run-if-pass: 42' stdout], [], [ignore])
534 [-v mystatus=42 expected=1
538 AT_CHECK_AT_TEST([AT@&t@_CHECK execution environment],
539   [dnl The first test should fail, so we enter RUN-IF-FAIL.
540    AT_CHECK([test "$state" != before], [], [], [],
541             [state=run-if-fail
542              AT_CHECK([:]) dnl need this so we do not bail out at this point.
543             ])
544    dnl This should pass, so we enter RUN-IF-PASS.
545    AT_CHECK([test "$state" = run-if-fail], [], [], [], [],
546             [state=run-if-pass])
547    AT_CHECK([test "$state" = run-if-pass])
548    dnl However, COMMANDS are run inside a subshell, so do not change state.
549    AT_CHECK([state=broken; false], [], [], [],
550             [AT_CHECK([test "$state" = run-if-pass])])
551    AT_CHECK([state=broken], [], [], [], [],
552             [AT_CHECK([test "$state" = run-if-pass])])
553   ],
554   [], [], [], [], [], [], [state=before])
557 AT_CHECK_AT_TEST([unquoted output],
558   [m4_define([backtick], [`])
559    a=a
560    AT_CHECK_UNQUOTED([echo 'a"b  backtick`'], [],
561      [${a}"`echo 'b  '`\`\backtick]m4_newline)],
562   [], [], [], [], [AT_KEYWORDS([AT@&t@_CHECK_UNQUOTED])])
564 AT_CHECK_AT_TEST([Trace output],
565   [AT_CHECK([echo some longer longer longer command piped | ]dnl
566             [sed 's,into some other longer longer longer command,,'],
567             [], [some longer longer longer command piped
568 ])])
570 AT_CHECK_AT([Logging],
571   [[AT_INIT([artificial test suite])
572     dnl intentionally write failing tests, to see what gets logged
573     AT_SETUP([one])
574     AT_CHECK([echo magicstring01], [1], [ignore])
575     AT_CLEANUP
576     AT_SETUP([two])
577     AT_CHECK([echo magicstring02 >&2], [1], [], [ignore])
578     AT_CLEANUP
579     AT_SETUP([three])
580     AT_CHECK([echo magicstring03], [1], [ignore-nolog])
581     AT_CLEANUP
582     AT_SETUP([four])
583     AT_CHECK([echo magicstring04 >&2], [1], [], [ignore-nolog])
584     AT_CLEANUP
585     AT_SETUP([five])
586     AT_CHECK([echo magicstring05], [1], [stdout])
587     AT_CLEANUP
588     AT_SETUP([six])
589     AT_CHECK([echo magicstring06 >&2], [1], [], [stderr])
590     AT_CLEANUP
591     AT_SETUP([seven])
592     AT_CHECK([echo magicstring07], [1], [stdout-nolog])
593     AT_CLEANUP
594     AT_SETUP([eight])
595     AT_CHECK([echo magicstring08 >&2], [1], [], [stderr-nolog])
596     AT_CLEANUP
597     AT_SETUP([nine])
598     echo magicstring09 > expout
599     AT_CHECK([echo magicstring09], [1], [expout])
600     AT_CLEANUP
601     AT_SETUP([ten])
602     echo magicstring10 > experr
603     AT_CHECK([echo magicstring10 >&2], [1], [], [experr])
604     AT_CLEANUP
605 ]], [], [1], [], [ignore], [],
606   [AT_CHECK([$CONFIG_SHELL ./micro-suite], [1], [ignore-nolog], [ignore-nolog])
607    AT_CHECK([grep '^magicstring' micro-suite.log], [],
608 [[magicstring01
609 magicstring02
610 magicstring05
611 magicstring06
612 ]])])
615 AT_CHECK_AT([Binary output],
616   [[AT_INIT([artificial test suite])
617     AT_SETUP([pass: no trailing newline])
618     AT_CHECK([printf short], [0], [stdout-nolog])
619     AT_CHECK([cat stdout], [0], [[short]])
620     AT_CLEANUP
621     AT_SETUP([pass: non-printing characters])
622     AT_CHECK([printf '\1\n' >&2], [0], [], [stderr-nolog])
623     printf '\1\n' > expout
624     AT_CHECK([cat stderr], [0], [expout])
625     AT_CLEANUP
626     AT_SETUP([pass: long lines])
627     # 5000 bytes in str
628     str=..........
629     str=$str$str$str$str$str$str$str$str$str$str
630     str=$str$str$str$str$str$str$str$str$str$str
631     str=$str$str$str$str$str
632     AT_CHECK_UNQUOTED([echo $str], [0], [[$str]m4_newline])
633     AT_CLEANUP
634     AT_SETUP([fail: no trailing newline])
635     AT_CHECK([printf short], [0], [stdout-nolog])
636     AT_CHECK([cat stdout], [0], [[long]])
637     AT_CLEANUP
638     AT_SETUP([fail: non-printing characters])
639     AT_CHECK([printf '\1\n' >&2], [0], [], [stderr-nolog])
640     printf '\2\n' > expout
641     AT_CHECK([cat stderr], [0], [expout])
642     AT_CLEANUP
643     AT_SETUP([fail: long lines])
644     # 5000 bytes in str
645     str=..........
646     str=$str$str$str$str$str$str$str$str$str$str
647     str=$str$str$str$str$str$str$str$str$str$str
648     str=$str$str$str$str$str
649     AT_CHECK_UNQUOTED([echo x$str], [0], [[${str}x]m4_newline])
650     AT_CLEANUP
651 ]], [], [0], [], [], [],
652   [AT_CHECK([$CONFIG_SHELL ./micro-suite 4], [1], [ignore], [ignore])
653    AT_CHECK([$CONFIG_SHELL ./micro-suite 5], [1], [ignore], [ignore])
654    AT_CHECK([$CONFIG_SHELL ./micro-suite 6], [1], [ignore], [ignore])], [1-3])
657 AT_CHECK_AT_TEST([Cleanup],
658   [AT_CHECK([test ! -f cleanup.success && test ! -f cleanup.failure])
659    AT_XFAIL_IF([$xfail])
660    AT_CHECK_UNQUOTED([exit $value], [ignore], [$output],
661      [], [touch cleanup.failure], [touch cleanup.success])],
662   [], [], [], [],
663   [AT_KEYWORDS([AT@&t@_CHECK_UNQUOTED])
664     output=; export output],
665   [AT_CHECK([test -d micro-suite.dir/1])
666    AT_CHECK([test -f micro-suite.dir/1/cleanup.success])
667    AT_CHECK([test ! -f micro-suite.dir/1/cleanup.failure])
669    AT_CHECK([$CONFIG_SHELL ./micro-suite -d xfail=false value=1], [], [ignore])
670    AT_CHECK([test -f micro-suite.dir/1/cleanup.success])
671    AT_CHECK([test ! -f micro-suite.dir/1/cleanup.failure])
673    AT_CHECK([$CONFIG_SHELL ./micro-suite xfail=: value=0],
674      [1], [ignore], [ignore])
675    AT_CHECK([test -f micro-suite.dir/1/cleanup.success])
676    AT_CHECK([test ! -f micro-suite.dir/1/cleanup.failure])
678    AT_CHECK([$CONFIG_SHELL ./micro-suite -d xfail=false value=1 output=mismatch],
679      [1], [ignore], [ignore])
680    AT_CHECK([test ! -f micro-suite.dir/1/cleanup.success])
681    AT_CHECK([test -f micro-suite.dir/1/cleanup.failure])
683    AT_CHECK([$CONFIG_SHELL ./micro-suite -d xfail=false value=77], [], [ignore])
684    AT_CHECK([test ! -f micro-suite.dir/1/cleanup.success])
685    AT_CHECK([test ! -f micro-suite.dir/1/cleanup.failure])
687    AT_CHECK([$CONFIG_SHELL ./micro-suite -d xfail=false value=99],
688      [1], [ignore], [ignore])
689    AT_CHECK([test ! -f micro-suite.dir/1/cleanup.success])
690    AT_CHECK([test ! -f micro-suite.dir/1/cleanup.failure])
691   ], [-d xfail=false value=0])
693 ## ----------------------------------------------------- ##
694 ## Newlines and command substitutions in test commands.  ##
695 ## ----------------------------------------------------- ##
697 AT_CHECK_AT_TEST([Literal multiline command],
698   [AT_CHECK([echo Auto'
699 'conf], 0, [Auto
700 conf
701 ], [])])
703 AT_CHECK_AT_TEST([Multiline parameter expansion],
704   [FOO='one
705 two'
706    AT_CHECK([echo "$FOO"], 0, [one
708 ], [])])
710 AT_CHECK_AT_TEST([Backquote command substitution],
711   [AT_CHECK([echo `echo hi`], 0, [hi
712 ], [])])
715 AT_CHECK_AT_TEST([Multiline backquote command substitution],
716   [AT_DATA([myfile],[foo
719    AT_CHECK([echo "`cat myfile`"], 0, [foo
721 ], [])])
723 AT_CHECK_AT_TEST([Parenthetical command substitution],
724   [AT_CHECK([echo $(echo hi)], 0, [hi
725 ], [])],
726   [AT_NO_CMDSUBST])
728 AT_CHECK_AT_TEST([Multiline parenthetical command substitution],
729   [AT_DATA([myfile],[foo
732    AT_CHECK([echo "$(cat myfile)"], 0, [foo
734 ], [])],
735   [AT_NO_CMDSUBST])
738 AT_CHECK_AT_TEST([Shell comment in command],
739   [my_echo=echo
740    AT_CHECK([$my_echo one [#] two], [], [one
741 ])])
744 ## ------------------------- ##
745 ## ${...} in test commands.  ##
746 ## ------------------------- ##
748 # If this invalid parameter expansion capsizes the test suite, the entire
749 # AT_SETUP ... AT_CLEANUP subshell will exit, and the commands it runs will
750 # appear to have succeeded.  Therefore, we verify a failing test case.
752 AT_CHECK_AT_TEST([Invalid brace-enclosed parameter expansion],
753   [AT_CHECK([echo '${=invalid}'], 0, [wrong])], [false], 1, ignore, ignore)
756 ## ---------------------------- ##
757 ## M4 macros in test commands.  ##
758 ## ---------------------------- ##
760 AT_CHECK_AT_TEST([Multiline command from M4 expansion],
761   [m4_define([GNU], ['foo
762 bar'])
763    AT_CHECK([echo GNU], 0, [foo
765 ], [])])
767 AT_CHECK_AT_TEST([Double-M4-quoted command],
768   [m4_define([GNU], ['foo
769 bar'])
770    AT_CHECK([[echo GNU]], 0, [[GNU
771 ]], [])])
774 AT_CHECK_AT_TEST([Metacharacters in command from M4 expansion],
775   [m4_define([GNU], [\"`])
776    AT_CHECK([echo '\"`' [GNU] 'GNU'], 0, [GNU [G][NU] [\"`
777 ]], [])])
780 ## -------------------------------------- ##
781 ## Backslash-<newline> in test commands.  ##
782 ## -------------------------------------- ##
784 AT_CHECK_AT_TEST([BS-newline in command],
785   [AT_CHECK([echo Auto"\
786 "conf], 0, [Autoconf
787 ], [])])
789 AT_CHECK_AT_TEST([^BS-newline in command],
790   [AT_CHECK([\
791 echo GNU], 0, [GNU
792 ], [])])
794 AT_CHECK_AT_TEST([BSx641-newline in command],
795   [AT_CHECK([printf '%s\n' Auto"\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
796 "conf], 0, [Auto\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\conf
797 ], [])])
799 AT_CHECK_AT_TEST([BS-BS-newline in command],
800   [AT_CHECK([printf '%s\n' Auto"\\
801 "conf], 0, [Auto\
802 conf
803 ], [])])
805 # A '^BS-BS-newline in command' test will run a command named '\'.  No, thanks.
807 AT_CHECK_AT_TEST([BSx640-newline in command],
808   [AT_CHECK([printf '%s\n' Auto"\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
809 "conf], 0, [Auto\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
810 conf
811 ], [])])
813 # This command has both escaped and unescaped newlines.
814 AT_CHECK_AT_TEST([Newline-CODE-BS-newline in command],
815   [AT_CHECK([printf '%s\n' Auto'
816 'co\
817 nf], 0, [Auto
818 conf
819 ], [])])
821 AT_CHECK_AT_TEST([Single-quote-BS-newline in command],
822   [AT_CHECK([printf '%s\n' Auto'\
823 'conf], 0, [Auto\
824 conf
825 ], [])])
827 AT_CHECK_AT_TEST([Single-quote-newline-BS-newline in command],
828   [AT_CHECK([printf '%s\n' Auto'
830 'conf], 0, [Auto
832 conf
833 ], [])])
836 ## ----------------- ##
837 ## Input from stdin. ##
838 ## ----------------- ##
840 AT_SETUP([Input from stdin])
842 AT_CHECK_AT_PREP([micro-suite],
843 [[AT_INIT
844 AT_SETUP([please enter hello<RETURN><EOF>])
845 AT_CHECK([cat], [], [hello
847 AT_CLEANUP
850 AT_CHECK([echo hello | $CONFIG_SHELL ./micro-suite], [], [ignore])
851 AT_CHECK([$CONFIG_SHELL ./micro-suite </dev/null], [1], [ignore], [ignore])
853 AT_CLEANUP
856 ## ------------------------------- ##
857 ## Funny characters in test names. ##
858 ## ------------------------------- ##
860 # AT_CHECK_AT_TITLE(TITLE, TITLE-TO-TEST, EXPANDED-TITLE-TO-TEST,
861 #                   [XFAIL-CONDITION], [COLUMN = 53])
862 # ---------------------------------------------------------------
863 # Create a new test named TITLE that runs an Autotest test suite
864 # comprised of a trivial test named TITLE-TO-TEST, which expands
865 # to EXPANDED-TITLE-TO-TEST.  XFAIL-CONDITION passes verbatim to
866 # AT_CHECK_AT.  Verify that 'ok' prints at COLUMN.
867 m4_define([AT_CHECK_AT_TITLE],
868 [AT_CHECK_AT([$1],
870 m4_define([macro_name],         [[macro_expanded]])
871 m4_define([macro_expanded],     [[macro_overexpanded]])
872 m4_define([macro_backquote],    [`])
873 m4_define([macro_single_quote], ['])
874 m4_define([macro_double_quote], ["])
875 ]]dnl restore font-lock: "
876 [[m4_define([macro_backslash],  [\])
877 m4_define([macro_echo],         [$][1])
878 AT_INIT([artificial test suite])
879 AT_SETUP([$2])
880 AT_CHECK([:])
881 AT_CLEANUP
882 ]], [$4], [], [], [], [],
883 dnl This sed script checks for two things - that the output is properly
884 dnl expanded, and that the 'ok' starts on the right column.
885 [AT_KEYWORDS([m4@&t@_expand])
886 AT_CHECK([[$CONFIG_SHELL ./micro-suite |
887             sed -n '/^  1:/{
889 s/[^:]*: \(.*[^  ]\)[    ]*ok.*/\1/p
891 s/^.\{]]]m4_default($5, 53)[[[\}ok.*/ok/p
892 }']],,
893 [[$3
896 dnl This sed script checks for two things - that -v output doesn't have
897 dnl an empty $at_srcdir expansion, and that the 'testing ...' line
898 dnl contains the test group title.
899 AT_CHECK([[$CONFIG_SHELL ./micro-suite -v |
900             sed -n 's/.*testing \(.*\) \.\.\./\1/p; /^\/micro-suite\.at:/p']],,
901 [[$3
903 AT_CHECK([[$CONFIG_SHELL ./micro-suite -l |
904            sed -n 's/.*[0-9]: [^         ][^     ]*[     ][      ]*\(.*[^        ]\)[    ]*/\1/p']],,
905 [[$3
907 AT_CHECK([[sed -n 's/[^.]*\. \(.*\) ([^)]*): ok.*/\1/p' micro-suite.log]],,
908 [[$3
910 ])])
912 m4_define([AT_CHECK_AT_TITLE_CHAR],
913 [AT_CHECK_AT_TITLE([$1 in a test title], [A $2 in my name],
914                    [A ]m4_ifval([$3], [[$3]], [[$2]])[ in my name], $4, $5)])
916 AT_CHECK_AT_TITLE_CHAR([Backquote],     [`])
917 AT_CHECK_AT_TITLE_CHAR([Single-quote],  ['])
918 AT_CHECK_AT_TITLE_CHAR([Double-quote],  ["])
919 dnl restore font-lock: "
920 AT_CHECK_AT_TITLE_CHAR([Backslash],     [\])
921 AT_CHECK_AT_TITLE_CHAR([Brackets],   [[[]]], [[]])
922 AT_CHECK_AT_TITLE_CHAR([Left bracket],  [@<:@], [@<:@])
923 AT_CHECK_AT_TITLE_CHAR([Right bracket], [@:>@], [@:>@])
924 AT_CHECK_AT_TITLE_CHAR([Quoted pound],  [[#]], [#])
925 AT_CHECK_AT_TITLE_CHAR([Pound],         [#])
926 AT_CHECK_AT_TITLE_CHAR([Quoted comma],  [[,]], [,])
927 AT_CHECK_AT_TITLE_CHAR([Comma],         [,])
928 dnl this test also hits quadrigraphs for ()
929 AT_CHECK_AT_TITLE_CHAR([Parentheses],   [(@{:@)@:}@], [(())])
930 AT_CHECK_AT_TITLE_CHAR([Left paren],    [[(]], [(])
931 AT_CHECK_AT_TITLE_CHAR([Right paren],   [[)]], [)])
933 AT_CHECK_AT_TITLE_CHAR([Quoted Macro], [[macro_name]], [macro_name])
934 AT_CHECK_AT_TITLE_CHAR([Macro],        [macro_name],   [macro_expanded])
935 AT_CHECK_AT_TITLE_CHAR([Macro with backquote],       [macro_backquote], [`])
936 AT_CHECK_AT_TITLE_CHAR([Macro with single-quote], [macro_single_quote], ['])
937 AT_CHECK_AT_TITLE_CHAR([Macro with double-quote], [macro_double_quote], ["])
938 dnl restore font-lock: "
939 AT_CHECK_AT_TITLE_CHAR([Macro with backslash],       [macro_backslash], [\])
940 AT_CHECK_AT_TITLE_CHAR([Macro echoing macro], [macro_echo([macro_name])],
941                        [macro_expanded])
942 AT_CHECK_AT_TITLE_CHAR([Macro echoing single-quote], [macro_echo(['])], ['])
943 AT_CHECK_AT_TITLE_CHAR([Long test title], [0123456789012345678901234567890123])
944 AT_CHECK_AT_TITLE_CHAR([Longer test title],
945                        [01234567890123456789012345678901234], [], [], [54])
948 ## ----------------------- ##
949 ## Long test source lines. ##
950 ## ----------------------- ##
952 # Create a test file that has more than 99 words in a line, for Solaris awk.
953 # While at that, try out the limit of 2000 bytes in a text file line.
955 AT_CHECK_AT_TEST([Long test source lines],
956 [m4_for([nnn], [1], [999], [], [: ])
957 AT_CHECK([:])
958 ], [], [], [], [ignore], [],
959 [AT_CHECK([$CONFIG_SHELL ./micro-suite -k skipalltests], [], [ignore], [ignore])
963 ## ---------------- ##
964 ## Huge testsuite.  ##
965 ## ---------------- ##
967 # Ensure we don't hit line length limits with large test suites.
969 AT_CHECK_AT_TEST([Huge testsuite],
970 [m4_for([nnn], [1], [1999], [],
971 [AT_CLEANUP
972 AT_SETUP([test ]nnn)
974 ], [], [], [], [ignore], [], [], [1999])
977 ## ----------------- ##
978 ## Debugging a test. ##
979 ## ----------------- ##
981 AT_CHECK_AT_TEST([Debugging a successful test],
982   [AT_CHECK([:])], [], [], [], [ignore], [],
983 [# Without options, when all tests pass, no test directory should exist.
984 AT_CHECK([test -d micro-suite.dir/1 && exit 42
985           $CONFIG_SHELL ./micro-suite -d 1], [], [ignore], [ignore])
986 # Running with -d should leave a reproducible test group.
987 # Also, running the test script from the test group locks the
988 # directory from removal on some platforms; the script should still be
989 # able to run even if rmdir fails.
990 AT_CHECK([(cd micro-suite.dir/1 && ./run)], [], [ignore], [ignore])
991 # Running a debugging script implies -d.
992 AT_CHECK([(cd micro-suite.dir/1 && ./run)], [], [ignore], [ignore])
995 AT_CHECK_AT_TEST([Debugging script and environment],
996   [AT_CHECK([test "$MY_VAR" = pass || exit 42])],
997   [], [1], [], [ignore], [], [
998 # Changing environment outside of debugging script is not preserved.
999 AT_CHECK([(cd micro-suite.dir/1 && MY_VAR=pass ./run)],
1000          [0], [ignore], [ignore])
1001 AT_CHECK([(cd micro-suite.dir/1 && ./run)],
1002          [1], [ignore], [ignore])
1003 # Changing environment as argument to debugging script is preserved.
1004 AT_CHECK([(cd micro-suite.dir/1; ./run MY_VAR=pass)],
1005          [0], [ignore], [ignore])
1006 AT_CHECK([(cd micro-suite.dir/1; ./run)],
1007          [0], [ignore], [ignore])
1010 # The run script must still be valid when shell metacharacters are passed
1011 # in via an environment option.
1012 AT_CHECK_AT_TEST([Debugging a failed test],
1013   [AT_CHECK([test "$MY_VAR" = "one space" || exit 42])],
1014   [], [1], [], [ignore], [], [
1015 AT_CHECK([(cd micro-suite.dir/1 && ./run MY_VAR='two  spaces')],
1016          [1], [ignore], [ignore])
1017 AT_CHECK([(cd micro-suite.dir/1 && ./run MY_VAR='one space')],
1018          [0], [ignore], [ignore])
1022 # Setting default variable values via atlocal.
1023 AT_CHECK_AT_TEST([Using atlocal],
1024   [AT_CHECK([test "x$MY_VAR" = "xodd;  'string" || exit 42])],
1025   [], [1], [ignore], [ignore], [], [
1026 dnl check that command line can set variable
1027 AT_CHECK([$CONFIG_SHELL ./micro-suite MY_VAR="odd;  'string"], [0], [ignore])
1028 dnl check that command line overrides environment
1029 AT_CHECK([MY_VAR="odd;  'string" $CONFIG_SHELL ./micro-suite MY_VAR=unset],
1030          [1], [ignore], [ignore])
1031 dnl check that atlocal can give it a default
1032 AT_CHECK([cat <<EOF >atlocal
1033 MY_VAR="odd;  'string"
1034 export MY_VAR
1035 dnl Also populate enough of atlocal to do what atconfig normally does.
1036 at_testdir=.
1037 abs_builddir='`pwd`'
1038 at_srcdir=.
1039 abs_srcdir='`pwd`'
1040 at_top_srcdir=.
1041 abs_top_srcdir='`pwd`'
1042 at_top_build_prefix=
1043 abs_top_builddir='`pwd`'
1046 AT_CHECK([$CONFIG_SHELL ./micro-suite], [0], [ignore])
1047 dnl check that atlocal overrides environment
1048 AT_CHECK([MY_VAR=unset $CONFIG_SHELL ./micro-suite], [0], [ignore])
1049 dnl check that command line overrides atlocal
1050 AT_CHECK([$CONFIG_SHELL ./micro-suite MY_VAR=], [1], [ignore], [ignore])
1051 dnl check that syntax error is detected
1052 AT_CHECK([$CONFIG_SHELL ./micro-suite =], [1], [], [ignore], [ignore])
1053 AT_CHECK([$CONFIG_SHELL ./micro-suite 1=2], [1], [], [ignore], [ignore])
1057 # Controlling where the testsuite is run.
1058 AT_CHECK_AT_TEST([Choosing where testsuite is run],
1059   [AT_CHECK([:])], [], [], [], [], [], [
1060 dnl AT_CHECK_AT_TEST tests the default of running in '.'.
1061 AT_CHECK([$CONFIG_SHELL ./micro-suite --clean])
1062 AT_CHECK([test -f micro-suite.log], [1])
1063 AT_CHECK([test -d micro-suite.dir], [1])
1064 AT_CHECK([mkdir sub1 sub2])
1065 dnl check specifying a different relative path to run in.
1066 AT_CHECK([$CONFIG_SHELL ./micro-suite -C sub1], [0], [ignore], [])
1067 AT_CHECK([test -f micro-suite.log], [1])
1068 AT_CHECK([test -f sub1/micro-suite.log], [0])
1069 AT_CHECK([test -d micro-suite.dir], [1])
1070 AT_CHECK([test -d sub1/micro-suite.dir], [0])
1071 AT_CHECK([$CONFIG_SHELL ./micro-suite -C sub1 --clean])
1072 AT_CHECK([test -f sub1/micro-suite.log], [1])
1073 AT_CHECK([test -d sub1/micro-suite.dir], [1])
1074 dnl check specifying an absolute path to run in.
1075 AT_CHECK([$CONFIG_SHELL ./micro-suite --directory="`pwd`/sub2"],
1076          [0], [ignore], [])
1077 AT_CHECK([test -f micro-suite.log], [1])
1078 AT_CHECK([test -f sub2/micro-suite.log], [0])
1079 AT_CHECK([$CONFIG_SHELL ./micro-suite --clean --directory="`pwd`/sub2"])
1080 AT_CHECK([test -f sub2/micro-suite.log], [1])
1081 AT_CHECK([test -f sub2/micro-suite.dir], [1])
1082 dnl check for failure detection with bad, missing, or empty directory.
1083 AT_CHECK([$CONFIG_SHELL ./micro-suite -C nonesuch || exit 1], [1], [ignore], [ignore])
1084 AT_CHECK([$CONFIG_SHELL ./micro-suite -C ''], [1], [ignore], [ignore])
1085 AT_CHECK([$CONFIG_SHELL ./micro-suite -C - || exit 1], [1], [ignore], [ignore])
1086 AT_CHECK([$CONFIG_SHELL ./micro-suite -C], [1], [ignore], [ignore])
1087 dnl check that --help overrides bad directory selection.
1088 AT_CHECK([$CONFIG_SHELL ./micro-suite -C nonesuch --help], [0], [ignore], [])
1092 # --recheck.
1093 AT_CHECK_AT_TEST([recheck],
1094   [AT_CHECK([:])
1095    AT_CLEANUP
1096    AT_SETUP([failing test])
1097    AT_CHECK([exit 1])
1098    AT_CLEANUP
1099    AT_SETUP([xpassing test])
1100    AT_XFAIL_IF([:])
1101    AT_CHECK([:])
1102    AT_CLEANUP
1103    AT_SETUP([xfailing test])
1104    AT_XFAIL_IF([:])
1105    AT_CHECK([exit 1])
1106 ], [], [], [], [], [], [
1107 AT_CHECK([$CONFIG_SHELL ./micro-suite --recheck], [0], [stdout])
1108 AT_CHECK([grep "0 tests were successful" stdout], [0], [ignore])
1110 AT_CHECK([$CONFIG_SHELL ./micro-suite], [1], [ignore], [ignore])
1111 AT_CHECK([grep 'only test' micro-suite.log], [0], [ignore])
1112 AT_CHECK([$CONFIG_SHELL ./micro-suite --recheck], [1], [ignore], [ignore])
1113 AT_CHECK([grep 'only test' micro-suite.log], [1])
1114 AT_CHECK([grep 'xfailing' micro-suite.log], [1])
1115 AT_CHECK([grep 'failing test' micro-suite.log], [0], [ignore])
1116 AT_CHECK([grep 'xpassing test' micro-suite.log], [0], [ignore])
1118 AT_CHECK([$CONFIG_SHELL ./micro-suite --clean], [0])
1119 AT_CHECK([test -f micro-suite.log], [1])
1121 dnl check specifying a different relative path to run in.
1122 AT_CHECK([mkdir sub1])
1123 AT_CHECK([$CONFIG_SHELL ./micro-suite -C sub1], [1], [ignore], [ignore])
1124 AT_CHECK([test -f micro-suite.log], [1])
1125 AT_CHECK([test -f sub1/micro-suite.log], [0])
1126 AT_CHECK([$CONFIG_SHELL ./micro-suite -C sub1 --recheck --list], [0], [stdout])
1127 AT_CHECK([grep 'only test' stdout], [1])
1128 AT_CHECK([grep 'xfailing test' stdout], [1])
1129 AT_CHECK([grep 'failing test' stdout], [0], [ignore])
1130 AT_CHECK([grep 'xpassing test' stdout], [0], [ignore])
1131 AT_CHECK([$CONFIG_SHELL ./micro-suite -C sub1 --recheck], [1], [ignore],
1132          [ignore])
1133 AT_CHECK([grep 'failing test' sub1/micro-suite.log], [0], [ignore])
1134 AT_CHECK([grep 'xpassing test' sub1/micro-suite.log], [0], [ignore])
1135 ], [1 4])
1138 ## -------- ##
1139 ## Banners. ##
1140 ## -------- ##
1141 AT_SETUP([Banners])
1143 AT_CHECK_AT_PREP([b],
1144 [[AT_INIT
1145 AT_SETUP(zero)# 1
1146 AT_CHECK(:)
1147 AT_CLEANUP
1149 AT_BANNER([first])
1150 AT_SETUP(one a)# 2
1151 AT_CHECK(:)
1152 AT_CLEANUP
1153 AT_SETUP(one b)# 3
1154 AT_CHECK(:)
1155 AT_CLEANUP
1157 AT_BANNER()
1158 AT_SETUP(two a)# 4
1159 AT_CHECK(:)
1160 AT_CLEANUP
1161 AT_SETUP(two b)# 5
1162 AT_CHECK(:)
1163 AT_CLEANUP
1165 AT_BANNER([second])
1166 AT_SETUP(three a)# 6
1167 AT_CHECK(:)
1168 AT_CLEANUP
1169 AT_SETUP(three b)# 7
1170 AT_CHECK(:)
1171 AT_CLEANUP
1174 # AT_CHECK_BANNERS(TESTSUITE-OPTIONS, PATTERN1, COUNT1, PATTERN2, COUNT2)
1175 m4_define([AT_CHECK_BANNERS],
1176 [AT_CHECK([$CONFIG_SHELL ./b $1], [], [stdout])
1177 AT_CHECK_EGREP([$2], m4_if([$3], [0], [1], [0]), [$3])
1178 AT_CHECK_EGREP([$4], m4_if([$5], [0], [1], [0]), [$5])
1181 AT_CHECK_BANNERS([],            [first], [1], [second], [1])
1182 AT_CHECK_BANNERS([-k zero],     [first], [0], [second], [0])
1183 AT_CHECK_BANNERS([1],           [first], [0], [second], [0])
1184 AT_CHECK_BANNERS([-2],          [first], [1], [second], [0])
1185 AT_CHECK_BANNERS([-3],          [first], [1], [second], [0])
1186 AT_CHECK_BANNERS([-k one],      [first], [1], [second], [0])
1187 AT_CHECK_BANNERS([3-4],         [first], [1], [second], [0])
1188 dnl There should be an empty line separating the first category from the
1189 dnl unnamed one.
1190 AT_CHECK([sed -n '/one b/,/two a/p' stdout | grep '^$'], [0], [ignore])
1191 AT_CHECK_BANNERS([3-6],         [first], [1], [second], [1])
1192 AT_CHECK_BANNERS([4-6],         [first], [0], [second], [1])
1193 AT_CHECK_BANNERS([3-],          [first], [1], [second], [1])
1194 AT_CHECK_BANNERS([-k a],        [first], [1], [second], [1])
1195 AT_CHECK_BANNERS([4],           [first], [0], [second], [0])
1196 AT_CHECK_BANNERS([4-],          [first], [0], [second], [1])
1197 AT_CHECK_BANNERS([-k two],      [first], [0], [second], [0])
1198 AT_CHECK_BANNERS([1 4],         [first], [0], [second], [0])
1199 AT_CHECK_BANNERS([-k three],    [first], [0], [second], [1])
1200 AT_CHECK_BANNERS([5],           [first], [0], [second], [0])
1201 AT_CHECK_BANNERS([5-],          [first], [0], [second], [1])
1202 AT_CLEANUP
1205 ## --------- ##
1206 ## Keywords. ##
1207 ## --------- ##
1208 AT_SETUP([Keywords and ranges])
1210 AT_CHECK_AT_PREP([k],
1211 [[AT_INIT
1212 AT_SETUP(none) # 01
1213 AT_CHECK(:)
1214 AT_CLEANUP
1215 AT_SETUP(first) # 02
1216 AT_KEYWORDS(key1)
1217 AT_CHECK(:)
1218 AT_CLEANUP
1219 AT_SETUP(second) # 03
1220 AT_KEYWORDS(key2)
1221 AT_CHECK(:)
1222 AT_CLEANUP
1223 AT_SETUP(both) # 04
1224 AT_KEYWORDS([key1 key2])
1225 AT_KEYWORDS([m4_echo([Key1])])
1226 AT_CHECK(:)
1227 AT_CLEANUP
1228 AT_SETUP(test5) # 05
1229 AT_CHECK(:)
1230 AT_CLEANUP
1231 AT_SETUP(test6) # 06
1232 AT_CHECK(:)
1233 AT_CLEANUP
1234 AT_SETUP(test7) # 07
1235 AT_CHECK(:)
1236 AT_CLEANUP
1237 AT_SETUP(test8) # 08
1238 AT_CHECK(:)
1239 AT_CLEANUP
1240 AT_SETUP(test9) # 09
1241 AT_CHECK(:)
1242 AT_CLEANUP
1243 AT_SETUP(test10) # 10
1244 AT_CHECK(:)
1245 AT_CLEANUP
1247 dnl check that AT_KEYWORDS does not duplicate words
1248 AT_CHECK([grep -i 'key1.*key1' k], [1])
1249 dnl check that -k requires an argument
1250 AT_CHECK([$CONFIG_SHELL ./k -k], [1], [], [ignore])
1252 # AT_CHECK_KEYS(TESTSUITE-OPTIONS, PATTERN1, COUNT1, PATTERN2, COUNT2)
1253 m4_define([AT_CHECK_KEYS],
1254 [AT_CHECK([$CONFIG_SHELL ./k $1], 0, [stdout])
1255 AT_CHECK_EGREP([$2], 0, [$3])
1256 AT_CHECK_EGREP([$4], 1, [$5])
1259 AT_CHECK_KEYS([-k key1], [first|both], [2], [none|second], [0])
1260 AT_CHECK_KEYS([-k key2], [second|both], [2], [none|first], [0])
1261 AT_CHECK_KEYS([-k key1,key2], [both], [1], [none|first|second], [0])
1262 AT_CHECK_KEYS([-k key1 -k key2], [first|second|both], [3], [none], [0])
1263 AT_CHECK_KEYS([-k '!key1'], [none|second], [2], [first|both], [0])
1264 AT_CHECK_KEYS([-k '!key2'], [none|first], [2], [second|both], [0])
1265 AT_CHECK_KEYS([-k '!key1,key2'], [second], [1], [none|first|both], [0])
1266 AT_CHECK_KEYS([-k 'key1,!key2'], [first], [1], [none|second|both], [0])
1267 AT_CHECK_KEYS([-k '!key1,!key2'], [none], [1], [first|second|both], [0])
1268 AT_CHECK_KEYS([-k '!key1' -k KEY2], [none|second|both], [3], [first], [0])
1269 AT_CHECK_KEYS([-k key1 -k '!key2'], [none|first|both], [3], [second], [0])
1270 AT_CHECK_KEYS([-k '!KEY1' -k '!key2'], [none|first|second], [3], [both], [0])
1272 AT_CHECK_KEYS([-k none], [none], [1], [first|second|both], [0])
1273 AT_CHECK_KEYS([-k key1,both], [both], [1], [none|first|second], [0])
1274 AT_CHECK_KEYS([-k key1 -k both], [first|both], [2], [none|second], [0])
1275 AT_CHECK_KEYS([-k none,first], [successful], [1], [none|first|second|both], [0])
1276 AT_CHECK_KEYS([-k none,first,second,both], [successful], [1], [none|first|second|both], [0])
1277 AT_CHECK_KEYS([-k !none,first], [first], [1], [none|second|both], [0])
1279 AT_CHECK_KEYS([-k '.*eco.*'], [second], [1], [none|first|both], [0])
1280 AT_CHECK_KEYS([-k 'ECO'], [successful], [1], [none|first|second|both], [0])
1281 AT_CHECK_KEYS([-k '.*eco'], [successful], [1], [none|first|second|both], [0])
1282 AT_CHECK_KEYS([-k 'eco.*'], [successful], [1], [none|first|second|both], [0])
1283 AT_CHECK_KEYS([-k 'fir.*'], [first], [1], [none|second|both], [0])
1285 AT_CHECK_KEYS([1-2], [none|first], [2], [second|both], [0])
1286 AT_CHECK_KEYS([01-002 08], [none|first], [2], [second|both], [0])
1287 AT_CHECK_KEYS([1-3 2-1], [none|first|second], [3], [both], [0])
1288 AT_CHECK_KEYS([-3], [none|first|second], [3], [both], [0])
1289 AT_CHECK_KEYS([4-], [both], [1], [none|first|second], [0])
1290 AT_CHECK_KEYS([010], [test10], [1], [none|first|second|both], [0])
1291 AT_CHECK_KEYS([-k second 4-], [second|both], [2], [none|first], [0])
1293 AT_CHECK([$CONFIG_SHELL ./k 0], [1], [ignore], [ignore])
1294 AT_CHECK([$CONFIG_SHELL ./k 0-], [1], [ignore], [ignore])
1295 AT_CHECK([$CONFIG_SHELL ./k -0], [1], [ignore], [ignore])
1296 AT_CHECK([$CONFIG_SHELL ./k 11], [1], [ignore], [ignore])
1297 AT_CHECK([$CONFIG_SHELL ./k 11-], [1], [ignore], [ignore])
1298 AT_CHECK([$CONFIG_SHELL ./k 1-011], [1], [ignore], [ignore])
1299 AT_CHECK([$CONFIG_SHELL ./k -k nonexistent], [0], [ignore])
1301 AT_CHECK_KEYS([--list -k nonexistent], [KEYWORDS], [1], [first|second|both], [0])
1302 AT_CHECK_KEYS([--list 1], [none], [1], [first|second|both], [0])
1303 AT_CHECK_KEYS([--list 01], [none], [1], [first|second|both], [0])
1304 AT_CHECK_KEYS([--list -k none -k first], [none|first], [2], [second|both], [0])
1305 AT_CLEANUP
1308 ## ----------------- ##
1309 ## Keyword wrapping. ##
1310 ## ----------------- ##
1311 AT_SETUP([Keyword wrapping])
1313 AT_CHECK_AT_PREP([k],
1314 [[AT_INIT
1315 AT_SETUP([test])
1316 AT_KEYWORDS([a1 b1 c1 d1 e1 f1 g1 h1 i1 j1 k1 l1 m1 n1 o1 p1 q1 r1 s1 t1])
1317 AT_KEYWORDS([u1 v1 w1 x1 y1 z1])
1318 AT_KEYWORDS([a b c d e f g h i j k l m n o p q r s t u v w x y z])
1319 AT_CLEANUP
1320 AT_SETUP([test with long keywords])
1321 AT_KEYWORDS(
1322 [this-is-a-long-keyword-that-cannot-be-wrapped-so-we-exceed-the-length-limit-here])
1323 # surrounded by short ones
1324 AT_KEYWORDS([s])
1325 AT_KEYWORDS(
1326 [another-very-long-keyword-that-hits-the-line-length-limit-bla-bla-bla-bla])
1327 AT_KEYWORDS([t])
1328 AT_CLEANUP
1331 AT_CHECK_KEYS([-l], [.{80}], [1], [.{87}], [0])
1333 AT_CLEANUP
1336 ## ------------- ##
1337 ## AT_ARG_OPTION ##
1338 ## ------------- ##
1340 AT_CHECK_AT([AT@&t@_ARG_OPTION],
1342 AT_INIT([artificial test suite])
1343 AT_ARG_OPTION([frob fro fr f],
1344               [AS_HELP_STRING([-f, --frob], [frobnicate the test run])],
1345               [frob=$at_optarg], [frob=default])
1346 AT_ARG_OPTION([opt-with-hyphen],
1347               [AS_HELP_STRING([--opt-with-hyphen], [option name with hypen])])
1348 AT_ARG_OPTION([ping],
1349               [AS_HELP_STRING([--ping], [ping on every encounter])],
1350               [echo ping])
1351 AT_SETUP([test argument handling])
1352 AT_CHECK([test "$frob" = "$FROB"])
1353 AT_CHECK([test "$at_arg_frob" = "$FROB_ARG"])
1354 AT_CLEANUP
1355 AT_SETUP([test hyphen normalization])
1356 AT_CHECK([test "$at_arg_opt_with_hyphen" = "$expected"])
1357 AT_CLEANUP
1359 [], [], [stdout], [], [],
1360 [# We already invoked --help.
1361 AT_CHECK([grep '  -f, --frob.*frobnicate' stdout], [], [ignore])
1362 for args in \
1363   '1 FROB=default FROB_ARG=false' \
1364   '1 -f FROB=: FROB_ARG=:' \
1365   '1 --fr FROB=: FROB_ARG=:' \
1366   '1 --fro FROB=: FROB_ARG=:' \
1367   '1 --frob FROB=: FROB_ARG=:' \
1368   '1 --no-f FROB=false FROB_ARG=false' \
1369   '1 --no-fr FROB=false FROB_ARG=false' \
1370   '1 --no-fro FROB=false FROB_ARG=false' \
1371   '1 --no-frob FROB=false FROB_ARG=false' \
1372   '2 expected=false' \
1373   '2 --opt-with-hyphen expected=:' \
1374   '2 --no-opt-with-hyphen expected=false'
1376   AT_CHECK([$CONFIG_SHELL ./micro-suite -x $args], [], [ignore])
1377 done
1378 AT_CHECK([$CONFIG_SHELL ./micro-suite 2 --ping --no-ping --ping expected=false],
1379          [], [stdout])
1380 AT_CHECK([grep -c ping stdout], [], [[3
1382 ], [--help])
1385 ## ----------------- ##
1386 ## AT_ARG_OPTION_ARG ##
1387 ## ----------------- ##
1389 AT_CHECK_AT([AT@&t@_ARG_OPTION_ARG],
1391 AT_INIT([artificial test suite])
1392 AT_ARG_OPTION_ARG([frob fro fr f],
1393                   [AS_HELP_STRING([-f, --frob=FOO], [frobnicate FOO])],
1394                   [frob=$at_optarg], [frob=default])
1395 AT_ARG_OPTION_ARG([opt-with-hyphen],
1396                   [AS_HELP_STRING([--opt-with-hyphen=ARG],
1397                                   [option name with hypen])])
1398 AT_ARG_OPTION_ARG([ping],
1399                   [AS_HELP_STRING([--ping], [ping on every encounter])],
1400                   [echo ping])
1401 AT_SETUP([test argument handling])
1402 AT_CHECK([test "$frob" = "$FROB"])
1403 AT_CHECK([test "$at_arg_frob" = "$FROB_ARG"])
1404 AT_CLEANUP
1405 AT_SETUP([test hyphen normalization])
1406 AT_CHECK([test "$at_arg_opt_with_hyphen" = "$expected"])
1407 AT_CLEANUP
1409 [], [], [stdout], [], [],
1410 [# We already invoked --help.
1411 AT_CHECK([grep '  -f, --frob.*frobnicate' stdout], [], [ignore])
1412 AT_CHECK([$CONFIG_SHELL ./micro-suite -x --frob], [1], [ignore], [stderr])
1413 AT_CHECK([grep 'requires an argument' stderr], [], [ignore])
1414 AT_CHECK([$CONFIG_SHELL ./micro-suite -x --no-frob], [1], [ignore], [stderr])
1415 AT_CHECK([grep 'invalid option' stderr], [], [ignore])
1416 for args in \
1417   '1 FROB=default FROB_ARG=' \
1418   '1 -f bar FROB=bar FROB_ARG=bar' \
1419   '1 --fr bar FROB=bar FROB_ARG=bar' \
1420   '1 --fro bar FROB=bar FROB_ARG=bar' \
1421   '1 --frob bar FROB=bar FROB_ARG=bar' \
1422   '1 -f=bar FROB=bar FROB_ARG=bar' \
1423   '1 --fr=bar FROB=bar FROB_ARG=bar' \
1424   '1 --fro=bar FROB=bar FROB_ARG=bar' \
1425   '1 --frob=bar FROB=bar FROB_ARG=bar' \
1426   '2 expected=' \
1427   '2 --opt-with-hyphen=baz expected=baz'
1429   AT_CHECK([$CONFIG_SHELL ./micro-suite -x $args], [], [ignore])
1430 done
1431 AT_CHECK([$CONFIG_SHELL ./micro-suite 2 --ping=1 --ping=2 expected=],
1432          [], [stdout])
1433 AT_CHECK([grep -c ping stdout], [], [[2
1435 ], [--help])
1438 m4_define([AT_SKIP_PARALLEL_TESTS],
1439 [# Per BUGS, we have not yet figured out how to run parallel tests cleanly
1440 # under dash and some ksh variants.  For now, only run this test under
1441 # limited conditions; help is appreciated in widening this test base.
1442 AT_SKIP_IF([${CONFIG_SHELL-$SHELL} -c 'test -z "${BASH_VERSION+set}]]dnl
1443 [[${ZSH_VERSION+set}${TEST_PARALLEL_AUTOTEST+set}"'])
1444 # The parallel scheduler requires mkfifo and job control to work.
1445 AT_CHECK([mkfifo fifo || exit 77])
1446 AT_CHECK([${CONFIG_SHELL-$SHELL} -c '(set -m && set +m) || exit 77'],
1447          [], [], [ignore])
1448 # Parallel tests malfunction with Guix's bash, as of this writing
1449 # (bash 5.1.8(1)-release, guix 9584b1d 2023-03-12).  I haven't been
1450 # able to figure out why.
1451 # It is *probably* safe to assume that if the shell is Bash and /gnu/store
1452 # exists, then we also have realpath and $(...).
1453 AT_SKIP_IF(
1454   [${CONFIG_SHELL-$SHELL} -c 'test "${BASH_VERSION+set}" = set' &&
1455    test -d /gnu/store &&
1456    test "$(realpath "${CONFIG_SHELL-$SHELL}" | cut -c-10)" = /gnu/store])
1459 ## ----------------------- ##
1460 ## parallel test execution ##
1461 ## ----------------------- ##
1463 AT_SETUP([parallel test execution])
1465 # This test tries to ensure that -j runs tests in parallel.
1466 # Such a test is inherently racy, because there are no real-time
1467 # guarantees about scheduling delays.  So we try to minimize
1468 # the chance to lose the race.
1470 # The time needed for a micro-suite consisting of NTESTS tests each
1471 # sleeping for a second is estimated by
1472 #   startup + ntests * (serial_overhead + 1 / njobs)
1474 # in absence of major scheduling delays.  This leads to side conditions:
1475 # - NTESTS should be high, so the STARTUP time is small compared to the
1476 #   test run time, and scheduling delays can even out; it should not be
1477 #   too high, to not slow down the testsuite unnecessarily,
1478 # - the number of concurrent jobs NJOBS should not be too low, so the
1479 #   race is not lost so easily; it should not be too high, to avoid fork
1480 #   failures on tightly limited systems.  4 seems a good compromise
1481 #   here, considering that Autotest spawns several other processes.
1482 # - STARTUP is assumed to be the same for parallel and serial runs, so
1483 #   the latter can estimate the former.
1484 # - To avoid unportable output from time measurement commands, spawn
1485 #   both a parallel and a serial testsuite run; check that the former
1486 #   completes before the latter has completed a fraction SERIAL_NTESTS
1487 #   of the tests (the serial run is executed in a subdirectory), plus
1488 #   some additional time to allow for compensation of SERIAL_OVERHEAD.
1489 # - when adding this time to the serial test execution, an initial delay
1490 #   SERIAL_DELAY of the serial test helps to avoid unreliable scheduling
1491 #   due to the startup burst of the suites.
1493 dnl total number of tests.
1494 m4_define([AT_PARALLEL_NTESTS], [16])
1495 dnl number of jobs to run in parallel.
1496 m4_define([AT_PARALLEL_NJOBS], [4])
1497 dnl number of tests to run serially, as comparison.
1498 m4_define([AT_PARALLEL_SERIAL_NTESTS],
1499   m4_eval(AT_PARALLEL_NTESTS / AT_PARALLEL_NJOBS))
1500 dnl initial delay of serial run, to compensate for SERIAL_OVERHEAD.
1501 dnl This corresponds to 0.67 s of overhead per test.
1502 m4_define([AT_PARALLEL_SERIAL_DELAY],
1503   m4_eval((AT_PARALLEL_NTESTS - AT_PARALLEL_SERIAL_NTESTS + 1) * 2 / 3))
1506 AT_CHECK_AT_PREP([micro-suite],
1507 [[AT_INIT([suite to test parallel execution])
1508 m4_for([count], [1], ]]AT_PARALLEL_NTESTS[[, [],
1509    [AT_SETUP([test number count])
1510     AT_CHECK([sleep 1])
1511     AT_CLEANUP
1515 # Even if parallel jobs are not supported, the command line must work.
1516 AT_CHECK([$CONFIG_SHELL ./micro-suite --help | grep " --jobs"], [0], [ignore])
1517 AT_CHECK([$CONFIG_SHELL ./micro-suite -j2foo], [1], [], [stderr])
1518 AT_CHECK([grep 'non-numeric argument' stderr], [], [ignore])
1519 AT_CHECK([$CONFIG_SHELL ./micro-suite --jobs=foo], [1], [], [stderr])
1520 AT_CHECK([grep 'non-numeric argument' stderr], [], [ignore])
1522 AT_SKIP_PARALLEL_TESTS
1524 # The parallel test driver makes some shells generate internal
1525 # debugging messages on stderr (notably bash 5.x in compile-time
1526 # development mode, see
1527 # https://lists.gnu.org/archive/html/bug-autoconf/2020-10/msg00047.html)
1528 # so ignore stderr in all invocations below.
1530 # Ensure that all tests run, and lines are not split.
1531 AT_CHECK([$CONFIG_SHELL ./micro-suite -j[]AT_PARALLEL_NJOBS],
1532          [], [stdout], [ignore])
1533 AT_CHECK([grep -c '^.\{53\}ok' stdout], [], [AT_PARALLEL_NTESTS
1535 # Running one test with -j should produce correctly formatted output:
1536 AT_CHECK([$CONFIG_SHELL ./micro-suite -j 3], [], [stdout], [ignore])
1537 AT_CHECK([grep -c '^.\{53\}ok' stdout], [], [1
1539 # Specifying more jobs than tests should not hang:
1540 AT_CHECK([$CONFIG_SHELL ./micro-suite -j3 3], [], [stdout], [ignore])
1541 AT_CHECK([grep -c '^.\{53\}ok' stdout], [], [1
1543 # Not even with zero tests:
1544 AT_CHECK([$CONFIG_SHELL ./micro-suite -j -k nomatch], [], [ignore])
1545 AT_CHECK([$CONFIG_SHELL ./micro-suite -j3 -k nomatch], [], [ignore])
1547 mkdir serial
1549 # Unfortunately, the return value of wait is unreliable,
1550 # so we check that kill fails.
1551 AT_CHECK([$CONFIG_SHELL ./micro-suite --jobs=[]AT_PARALLEL_NJOBS & ]dnl
1552          [sleep AT_PARALLEL_SERIAL_DELAY && ]dnl
1553          [cd serial && $CONFIG_SHELL ../micro-suite -AT_PARALLEL_SERIAL_NTESTS >/dev/null && ]dnl
1554          [{ kill $! && exit 1; :; }], [], [stdout], [ignore])
1555 AT_CHECK([grep -c '^.\{53\}ok' stdout], [], [AT_PARALLEL_NTESTS
1557 AT_CHECK([grep 'AT_PARALLEL_NTESTS tests' stdout], [], [ignore])
1559 AT_CLEANUP
1561 # stderr is ignored in the next several tests because the parallel
1562 # driver makes some shells emit internal debugging messages, see
1563 # https://lists.gnu.org/archive/html/bug-autoconf/2020-10/msg00047.html
1565 AT_CHECK_AT_TEST([parallel truth],
1566   [AT_CHECK([:], 0, [], [])],
1567   [], [], [], [ignore], [AT_SKIP_PARALLEL_TESTS],
1568   [], [-j])
1570 AT_CHECK_AT_TEST([parallel fallacy],
1571   [AT_CHECK([false], [], [], [])],
1572   [], [1], [], [ignore], [AT_SKIP_PARALLEL_TESTS],
1573   [AT_CHECK([grep failed micro-suite.log], [], [ignore])], [-j])
1575 AT_CHECK_AT_TEST([parallel skip],
1576   [AT_CHECK([echo output; echo irrelevant >&2; exit 77], 0, [mismatch], [])],
1577   [], [], [], [ignore], [AT_SKIP_PARALLEL_TESTS],
1578   [AT_CHECK([grep skipped micro-suite.log], [], [ignore])], [-j])
1580 AT_CHECK_AT_TEST([parallel syntax error],
1581   [AT_CHECK([:])
1582    AT_CLEANUP
1583    AT_SETUP([syntax])
1584    AT_CHECK([if])
1585    AT_CLEANUP
1586    AT_SETUP([another test])
1587    AT_CHECK([:])],
1588   [], [0], [], [ignore], [AT_SKIP_PARALLEL_TESTS],
1589   [dnl Until we can find a way to avoid catastrophic failure (ash) or
1590    dnl lack of failure (zsh), skip the rest of this test on such shells.
1591    echo 'if' > syntax
1592    AT_CHECK([${CONFIG_SHELL-$SHELL} -c 'case `. ./syntax; echo $?` in
1593                   0|"") exit 77;;
1594                 esac'], [0], [ignore], [ignore])
1595    AT_CHECK([${CONFIG_SHELL-$SHELL} ./micro-suite -j], [1], [ignore], [stderr])
1596    AT_CHECK([grep "unable to parse test group: 2" stderr], [0], [ignore])],
1597   [-j2 1 3])
1599 AT_CHECK_AT_TEST([parallel errexit],
1600   [AT_CHECK([false])
1601    AT_CLEANUP
1602    AT_SETUP([barrier test])
1603    AT_CHECK([sleep 4])
1604    AT_CLEANUP
1605    AT_SETUP([test that should not be run])
1606    AT_CHECK([:])],
1607   [], [1], [stdout], [stderr], [AT_SKIP_PARALLEL_TESTS],
1608   [AT_CHECK([test -f micro-suite.log], [1])
1609    touch micro-suite.log # shut up AT_CAPTURE_FILE.
1610    AT_CHECK([grep "should not be run" stdout], [1])
1611    AT_CHECK([grep "[[12]] .* inhibited subsequent" stderr], [], [ignore])],
1612   [-j2 --errexit])
1615 AT_SETUP([parallel autotest and signal handling])
1617 AT_SKIP_PARALLEL_TESTS
1619 # Goals:
1620 # (1) interrupt './testsuite -jN'
1621 # (2) interrupt 'make check TESTSUITEFLAGS=-jN'
1622 # (3) no trailing verbose/trace output
1623 # (4) exit status should be 128+signal
1625 AT_DATA([atlocal],
1626 [[suite_pid=$$
1627 export suite_pid
1630 AT_CHECK_AT_PREP([micro-suite],
1631 [[AT_INIT([suite to test parallel execution])
1632 AT_SETUP([test number 1])
1633 AT_CHECK([sleep 2])
1634 AT_CLEANUP
1635 AT_SETUP([test number 2])
1636 AT_CHECK([sleep 1])
1637 AT_CLEANUP
1638 AT_SETUP([test number 3])
1639 AT_CHECK([sleep 1])
1640 AT_CLEANUP
1641 AT_SETUP([killer test])
1642 AT_CHECK([kill -$signal $suite_pid])
1643 AT_CLEANUP
1644 m4_for([count], [5], [7], [],
1645    [AT_SETUP([test number count])
1646     AT_CHECK([sleep 1])
1647     AT_CLEANUP
1651 AT_DATA([Makefile.in],
1652 [[@SET_MAKE@
1653 SHELL = @SHELL@
1654 TESTSUITE = ./micro-suite
1655 check:
1656         $(SHELL) '$(TESTSUITE)' $(TESTSUITEFLAGS)
1657 .PHONY: check
1660 AT_CHECK([$CONFIG_SHELL $abs_top_builddir/config.status --file=Makefile:Makefile.in],
1661          [], [ignore])
1663 # Test INT and TERM.
1664 for signal in 2 15; do
1665   export signal
1666   AS_VAR_ARITH([expected_status], [128 + $signal])
1668   # Sequential case.
1669   AT_CHECK([$CONFIG_SHELL ./micro-suite], [$expected_status],
1670            [ignore], [stderr])
1671   # Both stderr and the log should contain the notification about the signal.
1672   AT_CHECK([grep 'bailing out' stderr], [], [ignore])
1673   AT_CHECK([grep 'bailing out' micro-suite.log], [], [ignore])
1674   # There should be no junk job status output.
1675   AT_CHECK([[grep '[iI]nterrupt[         ]' stderr]], [1])
1677   # Parallel case.
1678   AT_CHECK([$CONFIG_SHELL ./micro-suite --jobs=3], [$expected_status],
1679            [ignore], [stderr])
1680   AT_CHECK([grep 'bailing out' stderr], [], [ignore])
1681   AT_CHECK([grep 'bailing out' micro-suite.log], [], [ignore])
1682   # We'd like to check this here, too, but some shells do not allow to
1683   # turn off job control.
1684   # AT_CHECK([[grep '[iI]nterrupt[       ]' stderr]], [1])
1686   # Ditto with 'make' in the loop.
1687   # Explicitly setting TESTSUITEFLAGS to empty...
1688   AT_CHECK_MAKE([TESTSUITEFLAGS=], [], [1], [ignore], [stderr])
1689   AT_CHECK([grep 'bailing out' stderr], [], [ignore])
1690   AT_CHECK([grep 'bailing out' micro-suite.log], [], [ignore])
1692   # ... and explicitly requesting 3-fold parallelism.
1693   AT_CHECK_MAKE([TESTSUITEFLAGS=--jobs=3], [], [1], [ignore], [stderr])
1694   AT_CHECK([grep 'bailing out' stderr], [], [ignore])
1695   AT_CHECK([grep 'bailing out' micro-suite.log], [], [ignore])
1696 done
1699 # Test PIPE.
1700 # The most important part here is that things should not hang, nor
1701 # get out of hand.  OTOH, if the shell sets the default handler to
1702 # ignore PIPE (pdksh, dash), there is little we can do about having the
1703 # test run; it's only the output that won't be there.  So all we check
1704 # for is that, if test 7 didn't run serially, then it shouldn't be
1705 # run in the parallel case either; the intermediate tests serve as
1706 # parallel barrier.
1707 # Note that stderr may contain "Broken pipe" errors.
1708 AT_CHECK([($CONFIG_SHELL ./micro-suite -d -3 5-; echo $? >status) | sed 5q],
1709          [], [stdout], [stderr])
1710 AT_CHECK([grep '5.*ok' stdout], [1])
1711 # Apparently some shells don't get around to creating 'status' any more.
1712 # And ksh93 on FreeBSD uses 256 + 13 instead of 128 + 13
1713 AT_CHECK([test ! -s status || grep 141 status || grep 269 status || grep ^0 status ],
1714          [], [ignore])
1715 AT_CHECK([if test -f micro-suite.dir/7/micro-suite.log; then ]dnl
1716          [  echo "shell ignores SIGPIPE" > sigpipe-stamp ]dnl
1717          [else :; fi])
1719 AT_CHECK([$CONFIG_SHELL ./micro-suite -d -3 5- --jobs=2 | sed 5q], [], [stdout], [ignore])
1720 AT_CHECK([grep '5.*ok' stdout], [1])
1721 AT_CHECK([test -s sigpipe-stamp || test ! -f micro-suite.dir/7/micro-suite.log], [0])
1723 AT_CLEANUP
1726 # Avoid running into a regression when mkfifo does not work.
1727 AT_CHECK_AT_TEST([parallel args but non-working mkfifo],
1728 [AT_CHECK([:])
1729 AT_CLEANUP
1730 AT_SETUP([second test])
1731 AT_CHECK([:])
1733 [], [], [stdout], [stderr],
1734 [AT_SKIP_PARALLEL_TESTS
1735 mkdir bin
1736 cat >bin/mkfifo <<\EOF
1737 #! /bin/sh
1738 exit 1
1740 chmod +x bin/mkfifo
1741 PATH=`pwd`/bin:$PATH
1742 export PATH
1744 [AT_CHECK([grep 'second test' stdout], [], [ignore])
1745 ], [--jobs])
1748 # --color
1749 AT_CHECK_AT_TEST([colored test results],
1750   [AT_CHECK([:])
1751    AT_CLEANUP
1752    AT_SETUP([fail])
1753    AT_CHECK([exit 1])
1754    AT_CLEANUP
1755    AT_SETUP([xpass])
1756    AT_XFAIL_IF([:])
1757    AT_CHECK([:])
1758    AT_CLEANUP
1759    AT_SETUP([xfail])
1760    AT_XFAIL_IF([:])
1761    AT_CHECK([exit 1])
1762    AT_CLEANUP
1763    AT_SETUP([skip])
1764    AT_CHECK([exit 77])
1765    AT_CLEANUP
1766    AT_SETUP([hardfail])
1767    AT_XFAIL_IF([:])
1768    AT_CHECK([exit 99])
1769 ], [], [], [], [], [], [
1771 TERM=ansi
1772 export TERM
1774 red=`printf '\033@<:@0;31m'`
1775 grn=`printf '\033@<:@0;32m'`
1776 lgn=`printf '\033@<:@1;32m'`
1777 blu=`printf '\033@<:@1;34m'`
1778 std=`printf '\033@<:@m'`
1780 # Check that grep can parse nonprinting characters.
1781 # BSD 'grep' works from a pipe, but not a seekable file.
1782 # GNU or BSD 'grep -a' works on files, but is not portable.
1783 AT_CHECK([case `echo "$std" | grep .` in #'' restore font-lock
1784             $std) :;;
1785             *) exit 77;;
1786           esac], [], [ignore], [],
1787          [echo "grep can't parse nonprinting characters" >&2])
1789 if echo 'ab*c' | grep -F 'ab*c' >/dev/null 2>&1; then
1790   FGREP="grep -F"
1791 else
1792   FGREP=fgrep
1795 # No color.
1796 AT_CHECK([$CONFIG_SHELL ./micro-suite], [1], [stdout], [stderr])
1797 for color in "$red" "$grn" "$lgn" "$blu"; do
1798   AT_CHECK([cat stdout stderr | $FGREP "$color"], [1])
1799 done
1801 # Color of test group results.
1802 AT_CHECK([$CONFIG_SHELL ./micro-suite --color=always], [1], [stdout], [stderr])
1803 AT_CHECK([cat stdout | grep " only " | $FGREP "$grn"], [], [ignore])
1804 AT_CHECK([cat stdout | grep " fail " | $FGREP "$red"], [], [ignore])
1805 AT_CHECK([cat stdout | grep " xfail " | $FGREP "$lgn"], [], [ignore])
1806 AT_CHECK([cat stdout | grep " xpass " | $FGREP "$red"], [], [ignore])
1807 AT_CHECK([cat stdout | grep " skip " | $FGREP "$blu"], [], [ignore])
1808 AT_CHECK([cat stdout | grep " hardfail " | $FGREP "$red"], [], [ignore])
1809 AT_CHECK([cat stderr | grep ERROR | $FGREP "$red"], [], [ignore])
1811 # The summary is green if all tests were successful, light green if all
1812 # behaved as expected, and red otherwise.
1813 AT_CHECK([$CONFIG_SHELL ./micro-suite --color=always 1 -k skip],
1814          [0], [stdout])
1815 AT_CHECK([cat stdout | grep 'test.*successful' | $FGREP "$grn"],
1816          [], [ignore])
1817 AT_CHECK([$CONFIG_SHELL ./micro-suite --color=always 1 -k xfail -k skip],
1818          [0], [stdout])
1819 AT_CHECK([cat stdout | grep 'as expected' | $FGREP "$lgn"], [], [ignore])
1820 AT_CHECK([$CONFIG_SHELL ./micro-suite --color=always -k fail],
1821          [1], [ignore], [stderr])
1822 AT_CHECK([cat stderr | grep ERROR | $FGREP "$red"], [], [ignore])
1823 AT_CHECK([$CONFIG_SHELL ./micro-suite --color=always -k xpass],
1824          [1], [ignore], [stderr])
1825 AT_CHECK([cat stderr | grep ERROR | $FGREP "$red"], [], [ignore])
1826 AT_CHECK([$CONFIG_SHELL ./micro-suite --color=always -k hardfail],
1827          [1], [ignore], [stderr])
1828 AT_CHECK([cat stderr | grep ERROR | $FGREP "$red"], [], [ignore])
1829 # Reset color on verbose output.
1830 printf %s\\n "$std"
1831 ], [1])
1834 ## ------------------- ##
1835 ## srcdir propagation. ##
1836 ## ------------------- ##
1838 AT_SETUP([srcdir propagation])
1839 AT_KEYWORDS([AC_@&t@CONFIG_TESTDIR])
1841 mkdir pkg vpath-outside vpath-abs
1842 mkdir pkg/t pkg/vpath-inside
1843 AT_DATA([pkg/a])
1844 AT_DATA([pkg/t/b])
1846 AT_DATA([pkg/configure.ac], [[AC_INIT
1847 AC_CONFIG_TESTDIR([t])
1848 AC_OUTPUT
1850 cp "$abs_top_srcdir/build-aux/install-sh" pkg
1852 cd pkg
1853 AT_CHECK_AUTOCONF
1854 cd ..
1856 AT_CHECK_AT_PREP([suite],
1857 [[AT_INIT([suite to check srcdir])
1858 AT_SETUP([my only test])
1859 AT_CHECK([test -f "$top_srcdir"/a && test -f "$srcdir"/b])
1860 AT_CLEANUP
1861 ]], [], [], [], [pkg/t])
1863 rm -f pkg/t/atconfig
1865 # Build directory totally outside source directory.
1866 cd vpath-outside
1867 AT_CHECK([../pkg/configure $configure_options], [0], [ignore])
1868 cd t
1869 AT_CHECK([../../pkg/t/suite], [0], [ignore])
1870 AT_CHECK([../../pkg/t/suite -v], [0], [stdout])
1871 AT_CHECK([grep '^\.\./\.\./pkg/t/suite.at' stdout], [0], [ignore])
1872 cd ../..
1874 # Build directory totally outside source directory (absolute).
1875 my_srcdir=`pwd`/pkg
1876 cd vpath-abs
1877 AT_CHECK(["$my_srcdir"/configure $configure_options], [0], [ignore])
1878 cd t
1879 AT_CHECK(["$my_srcdir"/t/suite], [0], [ignore])
1880 AT_CHECK(["$my_srcdir"/t/suite -v], [0], [stdout])
1881 AT_CHECK([grep '..*/t/suite.at' stdout], [0], [ignore])
1882 cd ../..
1884 # Build directory as subdirectory of source directory.
1885 cd pkg/vpath-inside
1886 AT_CHECK([../configure $configure_options], [0], [ignore])
1887 cd t
1888 AT_CHECK([../../t/suite], [0], [ignore])
1889 AT_CHECK([../../t/suite -v], [0], [stdout])
1890 AT_CHECK([grep '^\.\./\.\./t/suite.at' stdout], [0], [ignore])
1891 cd ../../..
1893 # Build directory as parent of source directory.
1894 AT_CHECK([pkg/configure $configure_options], [0], [ignore])
1895 cd t
1896 AT_CHECK([../pkg/t/suite], [0], [ignore])
1897 AT_CHECK([../pkg/t/suite -v], [0], [stdout])
1898 AT_CHECK([grep '^\.\./pkg/t/suite.at' stdout], [0], [ignore])
1899 cd ..
1901 # Build directory as source directory.
1902 cd pkg
1903 AT_CHECK_CONFIGURE
1904 cd t
1905 AT_CHECK([./suite], [0], [ignore])
1906 AT_CHECK([./suite -v], [0], [stdout])
1907 AT_CHECK([grep '^\./suite.at' stdout], [0], [ignore])
1908 cd ../..
1910 AT_CLEANUP
1913 ## ------------------------------ ##
1914 ## whitespace in absolute testdir ##
1915 ## ------------------------------ ##
1917 AT_SETUP([whitespace in absolute testdir])
1919 dir='dir with  whitespace'
1920 mkdir "$dir"
1921 cd "$dir"
1922 wd=`pwd`
1924 AT_DATA([a])
1925 AT_CHECK_AT_PREP([suite],
1926 [[AT_INIT([suite to check srcdir])
1927 AT_SETUP([my only test])
1928 AT_CHECK([test -f "$top_srcdir"/a])
1929 AT_CLEANUP
1931 AT_CHECK([top_srcdir=$wd ./suite], [0], [ignore])
1932 AT_CHECK([top_srcdir=$wd ./suite -d], [0], [ignore])
1933 AT_CHECK([cd suite.dir/1 && ./run top_srcdir="$wd"], [0], [ignore], [ignore])
1934 AT_CLEANUP
1937 ## ------------------ ##
1938 ## unusual file names ##
1939 ## ------------------ ##
1941 AT_SETUP([unusual file names])
1943 AT_DATA_AUTOTEST([d@&t@nl.at],
1944 [[AT_SETUP([test one])
1945 m4_pattern_allow([^dnl$])
1946 AT_CHECK([test "]m4_dquote(AT_LINE)[" = dn[]l.at:3])
1947 AT_CLEANUP
1950 mkdir sub
1951 AT_DATA_AUTOTEST([sub/"two  spaces".at],
1952 [[AT_SETUP([test two])
1953 AT_CHECK([test "]m4_dquote(AT_LINE)[" = "two  spaces.at:2"])
1954 AT_CLEANUP
1957 AT_CHECK_AT_PREP([suite],
1958 [[AT_INIT([suite to check included file names])
1959 m4_include([d][nl.at])
1960 m4_include([sub/two  spaces.at])
1962 AT_CHECK([$CONFIG_SHELL ./suite], [0], [stdout])
1963 AT_CHECK([grep 'two spaces' suite.log], [1])
1964 AT_CLEANUP
1967 ## --------------- ##
1968 ## C executables.  ##
1969 ## --------------- ##
1971 AT_SETUP([C unit tests])
1972 AT_KEYWORDS([AC_@&t@CONFIG_TESTDIR])
1973 AT_KEYWORDS([AT_@&t@TESTED])
1975 mkdir t
1976 AT_DATA([configure.ac], [[AC_INIT
1977 AC_PROG_CC
1978 AC_CONFIG_TESTDIR([t], [.])
1979 AC_CONFIG_FILES([Makefile])
1980 AC_OUTPUT
1983 # Test file
1984 AT_DATA([testprog.c],
1985 [[int main (int argc, char **argv) { return argc == 2 ? 0 : 1; }
1988 # Testsuite
1989 AT_DATA([Makefile.in],
1990 [[testprog@EXEEXT@: testprog.c
1991         @CC@ @CPPFLAGS@ @CFLAGS@ @LDFLAGS@ -o testprog@EXEEXT@ testprog.c
1994 AT_CHECK_AT_PREP([suite],
1995 [[AT_INIT([suite to check C programs])
1996 AT_TESTED([testprog$EXEEXT])
1997 AT_SETUP([my only test])
1998 AT_CHECK([testprog$EXEEXT foo], [0])
1999 AT_CHECK([testprog$EXEEXT], [1])
2000 AT_CLEANUP
2001 ]], [], [], [], [t])
2003 rm t/atconfig
2004 AT_CHECK_AUTOCONF
2005 AT_CHECK_CONFIGURE
2006 AT_CHECK([grep '^EXEEXT='\''.*'\' t/atconfig], [], [ignore])
2007 AT_CHECK_MAKE
2008 AT_CHECK([cd t && $CONFIG_SHELL ./suite], [], [ignore])
2009 AT_CHECK([grep 1.*successful t/suite.log], [], [ignore])
2010 AT_CLEANUP
2013 ## -------------------------------------- ##
2014 ## C executables (force .exe extension).  ##
2015 ## -------------------------------------- ##
2017 AT_SETUP([C unit tests (EXEEXT)])
2018 AT_KEYWORDS([AC_@&t@CONFIG_TESTDIR])
2019 AT_KEYWORDS([AT_@&t@TESTED])
2021 mkdir t
2022 AT_DATA([configure.ac], [[AC_INIT
2023 AC_PROG_CC
2024 case $ac_cv_exeext in
2025   '' | .exe) ;;
2026   *) exit 77 ;;
2027 esac
2028 ac_cv_exeext=.exe
2029 AC_SUBST([EXEEXT], [$ac_cv_exeext])
2030 AC_CONFIG_TESTDIR([t], [.])
2031 AC_CONFIG_FILES([Makefile])
2032 AC_OUTPUT
2035 # Test file
2036 AT_DATA([testprog.c],
2037 [[int main (int argc, char **argv) { return argc == 2 ? 0 : 1; }
2040 # Testsuite
2041 AT_DATA([Makefile.in],
2042 [[testprog@EXEEXT@: testprog.c
2043         @CC@ @CPPFLAGS@ @CFLAGS@ @LDFLAGS@ -o testprog@EXEEXT@ testprog.c
2046 AT_CHECK_AT_PREP([suite],
2047 [[AT_INIT([suite to check C programs])
2048 AT_TESTED([testprog$EXEEXT])
2049 AT_SETUP([my only test])
2050 AT_CHECK([testprog$EXEEXT foo], [0])
2051 AT_CHECK([testprog$EXEEXT], [1])
2052 AT_CLEANUP
2053 ]], [], [], [], [t])
2055 rm t/atconfig
2056 AT_CHECK_AUTOCONF
2057 AT_CHECK_CONFIGURE
2058 AT_CHECK([grep '^EXEEXT='\''.*'\' t/atconfig], [], [ignore])
2059 AT_CHECK_MAKE
2060 AT_CHECK([cd t && $CONFIG_SHELL ./suite], [], [ignore])
2061 AT_CHECK([grep 1.*successful t/suite.log], [], [ignore])
2062 AT_CLEANUP
2065 ## ------------------------- ##
2066 ## Erlang EUnit unit tests.  ##
2067 ## ------------------------- ##
2069 AT_SETUP([Erlang Eunit unit tests])
2070 AT_KEYWORDS([Erlang])
2071 AT_KEYWORDS([AC_@&t@CONFIG_TESTDIR])
2073 mkdir s t
2074 AT_DATA([configure.ac], [[AC_INIT
2075 AC_ERLANG_PATH_ERL([no])
2076 AC_ERLANG_PATH_ERLC([no])
2077 if test "$ERL" = "no" || test "$ERLC" = "no"; then
2078   HAVE_ERLANG=no
2079   HAVE_EUNIT=no
2080 else
2081   HAVE_ERLANG=yes
2082   AC_ERLANG_CHECK_LIB([eunit], [HAVE_EUNIT=yes], [HAVE_EUNIT=no])
2084 AC_SUBST([HAVE_ERLANG])
2085 AC_SUBST([HAVE_EUNIT])
2087 AC_CONFIG_TESTDIR([t])
2088 AC_CONFIG_FILES([s/compile], [chmod +x s/compile])
2089 AC_CONFIG_FILES([erlang.conf])
2090 AC_OUTPUT
2093 # File to pass info back to us
2094 AT_DATA([erlang.conf.in],
2095 [[HAVE_ERLANG=@HAVE_ERLANG@
2096 HAVE_EUNIT=@HAVE_EUNIT@
2099 # Erlang module to test:
2100 AT_DATA([s/testme.erl],
2101 [[-module(testme).
2102 -export([foo/1]).
2103 foo(1) -> one;
2104 foo(2) -> two;
2105 foo(_) -> other.
2108 # Corresponding Eunit unit test module:
2109 AT_DATA([s/testme_tests.erl],
2110 [[-module(testme_tests).
2111 -include_lib("eunit/include/eunit.hrl").
2112 foo_one_test() -> ?assertEqual(one, testme:foo(1)).
2113 foo_two_test() -> ?assertEqual(two, testme:foo(2)).
2114 foo_other_test() -> ?assertEqual(other, testme:foo(42)).
2117 # Compilation script:
2118 AT_DATA([s/compile.in],
2119 [["@ERLC@" -b beam testme.erl testme_tests.erl
2122 AT_CHECK_AT_PREP([suite],
2123 [[AT_INIT([suite to check EUnit integration])
2124 AT_SETUP([my only test])
2125 AT_CHECK_EUNIT([my_testsuite], [{module, testme}],
2126                [-pa "${abs_top_builddir}/s"])
2127 AT_CLEANUP
2128 ]], [], [], [], [t])
2130 AT_CHECK_AUTOCONF
2131 AT_CHECK_CONFIGURE
2132 . ./erlang.conf
2134 AT_CHECK([grep '^ERL='\''.*'\' t/atconfig], [], [ignore])
2135 AT_CHECK([grep '^ERLC='\''.*'\' t/atconfig], [], [ignore])
2136 AT_CHECK([grep '^ERLCFLAGS='\''.*'\' t/atconfig], [], [ignore])
2138 if test "$HAVE_ERLANG" = yes && test "$HAVE_EUNIT" = yes; then
2139   AT_CHECK([cd s && $CONFIG_SHELL ./compile])
2142 AT_CHECK([cd t && $CONFIG_SHELL ./suite], [], [ignore])
2144 if test "$HAVE_EUNIT" = yes; then
2145   AT_CHECK([grep 1.*successful t/suite.log], [], [ignore])
2146   AT_CHECK([grep skipped t/suite.log], [1], [ignore])
2147 else
2148   AT_CHECK([grep 1.*skipped t/suite.log], [], [ignore])
2149   AT_CHECK([grep 0.*successful t/suite.log], [], [ignore])
2152 AT_CLEANUP