docs: avoid first person, and credit history to David MacKenzie
[autoconf.git] / tests / autotest.at
blob323006e030ef2d2bd8fd439ea4a8b8b79c2eeb37
1 #                                                       -*- Autotest -*-
3 AT_BANNER([Autotest.])
5 # Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free Software
6 # Foundation, Inc.
8 # This program is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation, either version 3 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
22 # AT_DATA_AUTOTEST(FILE-NAME, CONTENTS)
23 # -------------------------------------
24 # Escape the invalid tokens with @&t@.
25 m4_define([AT_DATA_AUTOTEST],
26 [AT_DATA([$1],
27 [m4_bpatsubst([$2], [\(@.\)\(.@\)\|\(m4\|AS\|AT\)\(_\)\|\(d\)\(nl\)],
28               [\1\3\5@&t@\2\4\6])])])
31 # AT_CHECK_AT_PREP(NAME, SUITE-CODE, [STATUS = 0], [STDOUT], [STDERR],
32 #                  [DIR = .])
33 # --------------------------------------------------------------------
34 # Create a new testsuite named NAME that runs a minimal Autotest test suite,
35 # SUITE-CODE.  Do not use `testsuite' for NAME, or the log file it generates
36 # will overwrite the log that the Autoconf test produces when managing
37 # this test case.  STATUS, STDOUT, and STDERR pass directly to the AT_CHECK
38 # that compiles the testsuite.  DIR can specify a particular subdirectory
39 # where the testsuite should live.
40 m4_define([AT_CHECK_AT_PREP],
41 [AT_KEYWORDS([autotest])dnl
42 dnl overquote AT_dir, to make it easier to use
43 m4_pushdef([AT_dir], m4_ifval([$6], [[[$6]]], [.]))dnl
44 dnl
45 AT_CAPTURE_FILE(AT_dir[/$1.log])dnl
46 dnl
47 AT_DATA_AUTOTEST(AT_dir[/package.m4],
48 [[m4_define([AT_PACKAGE_NAME],      [GNU Nonsense])
49 m4_define([AT_PACKAGE_TARNAME],   [nonsense])
50 m4_define([AT_PACKAGE_VERSION],   [1.0])
51 m4_define([AT_PACKAGE_STRING],    [GNU Nonsense 1.0])
52 m4_define([AT_PACKAGE_BUGREPORT], [bug-autoconf@gnu.org])
53 ]])
54 dnl
55 AT_DATA_AUTOTEST(AT_dir[/$1.at], [$2])
56 AT_CHECK([cat >m4_default([$6], [.])/atconfig <<EOF
57 at_testdir=m4_default([$6], [.])
58 abs_builddir='`pwd`'
59 at_srcdir=.
60 abs_srcdir='`pwd`'
61 at_top_srcdir=.
62 abs_top_srcdir='`pwd`'
63 at_top_build_prefix=
64 abs_top_builddir='`pwd`'
65 EOF])
66 m4_ifval([$6], [(cd AT_dir])
67 AT_CHECK_AUTOM4TE([--language=autotest -o $1 $1.at], [$3], [$4], [$5])
68 m4_ifval([$6], [)])
69 m4_popdef([AT_dir])dnl
70 ]) # AT_CHECK_AT_PREP
72 # AT_CHECK_AT(TITLE, SUITE-CODE, [XFAIL-CONDITION], [STATUS = 0],
73 #             [STDOUT = ignore], STDERR, [PRE-TEST-CODE],
74 #             [POST-TEST-CODE], [SUITE-ARGS])
75 # ---------------------------------------------------------------
76 # Create a new test named TITLE that runs a minimal Autotest test suite,
77 # SUITE-CODE with additional SUITE-ARGS, once without and once with
78 # '-v -x' added.  Call AT_XFAIL_IF with XFAIL-CONDITION.  Pass STDERR
79 # directly to the AT_CHECK that calls the minimal test suite, STDOUT to
80 # the AT_CHECK without '-v -x'; ignore stdout for the latter.
81 # Run PRE-TEST-CODE at the top level after the micro-suite is created, but
82 # before it is run, and POST-TEST-CODE after the micro-suite has been run.
83 m4_define([AT_CHECK_AT],
84 [AT_SETUP([$1])
85 AT_XFAIL_IF([$3])
86 AT_CHECK_AT_PREP([micro-suite], [$2])
88 AT_CHECK([$CONFIG_SHELL ./micro-suite $9],       m4_default([$4], 0),
89          m4_default([$5], [ignore]), [$6])
90 AT_CHECK([$CONFIG_SHELL ./micro-suite -v -x $9], m4_default([$4], 0),
91          [ignore], [$6])
93 AT_CLEANUP
94 ])# AT_CHECK_AT
96 # AT_CHECK_AT_TEST(TITLE, SUITE-SNIPPET, ...)
97 # -------------------------------------------
98 # Wrapper for AT_CHECK_AT that surrounds SUITE-SNIPPET with a boilerplate
99 # AT_INIT, AT_SETUP, and AT_CLEANUP and passes other arguments verbatim.
100 m4_define([AT_CHECK_AT_TEST],
101 [AT_CHECK_AT([$1],
103 AT_INIT([artificial test suite])
104 AT_SETUP([my only test])
106 AT_CLEANUP
107 ]], m4_shift2($@))]) # AT_CHECK_AT_TEST
109 # AT_CHECK_AT_SYNTAX(TITLE, SUITE, MESSAGE)
110 # -----------------------------------------
111 # Create a test named TITLE that tries compiling SUITE with syntax
112 # errors with autotest.  Expect a failed compilation, and grep for
113 # MESSAGE occuring within the error output.
114 m4_define([AT_CHECK_AT_SYNTAX],
115 [AT_SETUP([$1])
116 AT_CHECK_AT_PREP([micro-suite], [$2], [1], [], [stderr])
117 AT_CHECK([grep '$3' stderr], [0], [ignore])
118 AT_CLEANUP
119 ])# AT_CHECK_AT_SYNTAX
122 # AT_NO_CMDSUBST
123 # --------------
124 m4_define([AT_NO_CMDSUBST],
125 [if (eval 'foo=$(echo bar) && test "$foo" = bar') >/dev/null 2>&1; then ]dnl
126 [false; else :; fi])
128 # AT_CHECK_EGREP(PATTERN, STATUS, COUNT)
129 # --------------------------------------
130 # Run grep -E, counting how many times PATTERN occurs in the file 'stdout',
131 # and expecting exit STATUS and output COUNT.
132 m4_define([AT_CHECK_EGREP],
133 [AT_CHECK([$EGREP -c '$1' stdout], [$2], [$3
134 ], [ignore])
138 ## -------------- ##
139 ## AT_COPYRIGHT.  ##
140 ## -------------- ##
142 # Ensure the FSF notice as well as the user-provided one are present
143 # in the head of the testsuite as well as the --version output.
145 AT_CHECK_AT([AT@&t@_COPYRIGHT],
146 [[AT_INIT([Testing AT@&t@_COPYRIGHT])
147 AT_COPYRIGHT([[This is just a test notice, not a real one, so let's avoid
148 words that may be matched by scanners for legal things,
149 causing extra work for distributors.
150 Multi-line values should be supported.
152 ]], [], [], [stdout], [], [], [
153 AT_CHECK([grep 'Copyright.*Free Software Foundation' stdout], [], [ignore])
154 AT_CHECK([grep 'This is just a test notice' stdout], [], [ignore])
155 AT_CHECK([sed 50q micro-suite | grep 'Copyright.*Free Software Foundation'],
156          [], [ignore])
157 AT_CHECK([sed 50q micro-suite | grep 'This is just a test notice'],
158          [], [ignore])],
159 [--version])
162 ## --------- ##
163 ## AT_DATA.  ##
164 ## --------- ##
166 AT_CHECK_AT_TEST([AT@&t@_DATA], [
167 AT_CHECK([test -f file1], [1])
168 AT_DATA([file1])
169 AT_CHECK([test -f file1 && test ! -s file1])
170 AT_CHECK([echo hi > file1])
171 AT_DATA([file1], [[]])
172 AT_CHECK([test -f file1 && test ! -s file1])
173 file=file2
174 AT_DATA([$file], [[$file
176 AT_CHECK([echo '$file' > file3])
177 AT_CHECK([cmp file2 file3])
181 ## ------------------ ##
182 ## Empty test suite.  ##
183 ## ------------------ ##
185 # This is not a sensible thing to do, but the user should not get an unhelpful
186 # error message.
187 AT_CHECK_AT([Empty test suite],
188 [[AT_INIT([empty test suite])
191 AT_CHECK_AT([Banner-only test suite],
192 [[AT_INIT([empty test suite])
193 AT_BANNER([banner])
196 # Next level of emptiness.
197 AT_CHECK_AT_TEST([Empty test], [])
199 # And finally, an empty check should not cause a syntax error.
200 AT_CHECK_AT_TEST([Empty check], [AT_CHECK])
202 # Check for sensible error messages for common bugs.
203 AT_CHECK_AT_SYNTAX([AT@&t@_SETUP without AT@&t@_INIT],
204 [[AT_SETUP([only test])
205 AT_CHECK([:])
206 AT_CLEANUP
207 ]], [AT@&t@_SETUP: missing AT@&t@_INIT detected])
209 AT_CHECK_AT_SYNTAX([AT@&t@_BANNER without AT@&t@_INIT],
210 [[AT_BANNER([just a banner])
211 ]], [AT@&t@_BANNER: missing AT@&t@_INIT detected])
213 AT_CHECK_AT_SYNTAX([AT@&t@_CLEANUP without AT@&t@_INIT],
214 [[AT_CLEANUP
215 ]], [AT@&t@_CLEANUP: missing AT@&t@_INIT detected])
217 AT_CHECK_AT_SYNTAX([Missing AT@&t@_CLEANUP],
218 [[AT_INIT([incomplete test suite])
219 AT_SETUP([only test])
220 AT_CHECK([:])
221 ]], [missing AT@&t@_CLEANUP detected])
223 AT_CHECK_AT_SYNTAX([AT@&t@_FAIL_IF without AT@&t@_SETUP],
224 [[AT_INIT([incomplete test suite])
225 AT_FAIL_IF([:])
226 ]], [AT@&t@_FAIL_IF: missing AT@&t@_SETUP detected])
228 AT_CHECK_AT_SYNTAX([AT@&t@_SKIP_IF without AT@&t@_SETUP],
229 [[AT_INIT([incomplete test suite])
230 AT_SKIP_IF([:])
231 ]], [AT@&t@_SKIP_IF: missing AT@&t@_SETUP detected])
233 AT_CHECK_AT_SYNTAX([AT@&t@_CHECK without AT@&t@_SETUP],
234 [[AT_INIT([incomplete test suite])
235 AT_CHECK([:])
236 ]], [AT@&t@_CHECK: missing AT@&t@_SETUP detected])
238 AT_CHECK_AT_SYNTAX([AT@&t@_DATA without AT@&t@_SETUP],
239 [[AT_INIT([incomplete test suite])
240 AT_DATA([file])
241 ]], [AT@&t@_DATA: missing AT@&t@_SETUP detected])
243 AT_CHECK_AT_SYNTAX([AT@&t@_XFAIL_IF without AT@&t@_SETUP],
244 [[AT_INIT([incomplete test suite])
245 AT_XFAIL_IF([:])
246 ]], [AT@&t@_XFAIL_IF: missing AT@&t@_SETUP detected])
248 AT_CHECK_AT_SYNTAX([AT@&t@_KEYWORDS without AT@&t@_SETUP],
249 [[AT_INIT([incomplete test suite])
250 AT_KEYWORDS([keyword])
251 ]], [AT@&t@_KEYWORDS: missing AT@&t@_SETUP detected])
253 AT_CHECK_AT_SYNTAX([AT@&t@_CLEANUP without AT@&t@_SETUP],
254 [[AT_INIT([incomplete test suite])
255 AT_CLEANUP
256 ]], [AT@&t@_CLEANUP: missing AT@&t@_SETUP detected])
258 AT_CHECK_AT_SYNTAX([AT@&t@_BANNER inside AT@&t@_SETUP],
259 [[AT_INIT([incomplete test suite])
260 AT_SETUP([only test])
261 AT_BANNER([banner])
262 AT_CHECK([:])
263 AT_CLEANUP
264 ]], [AT@&t@_BANNER: nested AT@&t@_SETUP detected])
266 AT_CHECK_AT_SYNTAX([AT@&t@_SETUP inside AT@&t@_SETUP],
267 [[AT_INIT([incomplete test suite])
268 AT_SETUP([only test])
269  AT_SETUP([nested test])
270  AT_CHECK([:])
271  AT_CLEANUP
272 AT_CHECK([:])
273 AT_CLEANUP
274 ]], [AT@&t@_SETUP: nested AT@&t@_SETUP detected])
276 AT_CHECK_AT_SYNTAX([Multiple AT@&t@_INIT],
277 [[AT_INIT([[suite, take one]])
278 AT_INIT([repeat])
279 ]], [AT@&t@_INIT: invoked multiple times])
281 # Check for tested programs.  autoconf should only appear once.
282 AT_CHECK_AT([Tested programs],
283 [[AT_INIT([programs test suite])
284 AT_TESTED([autoconf autom4te])
285 AT_TESTED([autoconf])
286 ]], [], [], [], [], [],
287 [AT_CHECK([[sed -n 's|.*/\([^ /]* --version\)|\1|p' micro-suite.log]], [],
288 [[autoconf --version
289 autom4te --version
290 ]])])
292 AT_CHECK_AT([Startup error messages],
293 [[AT_INIT([[suite]])
294 AT_SETUP([only test])
295 AT_CHECK([:])
296 AT_CLEANUP
297 ]], [], [], [], [], [],
298 [AT_CHECK([sed -n '/exec AS_MESSAGE_LOG_FD/q; />&AS_MESSAGE_LOG_FD/p' < micro-suite])])
300 ## ----------------- ##
301 ## Status handling.  ##
302 ## ----------------- ##
304 AT_CHECK_AT_TEST([Truth],
305   [AT_CHECK([:], 0, [], [])])
307 AT_CHECK_AT_TEST([Fallacy],
308   [AT_CHECK([false], [], [], [])],
309   [], [1], [], [ignore], [],
310   [AT_CHECK([grep failed micro-suite.log], [], [ignore])])
312 AT_CHECK_AT_TEST([Skip],
313   [AT_CHECK([echo output; echo irrelevant >&2; exit 77], 0, [mismatch], [])],
314   [], [], [], [], [],
315   [AT_CHECK([grep skipped micro-suite.log], [], [ignore])])
317 AT_CHECK_AT_TEST([Hard fail],
318   [AT_CHECK([exit 99])
319    AT_CLEANUP
320    AT_SETUP([another test])
321    AT_XFAIL_IF([:])
322    AT_CHECK([exit 99])],
323   [], [1], [], [ignore], [],
324   [AT_CHECK([grep '2 failed unexpectedly' micro-suite.log], [], [ignore])
325    AT_CHECK([grep '^[[12]].*ok' micro-suite.log], [1])])
327 AT_CHECK_AT_TEST([AT@&t@_FAIL_IF],
328   [AT_FAIL_IF([:])
329   AT_CLEANUP
330   AT_SETUP
331   AT_FAIL_IF([false])
332   AT_CLEANUP
333   AT_SETUP
334   AT_FAIL_IF([test x = y])
335   AT_CLEANUP
336   AT_SETUP
337   AT_FAIL_IF([bah])
338   AT_CLEANUP
339   AT_SETUP
340   AT_FAIL_IF([test x = x])
341   AT_CLEANUP
342   AT_SETUP
343   AT_FAIL_IF([test $foo = x])],
344   [], [1], [stdout], [ignore], [],
345   [AT_CHECK([grep '1 5 failed' stdout], [], [ignore], [ignore])])
347 AT_CHECK_AT_TEST([AT@&t@_SKIP_IF],
348   [AT_SKIP_IF([:])
349   AT_CLEANUP
350   AT_SETUP
351   AT_SKIP_IF([false])
352   AT_CLEANUP
353   AT_SETUP
354   AT_SKIP_IF([test x = y])
355   AT_CLEANUP
356   AT_SETUP
357   AT_SKIP_IF([bah])
358   AT_CLEANUP
359   AT_SETUP
360   AT_SKIP_IF([test x = x])
361   AT_CLEANUP
362   AT_SETUP
363   AT_SKIP_IF([test $foo = x])],
364   [], [], [], [], [],
365   [AT_CHECK([grep '2.*skipped' micro-suite.log], [], [ignore], [ignore])])
367 AT_CHECK_AT_TEST([Syntax error],
368   [AT_CHECK([:])
369    AT_CLEANUP
370    AT_SETUP([syntax])
371    AT_CHECK([if])
372    AT_CLEANUP
373    AT_SETUP([another test])
374    AT_CHECK([:])],
375   [], [0], [], [], [],
376   [dnl Until we can find a way to avoid catastrophic failure (ash) or
377    dnl lack of failure (zsh), skip the rest of this test on such shells.
378    echo 'if' > syntax
379    AT_CHECK([${CONFIG_SHELL-$SHELL} -c 'case `. ./syntax; echo $?` in
380                   0|"") exit 77;;
381                 esac'], [0], [ignore], [ignore])
382    AT_CHECK([$CONFIG_SHELL ./micro-suite], [1], [ignore], [stderr])
383    AT_CHECK([grep "unable to parse test group: 2" stderr], [0], [ignore])],
384   [1 3])
386 AT_CHECK_AT_TEST([errexit],
387   [AT_CHECK([false])
388    AT_CLEANUP
389    AT_SETUP([test that should not be run])
390    AT_CHECK([:])
391    AT_CLEANUP
392    AT_SETUP([xpassing test])
393    AT_XFAIL_IF([:])
394    AT_CHECK([:])
395    AT_CLEANUP
396    AT_SETUP([another test that should not be run])
397    AT_CHECK([:])
398    AT_CLEANUP
399    AT_SETUP([skipping test])
400    AT_CHECK([exit 77])
401    AT_CLEANUP
402    AT_SETUP([xfailing test])
403    AT_XFAIL_IF([:])
404    AT_CHECK([false])
405    AT_CLEANUP
406    AT_SETUP([a test that should be run])
407    AT_CLEANUP
408    AT_SETUP([hard failure])
409    AT_XFAIL_IF([:])
410    AT_CHECK([exit 99])
411    AT_CLEANUP
412    AT_SETUP([yet another test that should not be run])],
413   [], [1], [stdout], [stderr], [],
414   [AT_CHECK([test -f micro-suite.log], [1])
415    touch micro-suite.log # shut up AT_CAPTURE_FILE.
416    AT_CHECK([grep "should not be run" stdout], [1])
417    AT_CHECK([grep "1 .* inhibited subsequent" stderr], [], [ignore])
418    AT_CHECK([$CONFIG_SHELL ./micro-suite --errexit 3-], [1], [stdout], [stderr])
419    AT_CHECK([grep "should not be run" stdout], [1])
420    AT_CHECK([grep "1 .* inhibited subsequent" stderr], [], [ignore])
421    AT_CHECK([$CONFIG_SHELL ./micro-suite --errexit 5-], [1], [stdout], [stderr])
422    AT_CHECK([grep "should be run" stdout], [0], [ignore])
423    AT_CHECK([grep "should not be run" stdout], [1])
424    AT_CHECK([grep "inhibited subsequent" stderr], [], [ignore])],
425   [--errexit])
428 AT_CHECK_AT_TEST([at_status],
429   [AT_CHECK([exit $mystatus], [$expected], [], [],
430             [AT_CHECK([echo run-if-fail: $at_status], [], [ignore])],
431             [AT_CHECK([echo run-if-pass: $at_status], [], [ignore])])
432    AT_CLEANUP
433    AT_SETUP([test with nested checks])
434    AT_CHECK([exit $mystatus], [$expected], [], [],
435             [AT_CHECK([exit $mystatus], [$expected], [], [],
436                       [AT_CHECK([echo inner run-if-fail: $at_status], [],
437                                 [ignore])])])],
438   [], [], [stdout], [],
439 [], [
440 AT_CHECK([grep 'inner run-if-fail: 42' stdout], [], [ignore])
441 AT_CHECK([$CONFIG_SHELL ./micro-suite -x -v 1 mystatus=0 expected=0], [], [stdout])
442 AT_CHECK([grep 'run-if-pass: 0' stdout], [], [ignore])
443 AT_CHECK([$CONFIG_SHELL ./micro-suite -x -v 1 mystatus=42 expected=0], [], [stdout])
444 AT_CHECK([grep 'run-if-fail: 42' stdout], [], [ignore])
445 AT_CHECK([$CONFIG_SHELL ./micro-suite -x -v 1 mystatus=0 expected=42], [], [stdout])
446 AT_CHECK([grep 'run-if-fail: 0' stdout], [], [ignore])
447 AT_CHECK([$CONFIG_SHELL ./micro-suite -x -v 1 mystatus=42 expected=42], [], [stdout])
448 AT_CHECK([grep 'run-if-pass: 42' stdout], [], [ignore])
450 [-v mystatus=42 expected=1
454 AT_CHECK_AT_TEST([AT@&t@_CHECK execution environment],
455   [dnl The first test should fail, so we enter RUN-IF-FAIL.
456    AT_CHECK([test "$state" != before], [], [], [],
457             [state=run-if-fail
458              AT_CHECK([:]) dnl need this so we do not bail out at this point.
459             ])
460    dnl This should pass, so we enter RUN-IF-PASS.
461    AT_CHECK([test "$state" = run-if-fail], [], [], [], [],
462             [state=run-if-pass])
463    AT_CHECK([test "$state" = run-if-pass])
464    dnl However, COMMANDS are run inside a subshell, so do not change state.
465    AT_CHECK([state=broken; false], [], [], [],
466             [AT_CHECK([test "$state" = run-if-pass])])
467    AT_CHECK([state=broken], [], [], [], [],
468             [AT_CHECK([test "$state" = run-if-pass])])
469   ],
470   [], [], [], [], [], [], [state=before])
473 AT_CHECK_AT_TEST([unquoted output],
474   [m4_define([backtick], [`])
475    a=a
476    AT_CHECK_UNQUOTED([echo 'a"b  backtick`'], [],
477      [${a}"`echo 'b  '`\`\backtick]m4_newline)],
478   [], [], [], [], [AT_KEYWORDS([AT@&t@_CHECK_UNQUOTED])])
480 AT_CHECK_AT_TEST([Trace output],
481   [AT_CHECK([echo some longer longer longer command piped | ]dnl
482             [sed 's,into some other longer longer longer command,,'],
483             [], [some longer longer longer command piped
484 ])])
486 AT_CHECK_AT([Logging],
487   [[AT_INIT([artificial test suite])
488     dnl intentionally write failing tests, to see what gets logged
489     AT_SETUP([one])
490     AT_CHECK([echo magicstring01], [1], [ignore])
491     AT_CLEANUP
492     AT_SETUP([two])
493     AT_CHECK([echo magicstring02 >&2], [1], [], [ignore])
494     AT_CLEANUP
495     AT_SETUP([three])
496     AT_CHECK([echo magicstring03], [1], [ignore-nolog])
497     AT_CLEANUP
498     AT_SETUP([four])
499     AT_CHECK([echo magicstring04 >&2], [1], [], [ignore-nolog])
500     AT_CLEANUP
501     AT_SETUP([five])
502     AT_CHECK([echo magicstring05], [1], [stdout])
503     AT_CLEANUP
504     AT_SETUP([six])
505     AT_CHECK([echo magicstring06 >&2], [1], [], [stderr])
506     AT_CLEANUP
507     AT_SETUP([seven])
508     AT_CHECK([echo magicstring07], [1], [stdout-nolog])
509     AT_CLEANUP
510     AT_SETUP([eight])
511     AT_CHECK([echo magicstring08 >&2], [1], [], [stderr-nolog])
512     AT_CLEANUP
513     AT_SETUP([nine])
514     echo magicstring09 > expout
515     AT_CHECK([echo magicstring09], [1], [expout])
516     AT_CLEANUP
517     AT_SETUP([ten])
518     echo magicstring10 > experr
519     AT_CHECK([echo magicstring10 >&2], [1], [], [experr])
520     AT_CLEANUP
521 ]], [], [1], [], [ignore], [],
522   [AT_CHECK([$CONFIG_SHELL ./micro-suite], [1], [ignore-nolog], [ignore-nolog])
523    AT_CHECK([grep '^magicstring' micro-suite.log], [],
524 [[magicstring01
525 magicstring02
526 magicstring05
527 magicstring06
528 ]])])
531 AT_CHECK_AT([Binary output],
532   [[AT_INIT([artificial test suite])
533     AT_SETUP([pass: no trailing newline])
534     AT_CHECK([printf short], [0], [stdout-nolog])
535     AT_CHECK([cat stdout], [0], [[short]])
536     AT_CLEANUP
537     AT_SETUP([pass: non-printing characters])
538     AT_CHECK([printf '\1\n' >&2], [0], [], [stderr-nolog])
539     printf '\1\n' > expout
540     AT_CHECK([cat stderr], [0], [expout])
541     AT_CLEANUP
542     AT_SETUP([pass: long lines])
543     # 5000 bytes in str
544     str=..........
545     str=$str$str$str$str$str$str$str$str$str$str
546     str=$str$str$str$str$str$str$str$str$str$str
547     str=$str$str$str$str$str
548     AT_CHECK_UNQUOTED([echo $str], [0], [[$str]m4_newline])
549     AT_CLEANUP
550     AT_SETUP([fail: no trailing newline])
551     AT_CHECK([printf short], [0], [stdout-nolog])
552     AT_CHECK([cat stdout], [0], [[long]])
553     AT_CLEANUP
554     AT_SETUP([fail: non-printing characters])
555     AT_CHECK([printf '\1\n' >&2], [0], [], [stderr-nolog])
556     printf '\2\n' > expout
557     AT_CHECK([cat stderr], [0], [expout])
558     AT_CLEANUP
559     AT_SETUP([fail: long lines])
560     # 5000 bytes in str
561     str=..........
562     str=$str$str$str$str$str$str$str$str$str$str
563     str=$str$str$str$str$str$str$str$str$str$str
564     str=$str$str$str$str$str
565     AT_CHECK_UNQUOTED([echo x$str], [0], [[${str}x]m4_newline])
566     AT_CLEANUP
567 ]], [], [0], [], [], [],
568   [AT_CHECK([$CONFIG_SHELL ./micro-suite 4], [1], [ignore], [ignore])
569    AT_CHECK([$CONFIG_SHELL ./micro-suite 5], [1], [ignore], [ignore])
570    AT_CHECK([$CONFIG_SHELL ./micro-suite 6], [1], [ignore], [ignore])], [1-3])
573 AT_CHECK_AT_TEST([Cleanup],
574   [AT_CHECK([test ! -f cleanup.success && test ! -f cleanup.failure])
575    AT_XFAIL_IF([$xfail])
576    AT_CHECK_UNQUOTED([exit $value], [ignore], [$output],
577      [], [touch cleanup.failure], [touch cleanup.success])],
578   [], [], [], [],
579   [AT_KEYWORDS([AT@&t@_CHECK_UNQUOTED])
580     output=; export output],
581   [AT_CHECK([test -d micro-suite.dir/1])
582    AT_CHECK([test -f micro-suite.dir/1/cleanup.success])
583    AT_CHECK([test ! -f micro-suite.dir/1/cleanup.failure])
585    AT_CHECK([$CONFIG_SHELL ./micro-suite -d xfail=false value=1], [], [ignore])
586    AT_CHECK([test -f micro-suite.dir/1/cleanup.success])
587    AT_CHECK([test ! -f micro-suite.dir/1/cleanup.failure])
589    AT_CHECK([$CONFIG_SHELL ./micro-suite xfail=: value=0],
590      [1], [ignore], [ignore])
591    AT_CHECK([test -f micro-suite.dir/1/cleanup.success])
592    AT_CHECK([test ! -f micro-suite.dir/1/cleanup.failure])
594    AT_CHECK([$CONFIG_SHELL ./micro-suite -d xfail=false value=1 output=mismatch],
595      [1], [ignore], [ignore])
596    AT_CHECK([test ! -f micro-suite.dir/1/cleanup.success])
597    AT_CHECK([test -f micro-suite.dir/1/cleanup.failure])
599    AT_CHECK([$CONFIG_SHELL ./micro-suite -d xfail=false value=77], [], [ignore])
600    AT_CHECK([test ! -f micro-suite.dir/1/cleanup.success])
601    AT_CHECK([test ! -f micro-suite.dir/1/cleanup.failure])
603    AT_CHECK([$CONFIG_SHELL ./micro-suite -d xfail=false value=99],
604      [1], [ignore], [ignore])
605    AT_CHECK([test ! -f micro-suite.dir/1/cleanup.success])
606    AT_CHECK([test ! -f micro-suite.dir/1/cleanup.failure])
607   ], [-d xfail=false value=0])
609 ## ----------------------------------------------------- ##
610 ## Newlines and command substitutions in test commands.  ##
611 ## ----------------------------------------------------- ##
613 AT_CHECK_AT_TEST([Literal multiline command],
614   [AT_CHECK([echo Auto'
615 'conf], 0, [Auto
616 conf
617 ], [])])
619 AT_CHECK_AT_TEST([Multiline parameter expansion],
620   [FOO='one
621 two'
622    AT_CHECK([echo "$FOO"], 0, [one
624 ], [])])
626 AT_CHECK_AT_TEST([Backquote command substitution],
627   [AT_CHECK([echo `echo hi`], 0, [hi
628 ], [])])
631 AT_CHECK_AT_TEST([Multiline backquote command substitution],
632   [AT_DATA([myfile],[foo
635    AT_CHECK([echo "`cat myfile`"], 0, [foo
637 ], [])])
639 AT_CHECK_AT_TEST([Parenthetical command substitution],
640   [AT_CHECK([echo $(echo hi)], 0, [hi
641 ], [])],
642   [AT_NO_CMDSUBST])
644 AT_CHECK_AT_TEST([Multiline parenthetical command substitution],
645   [AT_DATA([myfile],[foo
648    AT_CHECK([echo "$(cat myfile)"], 0, [foo
650 ], [])],
651   [AT_NO_CMDSUBST])
654 AT_CHECK_AT_TEST([Shell comment in command],
655   [my_echo=echo
656    AT_CHECK([$my_echo one [#] two], [], [one
657 ])])
660 ## ------------------------- ##
661 ## ${...} in test commands.  ##
662 ## ------------------------- ##
664 # If this invalid parameter expansion capsizes the test suite, the entire
665 # AT_SETUP ... AT_CLEANUP subshell will exit, and the commands it runs will
666 # appear to have succeeded.  Therefore, we verify a failing test case.
668 AT_CHECK_AT_TEST([Invalid brace-enclosed parameter expansion],
669   [AT_CHECK([echo '${=invalid}'], 0, [wrong])], [false], 1, ignore, ignore)
672 ## ---------------------------- ##
673 ## M4 macros in test commands.  ##
674 ## ---------------------------- ##
676 AT_CHECK_AT_TEST([Multiline command from M4 expansion],
677   [m4_define([GNU], ['foo
678 bar'])
679    AT_CHECK([echo GNU], 0, [foo
681 ], [])])
683 AT_CHECK_AT_TEST([Double-M4-quoted command],
684   [m4_define([GNU], ['foo
685 bar'])
686    AT_CHECK([[echo GNU]], 0, [[GNU
687 ]], [])])
690 AT_CHECK_AT_TEST([Metacharacters in command from M4 expansion],
691   [m4_define([GNU], [\"`])
692    AT_CHECK([echo '\"`' [GNU] 'GNU'], 0, [GNU [G][NU] [\"`
693 ]], [])])
696 ## -------------------------------------- ##
697 ## Backslash-<newline> in test commands.  ##
698 ## -------------------------------------- ##
700 AT_CHECK_AT_TEST([BS-newline in command],
701   [AT_CHECK([echo Auto"\
702 "conf], 0, [Autoconf
703 ], [])])
705 AT_CHECK_AT_TEST([^BS-newline in command],
706   [AT_CHECK([\
707 echo GNU], 0, [GNU
708 ], [])])
710 AT_CHECK_AT_TEST([BSx641-newline in command],
711   [AT_CHECK([printf '%s\n' Auto"\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
712 "conf], 0, [Auto\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\conf
713 ], [])])
715 AT_CHECK_AT_TEST([BS-BS-newline in command],
716   [AT_CHECK([printf '%s\n' Auto"\\
717 "conf], 0, [Auto\
718 conf
719 ], [])])
721 # A `^BS-BS-newline in command' test will run a command named `\'.  No, thanks.
723 AT_CHECK_AT_TEST([BSx640-newline in command],
724   [AT_CHECK([printf '%s\n' Auto"\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
725 "conf], 0, [Auto\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
726 conf
727 ], [])])
729 # This command has both escaped and unescaped newlines.
730 AT_CHECK_AT_TEST([Newline-CODE-BS-newline in command],
731   [AT_CHECK([printf '%s\n' Auto'
732 'co\
733 nf], 0, [Auto
734 conf
735 ], [])])
737 AT_CHECK_AT_TEST([Single-quote-BS-newline in command],
738   [AT_CHECK([printf '%s\n' Auto'\
739 'conf], 0, [Auto\
740 conf
741 ], [])])
743 AT_CHECK_AT_TEST([Single-quote-newline-BS-newline in command],
744   [AT_CHECK([printf '%s\n' Auto'
746 'conf], 0, [Auto
748 conf
749 ], [])])
752 ## ----------------- ##
753 ## Input from stdin. ##
754 ## ----------------- ##
756 AT_SETUP([Input from stdin])
758 AT_CHECK_AT_PREP([micro-suite],
759 [[AT_INIT
760 AT_SETUP([please enter hello<RETURN><EOF>])
761 AT_CHECK([cat], [], [hello
763 AT_CLEANUP
766 AT_CHECK([echo hello | $CONFIG_SHELL ./micro-suite], [], [ignore])
767 AT_CHECK([$CONFIG_SHELL ./micro-suite </dev/null], [1], [ignore], [ignore])
769 AT_CLEANUP
772 ## ------------------------------- ##
773 ## Funny characters in test names. ##
774 ## ------------------------------- ##
776 # AT_CHECK_AT_TITLE(TITLE, TITLE-TO-TEST, EXPANDED-TITLE-TO-TEST,
777 #                   [XFAIL-CONDITION], [COLUMN = 53])
778 # ---------------------------------------------------------------
779 # Create a new test named TITLE that runs an Autotest test suite
780 # comprised of a trivial test named TITLE-TO-TEST, which expands
781 # to EXPANDED-TITLE-TO-TEST.  XFAIL-CONDITION passes verbatim to
782 # AT_CHECK_AT.  Verify that `ok' prints at COLUMN.
783 m4_define([AT_CHECK_AT_TITLE],
784 [AT_CHECK_AT([$1],
786 m4_define([macro_name],         [[macro_expanded]])
787 m4_define([macro_expanded],     [[macro_overexpanded]])
788 m4_define([macro_backquote],    [`])
789 m4_define([macro_single_quote], ['])
790 m4_define([macro_double_quote], ["])
791 ]]dnl restore font-lock: "
792 [[m4_define([macro_backslash],  [\])
793 m4_define([macro_echo],         [$][1])
794 AT_INIT([artificial test suite])
795 AT_SETUP([$2])
796 AT_CHECK([:])
797 AT_CLEANUP
798 ]], [$4], [], [], [], [],
799 dnl This sed script checks for two things - that the output is properly
800 dnl expanded, and that the 'ok' starts on the right column.
801 [AT_KEYWORDS([m4@&t@_expand])
802 AT_CHECK([[$CONFIG_SHELL ./micro-suite |
803             sed -n '/^  1:/{
805 s/[^:]*: \(.*[^  ]\)[    ]*ok.*/\1/p
807 s/^.\{]]]m4_default($5, 53)[[[\}ok.*/ok/p
808 }']],,
809 [[$3
812 dnl This sed script checks for two things - that -v output doesn't have
813 dnl an empty $at_srcdir expansion, and that the 'testing ...' line
814 dnl contains the test group title.
815 AT_CHECK([[$CONFIG_SHELL ./micro-suite -v |
816             sed -n 's/.*testing \(.*\) \.\.\./\1/p; /^\/micro-suite\.at:/p']],,
817 [[$3
819 AT_CHECK([[$CONFIG_SHELL ./micro-suite -l |
820            sed -n 's/.*[0-9]: [^         ][^     ]*[     ][      ]*\(.*[^        ]\)[    ]*/\1/p']],,
821 [[$3
823 AT_CHECK([[sed -n 's/[^.]*\. \(.*\) ([^)]*): ok.*/\1/p' micro-suite.log]],,
824 [[$3
826 ])])
828 m4_define([AT_CHECK_AT_TITLE_CHAR],
829 [AT_CHECK_AT_TITLE([$1 in a test title], [A $2 in my name],
830                    [A ]m4_ifval([$3], [[$3]], [[$2]])[ in my name], $4, $5)])
832 AT_CHECK_AT_TITLE_CHAR([Backquote],     [`])
833 AT_CHECK_AT_TITLE_CHAR([Single-quote],  ['])
834 AT_CHECK_AT_TITLE_CHAR([Double-quote],  ["])
835 dnl restore font-lock: "
836 AT_CHECK_AT_TITLE_CHAR([Backslash],     [\])
837 AT_CHECK_AT_TITLE_CHAR([Brackets],   [[[]]], [[]])
838 AT_CHECK_AT_TITLE_CHAR([Left bracket],  [@<:@], [@<:@])
839 AT_CHECK_AT_TITLE_CHAR([Right bracket], [@:>@], [@:>@])
840 AT_CHECK_AT_TITLE_CHAR([Quoted pound],  [[#]], [#])
841 AT_CHECK_AT_TITLE_CHAR([Pound],         [#])
842 AT_CHECK_AT_TITLE_CHAR([Quoted comma],  [[,]], [,])
843 AT_CHECK_AT_TITLE_CHAR([Comma],         [,])
844 dnl this test also hits quadrigraphs for ()
845 AT_CHECK_AT_TITLE_CHAR([Parentheses],   [(@{:@)@:}@], [(())])
846 AT_CHECK_AT_TITLE_CHAR([Left paren],    [[(]], [(])
847 AT_CHECK_AT_TITLE_CHAR([Right paren],   [[)]], [)])
849 AT_CHECK_AT_TITLE_CHAR([Quoted Macro], [[macro_name]], [macro_name])
850 AT_CHECK_AT_TITLE_CHAR([Macro],        [macro_name],   [macro_expanded])
851 AT_CHECK_AT_TITLE_CHAR([Macro with backquote],       [macro_backquote], [`])
852 AT_CHECK_AT_TITLE_CHAR([Macro with single-quote], [macro_single_quote], ['])
853 AT_CHECK_AT_TITLE_CHAR([Macro with double-quote], [macro_double_quote], ["])
854 dnl restore font-lock: "
855 AT_CHECK_AT_TITLE_CHAR([Macro with backslash],       [macro_backslash], [\])
856 AT_CHECK_AT_TITLE_CHAR([Macro echoing macro], [macro_echo([macro_name])],
857                        [macro_expanded])
858 AT_CHECK_AT_TITLE_CHAR([Macro echoing single-quote], [macro_echo(['])], ['])
859 AT_CHECK_AT_TITLE_CHAR([Long test title], [0123456789012345678901234567890123])
860 AT_CHECK_AT_TITLE_CHAR([Longer test title],
861                        [01234567890123456789012345678901234], [], [], [54])
864 ## ----------------------- ##
865 ## Long test source lines. ##
866 ## ----------------------- ##
868 # Create a test file that has more than 99 words in a line, for Solaris awk.
869 # While at that, try out the limit of 2000 bytes in a text file line.
871 AT_CHECK_AT_TEST([Long test source lines],
872 [m4_for([nnn], [1], [999], [], [: ])
873 AT_CHECK([:])
874 ], [], [], [], [ignore], [],
875 [AT_CHECK([$CONFIG_SHELL ./micro-suite -k skipalltests], [], [ignore], [ignore])
879 ## ---------------- ##
880 ## Huge testsuite.  ##
881 ## ---------------- ##
883 # Ensure we don't hit line length limits with large test suites.
885 AT_CHECK_AT_TEST([Huge testsuite],
886 [m4_for([nnn], [1], [1999], [],
887 [AT_CLEANUP
888 AT_SETUP([test ]nnn)
890 ], [], [], [], [ignore], [], [], [1999])
893 ## ----------------- ##
894 ## Debugging a test. ##
895 ## ----------------- ##
897 AT_CHECK_AT_TEST([Debugging a successful test],
898   [AT_CHECK([:])], [], [], [], [ignore], [],
899 [# Without options, when all tests pass, no test directory should exist.
900 AT_CHECK([test -d micro-suite.dir/1 && exit 42
901           $CONFIG_SHELL ./micro-suite -d 1], [], [ignore], [ignore])
902 # Running with -d should leave a reproducible test group.
903 # Also, running the test script from the test group locks the
904 # directory from removal on some platforms; the script should still be
905 # able to run even if rmdir fails.
906 AT_CHECK([(cd micro-suite.dir/1 && ./run)], [], [ignore], [ignore])
907 # Running a debugging script implies -d.
908 AT_CHECK([(cd micro-suite.dir/1 && ./run)], [], [ignore], [ignore])
911 AT_CHECK_AT_TEST([Debugging script and environment],
912   [AT_CHECK([test "$MY_VAR" = pass || exit 42])],
913   [], [1], [], [ignore], [], [
914 # Changing environment outside of debugging script is not preserved.
915 AT_CHECK([(cd micro-suite.dir/1 && MY_VAR=pass ./run)],
916          [0], [ignore], [ignore])
917 AT_CHECK([(cd micro-suite.dir/1 && ./run)],
918          [1], [ignore], [ignore])
919 # Changing environment as argument to debugging script is preserved.
920 AT_CHECK([(cd micro-suite.dir/1; ./run MY_VAR=pass)],
921          [0], [ignore], [ignore])
922 AT_CHECK([(cd micro-suite.dir/1; ./run)],
923          [0], [ignore], [ignore])
926 # The run script must still be valid when shell metacharacters are passed
927 # in via an environment option.
928 AT_CHECK_AT_TEST([Debugging a failed test],
929   [AT_CHECK([test "$MY_VAR" = "one space" || exit 42])],
930   [], [1], [], [ignore], [], [
931 AT_CHECK([(cd micro-suite.dir/1 && ./run MY_VAR='two  spaces')],
932          [1], [ignore], [ignore])
933 AT_CHECK([(cd micro-suite.dir/1 && ./run MY_VAR='one space')],
934          [0], [ignore], [ignore])
938 # Setting default variable values via atlocal.
939 AT_CHECK_AT_TEST([Using atlocal],
940   [AT_CHECK([test "x$MY_VAR" = "xodd;  'string" || exit 42])],
941   [], [1], [ignore], [ignore], [], [
942 dnl check that command line can set variable
943 AT_CHECK([$CONFIG_SHELL ./micro-suite MY_VAR="odd;  'string"], [0], [ignore])
944 dnl check that command line overrides environment
945 AT_CHECK([MY_VAR="odd;  'string" $CONFIG_SHELL ./micro-suite MY_VAR=unset],
946          [1], [ignore], [ignore])
947 dnl check that atlocal can give it a default
948 AT_CHECK([cat <<EOF >atlocal
949 MY_VAR="odd;  'string"
950 export MY_VAR
951 dnl Also populate enough of atlocal to do what atconfig normally does.
952 at_testdir=.
953 abs_builddir='`pwd`'
954 at_srcdir=.
955 abs_srcdir='`pwd`'
956 at_top_srcdir=.
957 abs_top_srcdir='`pwd`'
958 at_top_build_prefix=
959 abs_top_builddir='`pwd`'
962 AT_CHECK([$CONFIG_SHELL ./micro-suite], [0], [ignore])
963 dnl check that atlocal overrides environment
964 AT_CHECK([MY_VAR=unset $CONFIG_SHELL ./micro-suite], [0], [ignore])
965 dnl check that command line overrides atlocal
966 AT_CHECK([$CONFIG_SHELL ./micro-suite MY_VAR=], [1], [ignore], [ignore])
967 dnl check that syntax error is detected
968 AT_CHECK([$CONFIG_SHELL ./micro-suite =], [1], [], [ignore], [ignore])
969 AT_CHECK([$CONFIG_SHELL ./micro-suite 1=2], [1], [], [ignore], [ignore])
973 # Controlling where the testsuite is run.
974 AT_CHECK_AT_TEST([Choosing where testsuite is run],
975   [AT_CHECK([:])], [], [], [], [], [], [
976 dnl AT_CHECK_AT_TEST tests the default of running in `.'.
977 AT_CHECK([$CONFIG_SHELL ./micro-suite --clean])
978 AT_CHECK([test -f micro-suite.log], [1])
979 AT_CHECK([test -d micro-suite.dir], [1])
980 AT_CHECK([mkdir sub1 sub2])
981 dnl check specifying a different relative path to run in.
982 AT_CHECK([$CONFIG_SHELL ./micro-suite -C sub1], [0], [ignore], [])
983 AT_CHECK([test -f micro-suite.log], [1])
984 AT_CHECK([test -f sub1/micro-suite.log], [0])
985 AT_CHECK([test -d micro-suite.dir], [1])
986 AT_CHECK([test -d sub1/micro-suite.dir], [0])
987 AT_CHECK([$CONFIG_SHELL ./micro-suite -C sub1 --clean])
988 AT_CHECK([test -f sub1/micro-suite.log], [1])
989 AT_CHECK([test -d sub1/micro-suite.dir], [1])
990 dnl check specifying an absolute path to run in.
991 AT_CHECK([$CONFIG_SHELL ./micro-suite --directory="`pwd`/sub2"],
992          [0], [ignore], [])
993 AT_CHECK([test -f micro-suite.log], [1])
994 AT_CHECK([test -f sub2/micro-suite.log], [0])
995 AT_CHECK([$CONFIG_SHELL ./micro-suite --clean --directory="`pwd`/sub2"])
996 AT_CHECK([test -f sub2/micro-suite.log], [1])
997 AT_CHECK([test -f sub2/micro-suite.dir], [1])
998 dnl check for failure detection with bad, missing, or empty directory.
999 AT_CHECK([$CONFIG_SHELL ./micro-suite -C nonesuch || exit 1], [1], [ignore], [ignore])
1000 AT_CHECK([$CONFIG_SHELL ./micro-suite -C ''], [1], [ignore], [ignore])
1001 AT_CHECK([$CONFIG_SHELL ./micro-suite -C - || exit 1], [1], [ignore], [ignore])
1002 AT_CHECK([$CONFIG_SHELL ./micro-suite -C], [1], [ignore], [ignore])
1003 dnl check that --help overrides bad directory selection.
1004 AT_CHECK([$CONFIG_SHELL ./micro-suite -C nonesuch --help], [0], [ignore], [])
1008 # --recheck.
1009 AT_CHECK_AT_TEST([recheck],
1010   [AT_CHECK([:])
1011    AT_CLEANUP
1012    AT_SETUP([failing test])
1013    AT_CHECK([exit 1])
1014    AT_CLEANUP
1015    AT_SETUP([xpassing test])
1016    AT_XFAIL_IF([:])
1017    AT_CHECK([:])
1018    AT_CLEANUP
1019    AT_SETUP([xfailing test])
1020    AT_XFAIL_IF([:])
1021    AT_CHECK([exit 1])
1022 ], [], [], [], [], [], [
1023 AT_CHECK([$CONFIG_SHELL ./micro-suite --recheck], [0], [stdout])
1024 AT_CHECK([grep "0 tests were successful" stdout], [0], [ignore])
1026 AT_CHECK([$CONFIG_SHELL ./micro-suite], [1], [ignore], [ignore])
1027 AT_CHECK([grep 'only test' micro-suite.log], [0], [ignore])
1028 AT_CHECK([$CONFIG_SHELL ./micro-suite --recheck], [1], [ignore], [ignore])
1029 AT_CHECK([grep 'only test' micro-suite.log], [1])
1030 AT_CHECK([grep 'xfailing' micro-suite.log], [1])
1031 AT_CHECK([grep 'failing test' micro-suite.log], [0], [ignore])
1032 AT_CHECK([grep 'xpassing test' micro-suite.log], [0], [ignore])
1034 AT_CHECK([$CONFIG_SHELL ./micro-suite --clean], [0])
1035 AT_CHECK([test -f micro-suite.log], [1])
1037 dnl check specifying a different relative path to run in.
1038 AT_CHECK([mkdir sub1])
1039 AT_CHECK([$CONFIG_SHELL ./micro-suite -C sub1], [1], [ignore], [ignore])
1040 AT_CHECK([test -f micro-suite.log], [1])
1041 AT_CHECK([test -f sub1/micro-suite.log], [0])
1042 AT_CHECK([$CONFIG_SHELL ./micro-suite -C sub1 --recheck --list], [0], [stdout])
1043 AT_CHECK([grep 'only test' stdout], [1])
1044 AT_CHECK([grep 'xfailing test' stdout], [1])
1045 AT_CHECK([grep 'failing test' stdout], [0], [ignore])
1046 AT_CHECK([grep 'xpassing test' stdout], [0], [ignore])
1047 AT_CHECK([$CONFIG_SHELL ./micro-suite -C sub1 --recheck], [1], [ignore],
1048          [ignore])
1049 AT_CHECK([grep 'failing test' sub1/micro-suite.log], [0], [ignore])
1050 AT_CHECK([grep 'xpassing test' sub1/micro-suite.log], [0], [ignore])
1051 ], [1 4])
1054 ## -------- ##
1055 ## Banners. ##
1056 ## -------- ##
1057 AT_SETUP([Banners])
1059 AT_CHECK_AT_PREP([b],
1060 [[AT_INIT
1061 AT_SETUP(zero)# 1
1062 AT_CHECK(:)
1063 AT_CLEANUP
1065 AT_BANNER([first])
1066 AT_SETUP(one a)# 2
1067 AT_CHECK(:)
1068 AT_CLEANUP
1069 AT_SETUP(one b)# 3
1070 AT_CHECK(:)
1071 AT_CLEANUP
1073 AT_BANNER()
1074 AT_SETUP(two a)# 4
1075 AT_CHECK(:)
1076 AT_CLEANUP
1077 AT_SETUP(two b)# 5
1078 AT_CHECK(:)
1079 AT_CLEANUP
1081 AT_BANNER([second])
1082 AT_SETUP(three a)# 6
1083 AT_CHECK(:)
1084 AT_CLEANUP
1085 AT_SETUP(three b)# 7
1086 AT_CHECK(:)
1087 AT_CLEANUP
1090 # AT_CHECK_BANNERS(TESTSUITE-OPTIONS, PATTERN1, COUNT1, PATTERN2, COUNT2)
1091 m4_define([AT_CHECK_BANNERS],
1092 [AT_CHECK([$CONFIG_SHELL ./b $1], [], [stdout])
1093 AT_CHECK_EGREP([$2], m4_if([$3], [0], [1], [0]), [$3])
1094 AT_CHECK_EGREP([$4], m4_if([$5], [0], [1], [0]), [$5])
1097 AT_CHECK_BANNERS([],            [first], [1], [second], [1])
1098 AT_CHECK_BANNERS([-k zero],     [first], [0], [second], [0])
1099 AT_CHECK_BANNERS([1],           [first], [0], [second], [0])
1100 AT_CHECK_BANNERS([-2],          [first], [1], [second], [0])
1101 AT_CHECK_BANNERS([-3],          [first], [1], [second], [0])
1102 AT_CHECK_BANNERS([-k one],      [first], [1], [second], [0])
1103 AT_CHECK_BANNERS([3-4],         [first], [1], [second], [0])
1104 dnl There should be an empty line separating the first category from the
1105 dnl unnamed one.
1106 AT_CHECK([sed -n '/one b/,/two a/p' stdout | grep '^$'], [0], [ignore])
1107 AT_CHECK_BANNERS([3-6],         [first], [1], [second], [1])
1108 AT_CHECK_BANNERS([4-6],         [first], [0], [second], [1])
1109 AT_CHECK_BANNERS([3-],          [first], [1], [second], [1])
1110 AT_CHECK_BANNERS([-k a],        [first], [1], [second], [1])
1111 AT_CHECK_BANNERS([4],           [first], [0], [second], [0])
1112 AT_CHECK_BANNERS([4-],          [first], [0], [second], [1])
1113 AT_CHECK_BANNERS([-k two],      [first], [0], [second], [0])
1114 AT_CHECK_BANNERS([1 4],         [first], [0], [second], [0])
1115 AT_CHECK_BANNERS([-k three],    [first], [0], [second], [1])
1116 AT_CHECK_BANNERS([5],           [first], [0], [second], [0])
1117 AT_CHECK_BANNERS([5-],          [first], [0], [second], [1])
1118 AT_CLEANUP
1121 ## --------- ##
1122 ## Keywords. ##
1123 ## --------- ##
1124 AT_SETUP([Keywords and ranges])
1126 AT_CHECK_AT_PREP([k],
1127 [[AT_INIT
1128 AT_SETUP(none) # 01
1129 AT_CHECK(:)
1130 AT_CLEANUP
1131 AT_SETUP(first) # 02
1132 AT_KEYWORDS(key1)
1133 AT_CHECK(:)
1134 AT_CLEANUP
1135 AT_SETUP(second) # 03
1136 AT_KEYWORDS(key2)
1137 AT_CHECK(:)
1138 AT_CLEANUP
1139 AT_SETUP(both) # 04
1140 AT_KEYWORDS([key1 key2])
1141 AT_KEYWORDS([m4_echo([Key1])])
1142 AT_CHECK(:)
1143 AT_CLEANUP
1144 AT_SETUP(test5) # 05
1145 AT_CHECK(:)
1146 AT_CLEANUP
1147 AT_SETUP(test6) # 06
1148 AT_CHECK(:)
1149 AT_CLEANUP
1150 AT_SETUP(test7) # 07
1151 AT_CHECK(:)
1152 AT_CLEANUP
1153 AT_SETUP(test8) # 08
1154 AT_CHECK(:)
1155 AT_CLEANUP
1156 AT_SETUP(test9) # 09
1157 AT_CHECK(:)
1158 AT_CLEANUP
1159 AT_SETUP(test10) # 10
1160 AT_CHECK(:)
1161 AT_CLEANUP
1163 dnl check that AT_KEYWORDS does not duplicate words
1164 AT_CHECK([grep -i 'key1.*key1' k], [1])
1165 dnl check that -k requires an argument
1166 AT_CHECK([$CONFIG_SHELL ./k -k], [1], [], [ignore])
1168 # AT_CHECK_KEYS(TESTSUITE-OPTIONS, PATTERN1, COUNT1, PATTERN2, COUNT2)
1169 m4_define([AT_CHECK_KEYS],
1170 [AT_CHECK([$CONFIG_SHELL ./k $1], 0, [stdout])
1171 AT_CHECK_EGREP([$2], 0, [$3])
1172 AT_CHECK_EGREP([$4], 1, [$5])
1175 AT_CHECK_KEYS([-k key1], [first|both], [2], [none|second], [0])
1176 AT_CHECK_KEYS([-k key2], [second|both], [2], [none|first], [0])
1177 AT_CHECK_KEYS([-k key1,key2], [both], [1], [none|first|second], [0])
1178 AT_CHECK_KEYS([-k key1 -k key2], [first|second|both], [3], [none], [0])
1179 AT_CHECK_KEYS([-k '!key1'], [none|second], [2], [first|both], [0])
1180 AT_CHECK_KEYS([-k '!key2'], [none|first], [2], [second|both], [0])
1181 AT_CHECK_KEYS([-k '!key1,key2'], [second], [1], [none|first|both], [0])
1182 AT_CHECK_KEYS([-k 'key1,!key2'], [first], [1], [none|second|both], [0])
1183 AT_CHECK_KEYS([-k '!key1,!key2'], [none], [1], [first|second|both], [0])
1184 AT_CHECK_KEYS([-k '!key1' -k KEY2], [none|second|both], [3], [first], [0])
1185 AT_CHECK_KEYS([-k key1 -k '!key2'], [none|first|both], [3], [second], [0])
1186 AT_CHECK_KEYS([-k '!KEY1' -k '!key2'], [none|first|second], [3], [both], [0])
1188 AT_CHECK_KEYS([-k none], [none], [1], [first|second|both], [0])
1189 AT_CHECK_KEYS([-k key1,both], [both], [1], [none|first|second], [0])
1190 AT_CHECK_KEYS([-k key1 -k both], [first|both], [2], [none|second], [0])
1191 AT_CHECK_KEYS([-k none,first], [successful], [1], [none|first|second|both], [0])
1192 AT_CHECK_KEYS([-k none,first,second,both], [successful], [1], [none|first|second|both], [0])
1193 AT_CHECK_KEYS([-k !none,first], [first], [1], [none|second|both], [0])
1195 AT_CHECK_KEYS([-k '.*eco.*'], [second], [1], [none|first|both], [0])
1196 AT_CHECK_KEYS([-k 'ECO'], [successful], [1], [none|first|second|both], [0])
1197 AT_CHECK_KEYS([-k '.*eco'], [successful], [1], [none|first|second|both], [0])
1198 AT_CHECK_KEYS([-k 'eco.*'], [successful], [1], [none|first|second|both], [0])
1199 AT_CHECK_KEYS([-k 'fir.*'], [first], [1], [none|second|both], [0])
1201 AT_CHECK_KEYS([1-2], [none|first], [2], [second|both], [0])
1202 AT_CHECK_KEYS([01-002 08], [none|first], [2], [second|both], [0])
1203 AT_CHECK_KEYS([1-3 2-1], [none|first|second], [3], [both], [0])
1204 AT_CHECK_KEYS([-3], [none|first|second], [3], [both], [0])
1205 AT_CHECK_KEYS([4-], [both], [1], [none|first|second], [0])
1206 AT_CHECK_KEYS([010], [test10], [1], [none|first|second|both], [0])
1207 AT_CHECK_KEYS([-k second 4-], [second|both], [2], [none|first], [0])
1209 AT_CHECK([$CONFIG_SHELL ./k 0], [1], [ignore], [ignore])
1210 AT_CHECK([$CONFIG_SHELL ./k 0-], [1], [ignore], [ignore])
1211 AT_CHECK([$CONFIG_SHELL ./k -0], [1], [ignore], [ignore])
1212 AT_CHECK([$CONFIG_SHELL ./k 11], [1], [ignore], [ignore])
1213 AT_CHECK([$CONFIG_SHELL ./k 11-], [1], [ignore], [ignore])
1214 AT_CHECK([$CONFIG_SHELL ./k 1-011], [1], [ignore], [ignore])
1215 AT_CHECK([$CONFIG_SHELL ./k -k nonexistent], [0], [ignore])
1217 AT_CHECK_KEYS([--list -k nonexistent], [KEYWORDS], [1], [first|second|both], [0])
1218 AT_CHECK_KEYS([--list 1], [none], [1], [first|second|both], [0])
1219 AT_CHECK_KEYS([--list 01], [none], [1], [first|second|both], [0])
1220 AT_CHECK_KEYS([--list -k none -k first], [none|first], [2], [second|both], [0])
1221 AT_CLEANUP
1224 ## ----------------- ##
1225 ## Keyword wrapping. ##
1226 ## ----------------- ##
1227 AT_SETUP([Keyword wrapping])
1229 AT_CHECK_AT_PREP([k],
1230 [[AT_INIT
1231 AT_SETUP([test])
1232 AT_KEYWORDS([a1 b1 c1 d1 e1 f1 g1 h1 i1 j1 k1 l1 m1 n1 o1 p1 q1 r1 s1 t1])
1233 AT_KEYWORDS([u1 v1 w1 x1 y1 z1])
1234 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])
1235 AT_CLEANUP
1236 AT_SETUP([test with long keywords])
1237 AT_KEYWORDS(
1238 [this-is-a-long-keyword-that-cannot-be-wrapped-so-we-exceed-the-length-limit-here])
1239 # surrounded by short ones
1240 AT_KEYWORDS([s])
1241 AT_KEYWORDS(
1242 [another-very-long-keyword-that-hits-the-line-length-limit-bla-bla-bla-bla])
1243 AT_KEYWORDS([t])
1244 AT_CLEANUP
1247 AT_CHECK_KEYS([-l], [.{80}], [1], [.{87}], [0])
1249 AT_CLEANUP
1252 ## ------------- ##
1253 ## AT_ARG_OPTION ##
1254 ## ------------- ##
1256 AT_CHECK_AT([AT@&t@_ARG_OPTION],
1258 AT_INIT([artificial test suite])
1259 AT_ARG_OPTION([frob fro fr f],
1260               [AS_HELP_STRING([-f, --frob], [frobnicate the test run])],
1261               [frob=$at_optarg], [frob=default])
1262 AT_ARG_OPTION([opt-with-hyphen],
1263               [AS_HELP_STRING([--opt-with-hyphen], [option name with hypen])])
1264 AT_ARG_OPTION([ping],
1265               [AS_HELP_STRING([--ping], [ping on every encounter])],
1266               [echo ping])
1267 AT_SETUP([test argument handling])
1268 AT_CHECK([test "$frob" = "$FROB"])
1269 AT_CHECK([test "$at_arg_frob" = "$FROB_ARG"])
1270 AT_CLEANUP
1271 AT_SETUP([test hyphen normalization])
1272 AT_CHECK([test "$at_arg_opt_with_hyphen" = "$expected"])
1273 AT_CLEANUP
1275 [], [], [stdout], [], [],
1276 [# We already invoked --help.
1277 AT_CHECK([grep '  -f, --frob.*frobnicate' stdout], [], [ignore])
1278 for args in \
1279   '1 FROB=default FROB_ARG=false' \
1280   '1 -f FROB=: FROB_ARG=:' \
1281   '1 --fr FROB=: FROB_ARG=:' \
1282   '1 --fro FROB=: FROB_ARG=:' \
1283   '1 --frob FROB=: FROB_ARG=:' \
1284   '1 --no-f FROB=false FROB_ARG=false' \
1285   '1 --no-fr FROB=false FROB_ARG=false' \
1286   '1 --no-fro FROB=false FROB_ARG=false' \
1287   '1 --no-frob FROB=false FROB_ARG=false' \
1288   '2 expected=false' \
1289   '2 --opt-with-hyphen expected=:' \
1290   '2 --no-opt-with-hyphen expected=false'
1292   AT_CHECK([$CONFIG_SHELL ./micro-suite -x $args], [], [ignore])
1293 done
1294 AT_CHECK([$CONFIG_SHELL ./micro-suite 2 --ping --no-ping --ping expected=false],
1295          [], [stdout])
1296 AT_CHECK([grep -c ping stdout], [], [[3
1298 ], [--help])
1301 ## ----------------- ##
1302 ## AT_ARG_OPTION_ARG ##
1303 ## ----------------- ##
1305 AT_CHECK_AT([AT@&t@_ARG_OPTION_ARG],
1307 AT_INIT([artificial test suite])
1308 AT_ARG_OPTION_ARG([frob fro fr f],
1309                   [AS_HELP_STRING([-f, --frob=FOO], [frobnicate FOO])],
1310                   [frob=$at_optarg], [frob=default])
1311 AT_ARG_OPTION_ARG([opt-with-hyphen],
1312                   [AS_HELP_STRING([--opt-with-hyphen=ARG],
1313                                   [option name with hypen])])
1314 AT_ARG_OPTION_ARG([ping],
1315                   [AS_HELP_STRING([--ping], [ping on every encounter])],
1316                   [echo ping])
1317 AT_SETUP([test argument handling])
1318 AT_CHECK([test "$frob" = "$FROB"])
1319 AT_CHECK([test "$at_arg_frob" = "$FROB_ARG"])
1320 AT_CLEANUP
1321 AT_SETUP([test hyphen normalization])
1322 AT_CHECK([test "$at_arg_opt_with_hyphen" = "$expected"])
1323 AT_CLEANUP
1325 [], [], [stdout], [], [],
1326 [# We already invoked --help.
1327 AT_CHECK([grep '  -f, --frob.*frobnicate' stdout], [], [ignore])
1328 AT_CHECK([$CONFIG_SHELL ./micro-suite -x --frob], [1], [ignore], [stderr])
1329 AT_CHECK([grep 'requires an argument' stderr], [], [ignore])
1330 AT_CHECK([$CONFIG_SHELL ./micro-suite -x --no-frob], [1], [ignore], [stderr])
1331 AT_CHECK([grep 'invalid option' stderr], [], [ignore])
1332 for args in \
1333   '1 FROB=default FROB_ARG=' \
1334   '1 -f bar FROB=bar FROB_ARG=bar' \
1335   '1 --fr bar FROB=bar FROB_ARG=bar' \
1336   '1 --fro bar FROB=bar FROB_ARG=bar' \
1337   '1 --frob bar FROB=bar FROB_ARG=bar' \
1338   '1 -f=bar FROB=bar FROB_ARG=bar' \
1339   '1 --fr=bar FROB=bar FROB_ARG=bar' \
1340   '1 --fro=bar FROB=bar FROB_ARG=bar' \
1341   '1 --frob=bar FROB=bar FROB_ARG=bar' \
1342   '2 expected=' \
1343   '2 --opt-with-hyphen=baz expected=baz'
1345   AT_CHECK([$CONFIG_SHELL ./micro-suite -x $args], [], [ignore])
1346 done
1347 AT_CHECK([$CONFIG_SHELL ./micro-suite 2 --ping=1 --ping=2 expected=],
1348          [], [stdout])
1349 AT_CHECK([grep -c ping stdout], [], [[2
1351 ], [--help])
1354 m4_define([AT_SKIP_PARALLEL_TESTS],
1355 [# Per BUGS, we have not yet figured out how to run parallel tests cleanly
1356 # under dash and some ksh variants.  For now, only run this test under
1357 # limited conditions; help is appreciated in widening this test base.
1358 AT_SKIP_IF([${CONFIG_SHELL-$SHELL} -c 'test -z "${BASH_VERSION+set}]]dnl
1359 [[${ZSH_VERSION+set}${TEST_PARALLEL_AUTOTEST+set}"'])
1360 # The parallel scheduler requires mkfifo and job control to work.
1361 AT_CHECK([mkfifo fifo || exit 77])
1362 AT_CHECK([${CONFIG_SHELL-$SHELL} -c '(set -m && set +m) || exit 77'],
1363          [], [], [ignore])
1367 ## ----------------------- ##
1368 ## parallel test execution ##
1369 ## ----------------------- ##
1371 AT_SETUP([parallel test execution])
1373 # This test tries to ensure that -j runs tests in parallel.
1374 # Such a test is inherently racy, because there are no real-time
1375 # guarantees about scheduling delays.  So we try to minimize
1376 # the chance to lose the race.
1378 # The time needed for a micro-suite consisting of NTESTS tests each
1379 # sleeping for a second is estimated by
1380 #   startup + ntests * (serial_overhead + 1 / njobs)
1382 # in absence of major scheduling delays.  This leads to side conditions:
1383 # - NTESTS should be high, so the STARTUP time is small compared to the
1384 #   test run time, and scheduling delays can even out; it should not be
1385 #   too high, to not slow down the testsuite unnecessarily,
1386 # - the number of concurrent jobs NJOBS should not be too low, so the
1387 #   race is not lost so easily; it should not be too high, to avoid fork
1388 #   failures on tightly limited systems.  4 seems a good compromise
1389 #   here, considering that Autotest spawns several other processes.
1390 # - STARTUP is assumed to be the same for parallel and serial runs, so
1391 #   the latter can estimate the former.
1392 # - To avoid unportable output from time measurement commands, spawn
1393 #   both a parallel and a serial testsuite run; check that the former
1394 #   completes before the latter has completed a fraction SERIAL_NTESTS
1395 #   of the tests (the serial run is executed in a subdirectory), plus
1396 #   some additional time to allow for compensation of SERIAL_OVERHEAD.
1397 # - when adding this time to the serial test execution, an initial delay
1398 #   SERIAL_DELAY of the serial test helps to avoid unreliable scheduling
1399 #   due to the startup burst of the suites.
1401 dnl total number of tests.
1402 m4_define([AT_PARALLEL_NTESTS], [16])
1403 dnl number of jobs to run in parallel.
1404 m4_define([AT_PARALLEL_NJOBS], [4])
1405 dnl number of tests to run serially, as comparison.
1406 m4_define([AT_PARALLEL_SERIAL_NTESTS],
1407   m4_eval(AT_PARALLEL_NTESTS / AT_PARALLEL_NJOBS))
1408 dnl initial delay of serial run, to compensate for SERIAL_OVERHEAD.
1409 dnl This corresponds to 0.67 s of overhead per test.
1410 m4_define([AT_PARALLEL_SERIAL_DELAY],
1411   m4_eval((AT_PARALLEL_NTESTS - AT_PARALLEL_SERIAL_NTESTS + 1) * 2 / 3))
1414 AT_CHECK_AT_PREP([micro-suite],
1415 [[AT_INIT([suite to test parallel execution])
1416 m4_for([count], [1], ]]AT_PARALLEL_NTESTS[[, [],
1417    [AT_SETUP([test number count])
1418     AT_CHECK([sleep 1])
1419     AT_CLEANUP
1423 # Even if parallel jobs are not supported, the command line must work.
1424 AT_CHECK([$CONFIG_SHELL ./micro-suite --help | grep " --jobs"], [0], [ignore])
1425 AT_CHECK([$CONFIG_SHELL ./micro-suite -j2foo], [1], [], [stderr])
1426 AT_CHECK([grep 'non-numeric argument' stderr], [], [ignore])
1427 AT_CHECK([$CONFIG_SHELL ./micro-suite --jobs=foo], [1], [], [stderr])
1428 AT_CHECK([grep 'non-numeric argument' stderr], [], [ignore])
1430 AT_SKIP_PARALLEL_TESTS
1432 # Ensure that all tests run, and lines are not split.
1433 AT_CHECK([$CONFIG_SHELL ./micro-suite -j[]AT_PARALLEL_NJOBS], [], [stdout])
1434 AT_CHECK([grep -c '^.\{53\}ok' stdout], [], [AT_PARALLEL_NTESTS
1436 # Running one test with -j should produce correctly formatted output:
1437 AT_CHECK([$CONFIG_SHELL ./micro-suite -j 3], [], [stdout])
1438 AT_CHECK([grep -c '^.\{53\}ok' stdout], [], [1
1440 # Specifying more jobs than tests should not hang:
1441 AT_CHECK([$CONFIG_SHELL ./micro-suite -j3 3], [], [stdout])
1442 AT_CHECK([grep -c '^.\{53\}ok' stdout], [], [1
1444 # Not even with zero tests:
1445 AT_CHECK([$CONFIG_SHELL ./micro-suite -j -k nomatch], [], [ignore])
1446 AT_CHECK([$CONFIG_SHELL ./micro-suite -j3 -k nomatch], [], [ignore])
1448 mkdir serial
1450 # Unfortunately, the return value of wait is unreliable,
1451 # so we check that kill fails.
1452 AT_CHECK([$CONFIG_SHELL ./micro-suite --jobs=[]AT_PARALLEL_NJOBS & ]dnl
1453          [sleep AT_PARALLEL_SERIAL_DELAY && ]dnl
1454          [cd serial && $CONFIG_SHELL ../micro-suite -AT_PARALLEL_SERIAL_NTESTS >/dev/null && ]dnl
1455          [{ kill $! && exit 1; :; }], [], [stdout], [ignore])
1456 AT_CHECK([grep -c '^.\{53\}ok' stdout], [], [AT_PARALLEL_NTESTS
1458 AT_CHECK([grep 'AT_PARALLEL_NTESTS tests' stdout], [], [ignore])
1460 AT_CLEANUP
1462 AT_CHECK_AT_TEST([parallel truth],
1463   [AT_CHECK([:], 0, [], [])],
1464   [], [], [], [], [AT_SKIP_PARALLEL_TESTS],
1465   [], [-j])
1467 AT_CHECK_AT_TEST([parallel fallacy],
1468   [AT_CHECK([false], [], [], [])],
1469   [], [1], [], [ignore], [AT_SKIP_PARALLEL_TESTS],
1470   [AT_CHECK([grep failed micro-suite.log], [], [ignore])], [-j])
1472 AT_CHECK_AT_TEST([parallel skip],
1473   [AT_CHECK([echo output; echo irrelevant >&2; exit 77], 0, [mismatch], [])],
1474   [], [], [], [], [AT_SKIP_PARALLEL_TESTS],
1475   [AT_CHECK([grep skipped micro-suite.log], [], [ignore])], [-j])
1477 AT_CHECK_AT_TEST([parallel syntax error],
1478   [AT_CHECK([:])
1479    AT_CLEANUP
1480    AT_SETUP([syntax])
1481    AT_CHECK([if])
1482    AT_CLEANUP
1483    AT_SETUP([another test])
1484    AT_CHECK([:])],
1485   [], [0], [], [], [AT_SKIP_PARALLEL_TESTS],
1486   [dnl Until we can find a way to avoid catastrophic failure (ash) or
1487    dnl lack of failure (zsh), skip the rest of this test on such shells.
1488    echo 'if' > syntax
1489    AT_CHECK([${CONFIG_SHELL-$SHELL} -c 'case `. ./syntax; echo $?` in
1490                   0|"") exit 77;;
1491                 esac'], [0], [ignore], [ignore])
1492    AT_CHECK([$CONFIG_SHELL ./micro-suite -j], [1], [ignore], [stderr])
1493    AT_CHECK([grep "unable to parse test group: 2" stderr], [0], [ignore])],
1494   [-j2 1 3])
1496 AT_CHECK_AT_TEST([parallel errexit],
1497   [AT_CHECK([false])
1498    AT_CLEANUP
1499    AT_SETUP([barrier test])
1500    AT_CHECK([sleep 4])
1501    AT_CLEANUP
1502    AT_SETUP([test that should not be run])
1503    AT_CHECK([:])],
1504   [], [1], [stdout], [stderr], [AT_SKIP_PARALLEL_TESTS],
1505   [AT_CHECK([test -f micro-suite.log], [1])
1506    touch micro-suite.log # shut up AT_CAPTURE_FILE.
1507    AT_CHECK([grep "should not be run" stdout], [1])
1508    AT_CHECK([grep "[[12]] .* inhibited subsequent" stderr], [], [ignore])],
1509   [-j2 --errexit])
1512 AT_SETUP([parallel autotest and signal handling])
1514 AT_SKIP_PARALLEL_TESTS
1516 # Goals:
1517 # (1) interrupt `./testsuite -jN'
1518 # (2) interrupt `make check TESTSUITEFLAGS=-jN'
1519 # (3) no trailing verbose/trace output
1520 # (4) exit status should be 128+signal
1522 AT_DATA([atlocal],
1523 [[suite_pid=$$
1524 export suite_pid
1527 AT_CHECK_AT_PREP([micro-suite],
1528 [[AT_INIT([suite to test parallel execution])
1529 AT_SETUP([test number 1])
1530 AT_CHECK([sleep 2])
1531 AT_CLEANUP
1532 AT_SETUP([test number 2])
1533 AT_CHECK([sleep 1])
1534 AT_CLEANUP
1535 AT_SETUP([test number 3])
1536 AT_CHECK([sleep 1])
1537 AT_CLEANUP
1538 AT_SETUP([killer test])
1539 AT_CHECK([kill -$signal $suite_pid])
1540 AT_CLEANUP
1541 m4_for([count], [5], [7], [],
1542    [AT_SETUP([test number count])
1543     AT_CHECK([sleep 1])
1544     AT_CLEANUP
1548 AT_DATA([Makefile.in],
1549 [[@SET_MAKE@
1550 SHELL = @SHELL@
1551 TESTSUITE = ./micro-suite
1552 check:
1553         $(SHELL) '$(TESTSUITE)' $(TESTSUITEFLAGS)
1554 .PHONY: check
1557 AT_CHECK([$CONFIG_SHELL $abs_top_builddir/config.status --file=Makefile:Makefile.in],
1558          [], [ignore])
1560 # Test INT and TERM.
1561 for signal in 2 15; do
1562   export signal
1563   AS_VAR_ARITH([expected_status], [128 + $signal])
1565   # Sequential case.
1566   AT_CHECK([$CONFIG_SHELL ./micro-suite], [$expected_status],
1567            [ignore], [stderr])
1568   # Both stderr and the log should contain the notification about the signal.
1569   AT_CHECK([grep 'bailing out' stderr], [], [ignore])
1570   AT_CHECK([grep 'bailing out' micro-suite.log], [], [ignore])
1571   # There should be no junk job status output.
1572   AT_CHECK([[grep '[iI]nterrupt[         ]' stderr]], [1])
1574   # Parallel case.
1575   AT_CHECK([$CONFIG_SHELL ./micro-suite --jobs=3], [$expected_status],
1576            [ignore], [stderr])
1577   AT_CHECK([grep 'bailing out' stderr], [], [ignore])
1578   AT_CHECK([grep 'bailing out' micro-suite.log], [], [ignore])
1579   # We'd like to check this here, too, but some shells do not allow to
1580   # turn off job control.
1581   # AT_CHECK([[grep '[iI]nterrupt[       ]' stderr]], [1])
1583   # Ditto with `make' in the loop.
1584   : "${MAKE=make}"
1585   unset MAKEFLAGS
1586   # Need to eliminate outer TESTSUITEFLAGS here.
1587   # Need to normalize exit status here: some make implementations
1588   # exit 1 (BSD make), some exit 2 (GNU make).
1589   AT_CHECK([$MAKE check TESTSUITEFLAGS=; ]dnl
1590            [case $? in 1|2) exit 1;; *) exit $?;; esac],
1591            [1], [ignore], [stderr])
1592   AT_CHECK([grep 'bailing out' stderr], [], [ignore])
1593   AT_CHECK([grep 'bailing out' micro-suite.log], [], [ignore])
1594   # Ditto, parallel case.
1595   AT_CHECK([$MAKE check TESTSUITEFLAGS=--jobs=3; ]dnl
1596            [case $? in 1|2) exit 1;; *) exit $?;; esac],
1597            [1], [ignore], [stderr])
1598   AT_CHECK([grep 'bailing out' stderr], [], [ignore])
1599   AT_CHECK([grep 'bailing out' micro-suite.log], [], [ignore])
1600 done
1603 # Test PIPE.
1604 # The most important part here is that things should not hang, nor
1605 # get out of hand.  OTOH, if the shell sets the default handler to
1606 # ignore PIPE (pdksh, dash), there is little we can do about having the
1607 # test run; it's only the output that won't be there.  So all we check
1608 # for is that, if test 7 didn't run serially, then it shouldn't be
1609 # run in the parallel case either; the intermediate tests serve as
1610 # parallel barrier.
1611 # Note that stderr may contain "Broken pipe" errors.
1612 AT_CHECK([($CONFIG_SHELL ./micro-suite -d -3 5-; echo $? >status) | sed 5q],
1613          [], [stdout], [stderr])
1614 AT_CHECK([grep '5.*ok' stdout], [1])
1615 # Apparently some shells don't get around to creating 'status' any more.
1616 # And ksh93 on FreeBSD uses 256 + 13 instead of 128 + 13
1617 AT_CHECK([test ! -s status || grep 141 status || grep 269 status],
1618          [], [ignore])
1619 AT_CHECK([if test -f micro-suite.dir/7/micro-suite.log; then ]dnl
1620          [  echo "shell ignores SIGPIPE" > sigpipe-stamp ]dnl
1621          [else :; fi])
1623 AT_CHECK([$CONFIG_SHELL ./micro-suite -d -3 5- --jobs=2 | sed 5q], [], [stdout], [ignore])
1624 AT_CHECK([grep '5.*ok' stdout], [1])
1625 AT_CHECK([test -s sigpipe-stamp || test ! -f micro-suite.dir/7/micro-suite.log], [0])
1627 AT_CLEANUP
1630 # Avoid running into a regression when mkfifo does not work.
1631 AT_CHECK_AT_TEST([parallel args but non-working mkfifo],
1632 [AT_CHECK([:])
1633 AT_CLEANUP
1634 AT_SETUP([second test])
1635 AT_CHECK([:])
1637 [], [], [stdout], [stderr],
1638 [AT_SKIP_PARALLEL_TESTS
1639 mkdir bin
1640 cat >bin/mkfifo <<\EOF
1641 #! /bin/sh
1642 exit 1
1644 chmod +x bin/mkfifo
1645 PATH=`pwd`/bin:$PATH
1646 export PATH
1648 [AT_CHECK([grep 'second test' stdout], [], [ignore])
1649 ], [--jobs])
1652 # --color
1653 AT_CHECK_AT_TEST([colored test results],
1654   [AT_CHECK([:])
1655    AT_CLEANUP
1656    AT_SETUP([fail])
1657    AT_CHECK([exit 1])
1658    AT_CLEANUP
1659    AT_SETUP([xpass])
1660    AT_XFAIL_IF([:])
1661    AT_CHECK([:])
1662    AT_CLEANUP
1663    AT_SETUP([xfail])
1664    AT_XFAIL_IF([:])
1665    AT_CHECK([exit 1])
1666    AT_CLEANUP
1667    AT_SETUP([skip])
1668    AT_CHECK([exit 77])
1669    AT_CLEANUP
1670    AT_SETUP([hardfail])
1671    AT_XFAIL_IF([:])
1672    AT_CHECK([exit 99])
1673 ], [], [], [], [], [], [
1675 TERM=ansi
1676 export TERM
1678 red=`printf '\033@<:@0;31m'`
1679 grn=`printf '\033@<:@0;32m'`
1680 lgn=`printf '\033@<:@1;32m'`
1681 blu=`printf '\033@<:@1;34m'`
1682 std=`printf '\033@<:@m'`
1684 # Check that grep can parse nonprinting characters.
1685 # BSD 'grep' works from a pipe, but not a seekable file.
1686 # GNU or BSD 'grep -a' works on files, but is not portable.
1687 AT_CHECK([case `echo "$std" | grep .` in #'' restore font-lock
1688             $std) :;;
1689             *) exit 77;;
1690           esac], [], [ignore], [],
1691          [echo "grep can't parse nonprinting characters" >&2])
1693 if echo 'ab*c' | grep -F 'ab*c' >/dev/null 2>&1; then
1694   FGREP="grep -F"
1695 else
1696   FGREP=fgrep
1699 # No color.
1700 AT_CHECK([$CONFIG_SHELL ./micro-suite], [1], [stdout], [stderr])
1701 for color in "$red" "$grn" "$lgn" "$blu"; do
1702   AT_CHECK([cat stdout stderr | $FGREP "$color"], [1])
1703 done
1705 # Color of test group results.
1706 AT_CHECK([$CONFIG_SHELL ./micro-suite --color=always], [1], [stdout], [stderr])
1707 AT_CHECK([cat stdout | grep " only " | $FGREP "$grn"], [], [ignore])
1708 AT_CHECK([cat stdout | grep " fail " | $FGREP "$red"], [], [ignore])
1709 AT_CHECK([cat stdout | grep " xfail " | $FGREP "$lgn"], [], [ignore])
1710 AT_CHECK([cat stdout | grep " xpass " | $FGREP "$red"], [], [ignore])
1711 AT_CHECK([cat stdout | grep " skip " | $FGREP "$blu"], [], [ignore])
1712 AT_CHECK([cat stdout | grep " hardfail " | $FGREP "$red"], [], [ignore])
1713 AT_CHECK([cat stderr | grep ERROR | $FGREP "$red"], [], [ignore])
1715 # The summary is green if all tests were successful, light green if all
1716 # behaved as expected, and red otherwise.
1717 AT_CHECK([$CONFIG_SHELL ./micro-suite --color=always 1 -k skip],
1718          [0], [stdout])
1719 AT_CHECK([cat stdout | grep 'test.*successful' | $FGREP "$grn"],
1720          [], [ignore])
1721 AT_CHECK([$CONFIG_SHELL ./micro-suite --color=always 1 -k xfail -k skip],
1722          [0], [stdout])
1723 AT_CHECK([cat stdout | grep 'as expected' | $FGREP "$lgn"], [], [ignore])
1724 AT_CHECK([$CONFIG_SHELL ./micro-suite --color=always -k fail],
1725          [1], [ignore], [stderr])
1726 AT_CHECK([cat stderr | grep ERROR | $FGREP "$red"], [], [ignore])
1727 AT_CHECK([$CONFIG_SHELL ./micro-suite --color=always -k xpass],
1728          [1], [ignore], [stderr])
1729 AT_CHECK([cat stderr | grep ERROR | $FGREP "$red"], [], [ignore])
1730 AT_CHECK([$CONFIG_SHELL ./micro-suite --color=always -k hardfail],
1731          [1], [ignore], [stderr])
1732 AT_CHECK([cat stderr | grep ERROR | $FGREP "$red"], [], [ignore])
1733 # Reset color on verbose output.
1734 printf %s\\n "$std"
1735 ], [1])
1738 ## ------------------- ##
1739 ## srcdir propagation. ##
1740 ## ------------------- ##
1742 AT_SETUP([srcdir propagation])
1744 mkdir pkg vpath-outside vpath-abs
1745 mkdir pkg/t pkg/vpath-inside
1746 AT_DATA([pkg/a])
1747 AT_DATA([pkg/t/b])
1749 AT_DATA([pkg/configure.ac], [[AC_INIT
1750 AC_CONFIG_TESTDIR([t])
1751 AC_OUTPUT
1753 cp "$abs_top_srcdir/build-aux/install-sh" pkg
1755 cd pkg
1756 AT_CHECK_AUTOCONF
1757 cd ..
1759 AT_CHECK_AT_PREP([suite],
1760 [[AT_INIT([suite to check srcdir])
1761 AT_SETUP([my only test])
1762 AT_CHECK([test -f "$top_srcdir"/a && test -f "$srcdir"/b])
1763 AT_CLEANUP
1764 ]], [], [], [], [pkg/t])
1766 rm -f pkg/t/atconfig
1768 # Build directory totally outside source directory.
1769 cd vpath-outside
1770 AT_CHECK([../pkg/configure $configure_options], [0], [ignore])
1771 cd t
1772 AT_CHECK([../../pkg/t/suite], [0], [ignore])
1773 AT_CHECK([../../pkg/t/suite -v], [0], [stdout])
1774 AT_CHECK([grep '^\.\./\.\./pkg/t/suite.at' stdout], [0], [ignore])
1775 cd ../..
1777 # Build directory totally outside source directory (absolute).
1778 my_srcdir=`pwd`/pkg
1779 cd vpath-abs
1780 AT_CHECK(["$my_srcdir"/configure $configure_options], [0], [ignore])
1781 cd t
1782 AT_CHECK(["$my_srcdir"/t/suite], [0], [ignore])
1783 AT_CHECK(["$my_srcdir"/t/suite -v], [0], [stdout])
1784 AT_CHECK([grep '..*/t/suite.at' stdout], [0], [ignore])
1785 cd ../..
1787 # Build directory as subdirectory of source directory.
1788 cd pkg/vpath-inside
1789 AT_CHECK([../configure $configure_options], [0], [ignore])
1790 cd t
1791 AT_CHECK([../../t/suite], [0], [ignore])
1792 AT_CHECK([../../t/suite -v], [0], [stdout])
1793 AT_CHECK([grep '^\.\./\.\./t/suite.at' stdout], [0], [ignore])
1794 cd ../../..
1796 # Build directory as parent of source directory.
1797 AT_CHECK([pkg/configure $configure_options], [0], [ignore])
1798 cd t
1799 AT_CHECK([../pkg/t/suite], [0], [ignore])
1800 AT_CHECK([../pkg/t/suite -v], [0], [stdout])
1801 AT_CHECK([grep '^\.\./pkg/t/suite.at' stdout], [0], [ignore])
1802 cd ..
1804 # Build directory as source directory.
1805 cd pkg
1806 AT_CHECK_CONFIGURE
1807 cd t
1808 AT_CHECK([./suite], [0], [ignore])
1809 AT_CHECK([./suite -v], [0], [stdout])
1810 AT_CHECK([grep '^\./suite.at' stdout], [0], [ignore])
1811 cd ../..
1813 AT_CLEANUP
1816 ## ------------------------------ ##
1817 ## whitespace in absolute testdir ##
1818 ## ------------------------------ ##
1820 AT_SETUP([whitespace in absolute testdir])
1822 dir='dir with  whitespace'
1823 mkdir "$dir"
1824 cd "$dir"
1825 wd=`pwd`
1827 AT_DATA([a])
1828 AT_CHECK_AT_PREP([suite],
1829 [[AT_INIT([suite to check srcdir])
1830 AT_SETUP([my only test])
1831 AT_CHECK([test -f "$top_srcdir"/a])
1832 AT_CLEANUP
1834 AT_CHECK([top_srcdir=$wd ./suite], [0], [ignore])
1835 AT_CHECK([top_srcdir=$wd ./suite -d], [0], [ignore])
1836 AT_CHECK([cd suite.dir/1 && ./run top_srcdir="$wd"], [0], [ignore], [ignore])
1837 AT_CLEANUP
1840 ## ------------------ ##
1841 ## unusual file names ##
1842 ## ------------------ ##
1844 AT_SETUP([unusual file names])
1846 AT_DATA_AUTOTEST([d@&t@nl.at],
1847 [[AT_SETUP([test one])
1848 m4_pattern_allow([^dnl$])
1849 AT_CHECK([test "]m4_dquote(AT_LINE)[" = dn[]l.at:3])
1850 AT_CLEANUP
1853 mkdir sub
1854 AT_DATA_AUTOTEST([sub/"two  spaces".at],
1855 [[AT_SETUP([test two])
1856 AT_CHECK([test "]m4_dquote(AT_LINE)[" = "two  spaces.at:2"])
1857 AT_CLEANUP
1860 AT_CHECK_AT_PREP([suite],
1861 [[AT_INIT([suite to check included file names])
1862 m4_include([d][nl.at])
1863 m4_include([sub/two  spaces.at])
1865 AT_CHECK([$CONFIG_SHELL ./suite], [0], [stdout])
1866 AT_CHECK([grep 'two spaces' suite.log], [1])
1867 AT_CLEANUP
1870 ## ------------------------- ##
1871 ## Erlang EUnit unit tests.  ##
1872 ## ------------------------- ##
1874 AT_SETUP([Erlang Eunit unit tests])
1875 AT_KEYWORDS([Erlang])
1877 mkdir s t
1878 AT_DATA([configure.ac], [[AC_INIT
1879 AC_ERLANG_PATH_ERL([no])
1880 AC_ERLANG_PATH_ERLC([no])
1881 if test "$ERL" = "no" || test "$ERLC" = "no"; then
1882   HAVE_ERLANG=no
1883   HAVE_EUNIT=no
1884 else
1885   HAVE_ERLANG=yes
1886   AC_ERLANG_CHECK_LIB([eunit], [HAVE_EUNIT=yes], [HAVE_EUNIT=no])
1888 AC_SUBST([HAVE_ERLANG])
1889 AC_SUBST([HAVE_EUNIT])
1891 AC_CONFIG_TESTDIR([t])
1892 AC_CONFIG_FILES([s/compile], [chmod +x s/compile])
1893 AC_CONFIG_FILES([erlang.conf])
1894 AC_OUTPUT
1897 # File to pass info back to us
1898 AT_DATA([erlang.conf.in],
1899 [[HAVE_ERLANG=@HAVE_ERLANG@
1900 HAVE_EUNIT=@HAVE_EUNIT@
1903 # Erlang module to test:
1904 AT_DATA([s/testme.erl],
1905 [[-module(testme).
1906 -export([foo/1]).
1907 foo(1) -> one;
1908 foo(2) -> two;
1909 foo(_) -> other.
1912 # Corresponding Eunit unit test module:
1913 AT_DATA([s/testme_tests.erl],
1914 [[-module(testme_tests).
1915 -include_lib("eunit/include/eunit.hrl").
1916 foo_one_test() -> ?assertEqual(one, testme:foo(1)).
1917 foo_two_test() -> ?assertEqual(two, testme:foo(2)).
1918 foo_other_test() -> ?assertEqual(other, testme:foo(42)).
1921 # Compilation script:
1922 AT_DATA([s/compile.in],
1923 [["@ERLC@" -b beam testme.erl testme_tests.erl
1926 AT_CHECK_AT_PREP([suite],
1927 [[AT_INIT([suite to check EUnit integration])
1928 AT_SETUP([my only test])
1929 AT_CHECK_EUNIT([my_testsuite], [{module, testme}],
1930                [-pa "${abs_top_builddir}/s"])
1931 AT_CLEANUP
1932 ]], [], [], [], [t])
1934 AT_CHECK_AUTOCONF
1935 AT_CHECK_CONFIGURE
1936 . ./erlang.conf
1938 AT_CHECK([grep '^ERL='\''.*'\' t/atconfig], [], [ignore])
1939 AT_CHECK([grep '^ERLC='\''.*'\' t/atconfig], [], [ignore])
1940 AT_CHECK([grep '^ERLCFLAGS='\''.*'\' t/atconfig], [], [ignore])
1942 if test "$HAVE_ERLANG" = yes && test "$HAVE_EUNIT" = yes; then
1943   AT_CHECK([cd s && $CONFIG_SHELL ./compile])
1946 AT_CHECK([cd t && $CONFIG_SHELL ./suite], [], [ignore])
1948 if test "$HAVE_EUNIT" = yes; then
1949   AT_CHECK([grep 1.*successful t/suite.log], [], [ignore])
1950   AT_CHECK([grep skipped t/suite.log], [1], [ignore])
1951 else
1952   AT_CHECK([grep 1.*skipped t/suite.log], [], [ignore])
1953   AT_CHECK([grep 0.*successful t/suite.log], [], [ignore])
1956 AT_CLEANUP