5 # Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free Software
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],
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],
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
45 AT_CAPTURE_FILE(AT_dir[/$1.log])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])
55 AT_DATA_AUTOTEST(AT_dir[/$1.at], [$2])
56 AT_CHECK([cat >m4_default([$6], [.])/atconfig <<EOF
57 at_testdir=m4_default([$6], [.])
62 abs_top_srcdir='`pwd`'
64 abs_top_builddir='`pwd`'
66 m4_ifval([$6], [(cd AT_dir])
67 AT_CHECK_AUTOM4TE([--language=autotest -o $1 $1.at], [$3], [$4], [$5])
69 m4_popdef([AT_dir])dnl
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],
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),
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],
103 AT_INIT([artificial test suite])
104 AT_SETUP([my only test])
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],
116 AT_CHECK_AT_PREP([micro-suite], [$2], [1], [], [stderr])
117 AT_CHECK([grep '$3' stderr], [0], [ignore])
119 ])# AT_CHECK_AT_SYNTAX
124 m4_define([AT_NO_CMDSUBST],
125 [if (eval 'foo=$(echo bar) && test "$foo" = bar') >/dev/null 2>&1; then ]dnl
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
138 ## ------------------ ##
139 ## Empty test suite. ##
140 ## ------------------ ##
142 # This is not a sensible thing to do, but the user should not get an unhelpful
144 AT_CHECK_AT([Empty test suite],
145 [[AT_INIT([empty test suite])
148 AT_CHECK_AT([Banner-only test suite],
149 [[AT_INIT([empty test suite])
153 # Next level of emptiness.
154 AT_CHECK_AT_TEST([Empty test], [])
156 # And finally, an empty check should not cause a syntax error.
157 AT_CHECK_AT_TEST([Empty check], [AT_CHECK])
159 # Check for sensible error messages for common bugs.
160 AT_CHECK_AT_SYNTAX([AT@&t@_SETUP without AT@&t@_INIT],
161 [[AT_SETUP([only test])
164 ]], [AT@&t@_SETUP: missing AT@&t@_INIT detected])
166 AT_CHECK_AT_SYNTAX([AT@&t@_BANNER without AT@&t@_INIT],
167 [[AT_BANNER([just a banner])
168 ]], [AT@&t@_BANNER: missing AT@&t@_INIT detected])
170 AT_CHECK_AT_SYNTAX([AT@&t@_CLEANUP without AT@&t@_INIT],
172 ]], [AT@&t@_CLEANUP: missing AT@&t@_INIT detected])
174 AT_CHECK_AT_SYNTAX([Missing AT@&t@_CLEANUP],
175 [[AT_INIT([incomplete test suite])
176 AT_SETUP([only test])
178 ]], [missing AT@&t@_CLEANUP detected])
180 AT_CHECK_AT_SYNTAX([AT@&t@_FAIL_IF without AT@&t@_SETUP],
181 [[AT_INIT([incomplete test suite])
183 ]], [AT@&t@_FAIL_IF: missing AT@&t@_SETUP detected])
185 AT_CHECK_AT_SYNTAX([AT@&t@_SKIP_IF without AT@&t@_SETUP],
186 [[AT_INIT([incomplete test suite])
188 ]], [AT@&t@_SKIP_IF: missing AT@&t@_SETUP detected])
190 AT_CHECK_AT_SYNTAX([AT@&t@_CHECK without AT@&t@_SETUP],
191 [[AT_INIT([incomplete test suite])
193 ]], [AT@&t@_CHECK: missing AT@&t@_SETUP detected])
195 AT_CHECK_AT_SYNTAX([AT@&t@_DATA without AT@&t@_SETUP],
196 [[AT_INIT([incomplete test suite])
198 ]], [AT@&t@_DATA: missing AT@&t@_SETUP detected])
200 AT_CHECK_AT_SYNTAX([AT@&t@_XFAIL_IF without AT@&t@_SETUP],
201 [[AT_INIT([incomplete test suite])
203 ]], [AT@&t@_XFAIL_IF: missing AT@&t@_SETUP detected])
205 AT_CHECK_AT_SYNTAX([AT@&t@_KEYWORDS without AT@&t@_SETUP],
206 [[AT_INIT([incomplete test suite])
207 AT_KEYWORDS([keyword])
208 ]], [AT@&t@_KEYWORDS: missing AT@&t@_SETUP detected])
210 AT_CHECK_AT_SYNTAX([AT@&t@_CLEANUP without AT@&t@_SETUP],
211 [[AT_INIT([incomplete test suite])
213 ]], [AT@&t@_CLEANUP: missing AT@&t@_SETUP detected])
215 AT_CHECK_AT_SYNTAX([AT@&t@_BANNER inside AT@&t@_SETUP],
216 [[AT_INIT([incomplete test suite])
217 AT_SETUP([only test])
221 ]], [AT@&t@_BANNER: nested AT@&t@_SETUP detected])
223 AT_CHECK_AT_SYNTAX([AT@&t@_SETUP inside AT@&t@_SETUP],
224 [[AT_INIT([incomplete test suite])
225 AT_SETUP([only test])
226 AT_SETUP([nested test])
231 ]], [AT@&t@_SETUP: nested AT@&t@_SETUP detected])
233 AT_CHECK_AT_SYNTAX([Multiple AT@&t@_INIT],
234 [[AT_INIT([[suite, take one]])
236 ]], [AT@&t@_INIT: invoked multiple times])
238 # Check for tested programs. autoconf should only appear once.
239 AT_CHECK_AT([Tested programs],
240 [[AT_INIT([programs test suite])
241 AT_TESTED([autoconf autom4te])
242 AT_TESTED([autoconf])
243 ]], [], [], [], [], [],
244 [AT_CHECK([[sed -n 's|.*/\([^ /]* --version\)|\1|p' micro-suite.log]], [],
249 AT_CHECK_AT([Startup error messages],
251 AT_SETUP([only test])
254 ]], [], [], [], [], [],
255 [AT_CHECK([sed -n '/exec AS_MESSAGE_LOG_FD/q; />&AS_MESSAGE_LOG_FD/p' < micro-suite])])
257 ## ----------------- ##
258 ## Status handling. ##
259 ## ----------------- ##
261 AT_CHECK_AT_TEST([Truth],
262 [AT_CHECK([:], 0, [], [])])
264 AT_CHECK_AT_TEST([Fallacy],
265 [AT_CHECK([false], [], [], [])],
266 [], [1], [], [ignore], [],
267 [AT_CHECK([grep failed micro-suite.log], [], [ignore])])
269 AT_CHECK_AT_TEST([Skip],
270 [AT_CHECK([echo output; echo irrelevant >&2; exit 77], 0, [mismatch], [])],
272 [AT_CHECK([grep skipped micro-suite.log], [], [ignore])])
274 AT_CHECK_AT_TEST([Hard fail],
277 AT_SETUP([another test])
279 AT_CHECK([exit 99])],
280 [], [1], [], [ignore], [],
281 [AT_CHECK([grep '2 failed unexpectedly' micro-suite.log], [], [ignore])
282 AT_CHECK([grep '^[[12]].*ok' micro-suite.log], [1])])
284 AT_CHECK_AT_TEST([AT@&t@_FAIL_IF],
291 AT_FAIL_IF([test x = y])
297 AT_FAIL_IF([test x = x])
300 AT_FAIL_IF([test $foo = x])],
301 [], [1], [stdout], [ignore], [],
302 [AT_CHECK([grep '1 5 failed' stdout], [], [ignore], [ignore])])
304 AT_CHECK_AT_TEST([AT@&t@_SKIP_IF],
311 AT_SKIP_IF([test x = y])
317 AT_SKIP_IF([test x = x])
320 AT_SKIP_IF([test $foo = x])],
322 [AT_CHECK([grep '2.*skipped' micro-suite.log], [], [ignore], [ignore])])
324 AT_CHECK_AT_TEST([Syntax error],
330 AT_SETUP([another test])
333 [dnl Until we can find a way to avoid catastrophic failure (ash) or
334 dnl lack of failure (zsh), skip the rest of this test on such shells.
336 AT_CHECK([${CONFIG_SHELL-$SHELL} -c 'case `. ./syntax; echo $?` in
338 esac'], [0], [ignore], [ignore])
339 AT_CHECK([$CONFIG_SHELL ./micro-suite], [1], [ignore], [stderr])
340 AT_CHECK([grep "unable to parse test group: 2" stderr], [0], [ignore])],
343 AT_CHECK_AT_TEST([errexit],
346 AT_SETUP([test that should not be run])
348 [], [1], [stdout], [stderr], [],
349 [AT_CHECK([test -f micro-suite.log], [1])
350 touch micro-suite.log # shut up AT_CAPTURE_FILE.
351 AT_CHECK([grep "should not be run" stdout], [1])
352 AT_CHECK([grep "1 .* inhibited subsequent" stderr], [], [ignore])],
355 AT_CHECK_AT_TEST([unquoted output],
356 [m4_define([backtick], [`])
358 AT_CHECK_UNQUOTED([echo 'a"b backtick`'], [],
359 [${a}"`echo 'b '`\`\backtick]m4_newline)],
360 [], [], [], [], [AT_KEYWORDS([AT@&t@_CHECK_UNQUOTED])])
362 AT_CHECK_AT_TEST([Trace output],
363 [AT_CHECK([echo some longer longer longer command piped | ]dnl
364 [sed 's,into some other longer longer longer command,,'],
365 [], [some longer longer longer command piped
368 AT_CHECK_AT([Logging],
369 [[AT_INIT([artificial test suite])
370 dnl intentionally write failing tests, to see what gets logged
372 AT_CHECK([echo magicstring01], [1], [ignore])
375 AT_CHECK([echo magicstring02 >&2], [1], [], [ignore])
378 AT_CHECK([echo magicstring03], [1], [ignore-nolog])
381 AT_CHECK([echo magicstring04 >&2], [1], [], [ignore-nolog])
384 AT_CHECK([echo magicstring05], [1], [stdout])
387 AT_CHECK([echo magicstring06 >&2], [1], [], [stderr])
390 AT_CHECK([echo magicstring07], [1], [stdout-nolog])
393 AT_CHECK([echo magicstring08 >&2], [1], [], [stderr-nolog])
396 echo magicstring09 > expout
397 AT_CHECK([echo magicstring09], [1], [expout])
400 echo magicstring10 > experr
401 AT_CHECK([echo magicstring10 >&2], [1], [], [experr])
403 ]], [], [1], [], [ignore], [],
404 [AT_CHECK([$CONFIG_SHELL ./micro-suite], [1], [ignore-nolog], [ignore-nolog])
405 AT_CHECK([grep '^magicstring' micro-suite.log], [],
413 AT_CHECK_AT([Binary output],
414 [[AT_INIT([artificial test suite])
415 AT_SETUP([pass: no trailing newline])
416 AT_CHECK([printf short], [0], [stdout-nolog])
417 AT_CHECK([cat stdout], [0], [[short]])
419 AT_SETUP([pass: non-printing characters])
420 AT_CHECK([printf '\1\n' >&2], [0], [], [stderr-nolog])
421 printf '\1\n' > expout
422 AT_CHECK([cat stderr], [0], [expout])
424 AT_SETUP([pass: long lines])
427 str=$str$str$str$str$str$str$str$str$str$str
428 str=$str$str$str$str$str$str$str$str$str$str
429 str=$str$str$str$str$str
430 AT_CHECK_UNQUOTED([echo $str], [0], [[$str]m4_newline])
432 AT_SETUP([fail: no trailing newline])
433 AT_CHECK([printf short], [0], [stdout-nolog])
434 AT_CHECK([cat stdout], [0], [[long]])
436 AT_SETUP([fail: non-printing characters])
437 AT_CHECK([printf '\1\n' >&2], [0], [], [stderr-nolog])
438 printf '\2\n' > expout
439 AT_CHECK([cat stderr], [0], [expout])
441 AT_SETUP([fail: long lines])
444 str=$str$str$str$str$str$str$str$str$str$str
445 str=$str$str$str$str$str$str$str$str$str$str
446 str=$str$str$str$str$str
447 AT_CHECK_UNQUOTED([echo x$str], [0], [[${str}x]m4_newline])
449 ]], [], [0], [], [], [],
450 [AT_CHECK([$CONFIG_SHELL ./micro-suite 4], [1], [ignore], [ignore])
451 AT_CHECK([$CONFIG_SHELL ./micro-suite 5], [1], [ignore], [ignore])
452 AT_CHECK([$CONFIG_SHELL ./micro-suite 6], [1], [ignore], [ignore])], [1-3])
455 AT_CHECK_AT_TEST([Cleanup],
456 [AT_CHECK([test ! -f cleanup.success && test ! -f cleanup.failure])
457 AT_CHECK_UNQUOTED([exit $value], [ignore], [$output],
458 [], [touch cleanup.failure], [touch cleanup.success])],
460 [AT_KEYWORDS([AT@&t@_CHECK_UNQUOTED])
461 output=; export output],
462 [AT_CHECK([test -d micro-suite.dir/1])
463 AT_CHECK([test -f micro-suite.dir/1/cleanup.success])
464 AT_CHECK([test ! -f micro-suite.dir/1/cleanup.failure])
466 AT_CHECK([$CONFIG_SHELL ./micro-suite -d value=1], [], [ignore])
467 AT_CHECK([test -f micro-suite.dir/1/cleanup.success])
468 AT_CHECK([test ! -f micro-suite.dir/1/cleanup.failure])
470 AT_CHECK([$CONFIG_SHELL ./micro-suite -d value=1 output=mismatch],
471 [1], [ignore], [ignore])
472 AT_CHECK([test ! -f micro-suite.dir/1/cleanup.success])
473 AT_CHECK([test -f micro-suite.dir/1/cleanup.failure])
475 AT_CHECK([$CONFIG_SHELL ./micro-suite -d value=77], [], [ignore])
476 AT_CHECK([test ! -f micro-suite.dir/1/cleanup.success])
477 AT_CHECK([test ! -f micro-suite.dir/1/cleanup.failure])
479 AT_CHECK([$CONFIG_SHELL ./micro-suite -d value=99], [1], [ignore], [ignore])
480 AT_CHECK([test ! -f micro-suite.dir/1/cleanup.success])
481 AT_CHECK([test ! -f micro-suite.dir/1/cleanup.failure])
484 ## ----------------------------------------------------- ##
485 ## Newlines and command substitutions in test commands. ##
486 ## ----------------------------------------------------- ##
488 AT_CHECK_AT_TEST([Literal multiline command],
489 [AT_CHECK([echo Auto'
494 AT_CHECK_AT_TEST([Multiline parameter expansion],
497 AT_CHECK([echo "$FOO"], 0, [one
501 AT_CHECK_AT_TEST([Backquote command substitution],
502 [AT_CHECK([echo `echo hi`], 0, [hi
506 AT_CHECK_AT_TEST([Multiline backquote command substitution],
507 [AT_DATA([myfile],[foo
510 AT_CHECK([echo "`cat myfile`"], 0, [foo
514 AT_CHECK_AT_TEST([Parenthetical command substitution],
515 [AT_CHECK([echo $(echo hi)], 0, [hi
519 AT_CHECK_AT_TEST([Multiline parenthetical command substitution],
520 [AT_DATA([myfile],[foo
523 AT_CHECK([echo "$(cat myfile)"], 0, [foo
529 AT_CHECK_AT_TEST([Shell comment in command],
531 AT_CHECK([$my_echo one [#] two], [], [one
535 ## ------------------------- ##
536 ## ${...} in test commands. ##
537 ## ------------------------- ##
539 # If this invalid parameter expansion capsizes the test suite, the entire
540 # AT_SETUP ... AT_CLEANUP subshell will exit, and the commands it runs will
541 # appear to have succeeded. Therefore, we verify a failing test case.
543 AT_CHECK_AT_TEST([Invalid brace-enclosed parameter expansion],
544 [AT_CHECK([echo '${=invalid}'], 0, [wrong])], [false], 1, ignore, ignore)
547 ## ---------------------------- ##
548 ## M4 macros in test commands. ##
549 ## ---------------------------- ##
551 AT_CHECK_AT_TEST([Multiline command from M4 expansion],
552 [m4_define([GNU], ['foo
554 AT_CHECK([echo GNU], 0, [foo
558 AT_CHECK_AT_TEST([Double-M4-quoted command],
559 [m4_define([GNU], ['foo
561 AT_CHECK([[echo GNU]], 0, [[GNU
565 AT_CHECK_AT_TEST([Metacharacters in command from M4 expansion],
566 [m4_define([GNU], [\"`])
567 AT_CHECK([echo '\"`' [GNU] 'GNU'], 0, [GNU [G][NU] [\"`
571 ## -------------------------------------- ##
572 ## Backslash-<newline> in test commands. ##
573 ## -------------------------------------- ##
575 AT_CHECK_AT_TEST([BS-newline in command],
576 [AT_CHECK([echo Auto"\
580 AT_CHECK_AT_TEST([^BS-newline in command],
585 AT_CHECK_AT_TEST([BSx641-newline in command],
586 [AT_CHECK([printf '%s\n' Auto"\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
587 "conf], 0, [Auto\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\conf
590 AT_CHECK_AT_TEST([BS-BS-newline in command],
591 [AT_CHECK([printf '%s\n' Auto"\\
596 # A `^BS-BS-newline in command' test will run a command named `\'. No, thanks.
598 AT_CHECK_AT_TEST([BSx640-newline in command],
599 [AT_CHECK([printf '%s\n' Auto"\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
600 "conf], 0, [Auto\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
604 # This command has both escaped and unescaped newlines.
605 AT_CHECK_AT_TEST([Newline-CODE-BS-newline in command],
606 [AT_CHECK([printf '%s\n' Auto'
612 AT_CHECK_AT_TEST([Single-quote-BS-newline in command],
613 [AT_CHECK([printf '%s\n' Auto'\
618 AT_CHECK_AT_TEST([Single-quote-newline-BS-newline in command],
619 [AT_CHECK([printf '%s\n' Auto'
627 ## ----------------- ##
628 ## Input from stdin. ##
629 ## ----------------- ##
631 AT_SETUP([Input from stdin])
633 AT_CHECK_AT_PREP([micro-suite],
635 AT_SETUP([please enter hello<RETURN><EOF>])
636 AT_CHECK([cat], [], [hello
641 AT_CHECK([echo hello | $CONFIG_SHELL ./micro-suite], [], [ignore])
642 AT_CHECK([$CONFIG_SHELL ./micro-suite </dev/null], [1], [ignore], [ignore])
647 ## ------------------------------- ##
648 ## Funny characters in test names. ##
649 ## ------------------------------- ##
651 # AT_CHECK_AT_TITLE(TITLE, TITLE-TO-TEST, EXPANDED-TITLE-TO-TEST,
652 # [XFAIL-CONDITION], [COLUMN = 53])
653 # ---------------------------------------------------------------
654 # Create a new test named TITLE that runs an Autotest test suite
655 # comprised of a trivial test named TITLE-TO-TEST, which expands
656 # to EXPANDED-TITLE-TO-TEST. XFAIL-CONDITION passes verbatim to
657 # AT_CHECK_AT. Verify that `ok' prints at COLUMN.
658 m4_define([AT_CHECK_AT_TITLE],
661 m4_define([macro_name], [[macro_expanded]])
662 m4_define([macro_expanded], [[macro_overexpanded]])
663 m4_define([macro_backquote], [`])
664 m4_define([macro_single_quote], ['])
665 m4_define([macro_double_quote], ["])
666 ]]dnl restore font-lock: "
667 [[m4_define([macro_backslash], [\])
668 m4_define([macro_echo], [$][1])
669 AT_INIT([artificial test suite])
673 ]], [$4], [], [], [], [],
674 dnl This sed script checks for two things - that the output is properly
675 dnl expanded, and that the 'ok' starts on the right column.
676 [AT_KEYWORDS([m4@&t@_expand])
677 AT_CHECK([[$CONFIG_SHELL ./micro-suite |
680 s/[^:]*: \(.*[^ ]\)[ ]*ok.*/\1/p
682 s/^.\{]]]m4_default($5, 53)[[[\}ok.*/ok/p
687 dnl This sed script checks for two things - that -v output doesn't have
688 dnl an empty $at_srcdir expansion, and that the 'testing ...' line
689 dnl contains the test group title.
690 AT_CHECK([[$CONFIG_SHELL ./micro-suite -v |
691 sed -n 's/.*testing \(.*\) \.\.\./\1/p; /^\/micro-suite\.at:/p']],,
694 AT_CHECK([[$CONFIG_SHELL ./micro-suite -l |
695 sed -n 's/.*[0-9]: [^ ][^ ]*[ ][ ]*\(.*[^ ]\)[ ]*/\1/p']],,
698 AT_CHECK([[sed -n 's/[^.]*\. \(.*\) ([^)]*): ok.*/\1/p' micro-suite.log]],,
703 m4_define([AT_CHECK_AT_TITLE_CHAR],
704 [AT_CHECK_AT_TITLE([$1 in a test title], [A $2 in my name],
705 [A ]m4_ifval([$3], [[$3]], [[$2]])[ in my name], $4, $5)])
707 AT_CHECK_AT_TITLE_CHAR([Backquote], [`])
708 AT_CHECK_AT_TITLE_CHAR([Single-quote], ['])
709 AT_CHECK_AT_TITLE_CHAR([Double-quote], ["])
710 dnl restore font-lock: "
711 AT_CHECK_AT_TITLE_CHAR([Backslash], [\])
712 AT_CHECK_AT_TITLE_CHAR([Brackets], [[[]]], [[]])
713 AT_CHECK_AT_TITLE_CHAR([Left bracket], [@<:@], [@<:@])
714 AT_CHECK_AT_TITLE_CHAR([Right bracket], [@:>@], [@:>@])
715 AT_CHECK_AT_TITLE_CHAR([Quoted pound], [[#]], [#])
716 AT_CHECK_AT_TITLE_CHAR([Pound], [#])
717 AT_CHECK_AT_TITLE_CHAR([Quoted comma], [[,]], [,])
718 AT_CHECK_AT_TITLE_CHAR([Comma], [,])
719 dnl this test also hits quadrigraphs for ()
720 AT_CHECK_AT_TITLE_CHAR([Parentheses], [(@{:@)@:}@], [(())])
721 AT_CHECK_AT_TITLE_CHAR([Left paren], [[(]], [(])
722 AT_CHECK_AT_TITLE_CHAR([Right paren], [[)]], [)])
724 AT_CHECK_AT_TITLE_CHAR([Quoted Macro], [[macro_name]], [macro_name])
725 AT_CHECK_AT_TITLE_CHAR([Macro], [macro_name], [macro_expanded])
726 AT_CHECK_AT_TITLE_CHAR([Macro with backquote], [macro_backquote], [`])
727 AT_CHECK_AT_TITLE_CHAR([Macro with single-quote], [macro_single_quote], ['])
728 AT_CHECK_AT_TITLE_CHAR([Macro with double-quote], [macro_double_quote], ["])
729 dnl restore font-lock: "
730 AT_CHECK_AT_TITLE_CHAR([Macro with backslash], [macro_backslash], [\])
731 AT_CHECK_AT_TITLE_CHAR([Macro echoing macro], [macro_echo([macro_name])],
733 AT_CHECK_AT_TITLE_CHAR([Macro echoing single-quote], [macro_echo(['])], ['])
734 AT_CHECK_AT_TITLE_CHAR([Long test title], [0123456789012345678901234567890123])
735 AT_CHECK_AT_TITLE_CHAR([Longer test title],
736 [01234567890123456789012345678901234], [], [], [54])
739 ## ----------------------- ##
740 ## Long test source lines. ##
741 ## ----------------------- ##
743 # Create a test file that has more than 99 words in a line, for Solaris awk.
744 # While at that, try out the limit of 2000 bytes in a text file line.
746 AT_CHECK_AT_TEST([Long test source lines],
747 [m4_for([nnn], [1], [999], [], [: ])
749 ], [], [], [], [ignore], [],
750 [AT_CHECK([$CONFIG_SHELL ./micro-suite -k skipalltests], [], [ignore], [ignore])
754 ## ----------------- ##
755 ## Debugging a test. ##
756 ## ----------------- ##
758 AT_CHECK_AT_TEST([Debugging a successful test],
759 [AT_CHECK([:])], [], [], [], [ignore], [],
760 [# Without options, when all tests pass, no test directory should exist.
761 AT_CHECK([test -d micro-suite.dir/1 && exit 42
762 $CONFIG_SHELL ./micro-suite -d 1], [], [ignore], [ignore])
763 # Running with -d should leave a reproducible test group.
764 # Also, running the test script from the test group locks the
765 # directory from removal on some platforms; the script should still be
766 # able to run even if rmdir fails.
767 AT_CHECK([(cd micro-suite.dir/1 && ./run)], [], [ignore], [ignore])
768 # Running a debugging script implies -d.
769 AT_CHECK([(cd micro-suite.dir/1 && ./run)], [], [ignore], [ignore])
772 AT_CHECK_AT_TEST([Debugging script and environment],
773 [AT_CHECK([test "$MY_VAR" = pass || exit 42])],
774 [], [1], [], [ignore], [], [
775 # Changing environment outside of debugging script is not preserved.
776 AT_CHECK([(cd micro-suite.dir/1 && MY_VAR=pass ./run)],
777 [0], [ignore], [ignore])
778 AT_CHECK([(cd micro-suite.dir/1 && ./run)],
779 [1], [ignore], [ignore])
780 # Changing environment as argument to debugging script is preserved.
781 AT_CHECK([(cd micro-suite.dir/1; ./run MY_VAR=pass)],
782 [0], [ignore], [ignore])
783 AT_CHECK([(cd micro-suite.dir/1; ./run)],
784 [0], [ignore], [ignore])
787 # The run script must still be valid when shell metacharacters are passed
788 # in via an environment option.
789 AT_CHECK_AT_TEST([Debugging a failed test],
790 [AT_CHECK([test "$MY_VAR" = "one space" || exit 42])],
791 [], [1], [], [ignore], [], [
792 AT_CHECK([(cd micro-suite.dir/1 && ./run MY_VAR='two spaces')],
793 [1], [ignore], [ignore])
794 AT_CHECK([(cd micro-suite.dir/1 && ./run MY_VAR='one space')],
795 [0], [ignore], [ignore])
799 # Setting default variable values via atlocal.
800 AT_CHECK_AT_TEST([Using atlocal],
801 [AT_CHECK([test "x$MY_VAR" = "xodd; 'string" || exit 42])],
802 [], [1], [ignore], [ignore], [], [
803 dnl check that command line can set variable
804 AT_CHECK([$CONFIG_SHELL ./micro-suite MY_VAR="odd; 'string"], [0], [ignore])
805 dnl check that command line overrides environment
806 AT_CHECK([MY_VAR="odd; 'string" $CONFIG_SHELL ./micro-suite MY_VAR=unset],
807 [1], [ignore], [ignore])
808 dnl check that atlocal can give it a default
809 AT_CHECK([cat <<EOF >atlocal
810 MY_VAR="odd; 'string"
812 dnl Also populate enough of atlocal to do what atconfig normally does.
818 abs_top_srcdir='`pwd`'
820 abs_top_builddir='`pwd`'
823 AT_CHECK([$CONFIG_SHELL ./micro-suite], [0], [ignore])
824 dnl check that atlocal overrides environment
825 AT_CHECK([MY_VAR=unset $CONFIG_SHELL ./micro-suite], [0], [ignore])
826 dnl check that command line overrides atlocal
827 AT_CHECK([$CONFIG_SHELL ./micro-suite MY_VAR=], [1], [ignore], [ignore])
828 dnl check that syntax error is detected
829 AT_CHECK([$CONFIG_SHELL ./micro-suite =], [1], [], [ignore], [ignore])
830 AT_CHECK([$CONFIG_SHELL ./micro-suite 1=2], [1], [], [ignore], [ignore])
834 # Controlling where the testsuite is run.
835 AT_CHECK_AT_TEST([Choosing where testsuite is run],
836 [AT_CHECK([:])], [], [], [], [], [], [
837 dnl AT_CHECK_AT_TEST tests the default of running in `.'.
838 AT_CHECK([$CONFIG_SHELL ./micro-suite --clean])
839 AT_CHECK([test -f micro-suite.log], [1])
840 AT_CHECK([test -d micro-suite.dir], [1])
841 AT_CHECK([mkdir sub1 sub2])
842 dnl check specifying a different relative path to run in.
843 AT_CHECK([$CONFIG_SHELL ./micro-suite -C sub1], [0], [ignore], [])
844 AT_CHECK([test -f micro-suite.log], [1])
845 AT_CHECK([test -f sub1/micro-suite.log], [0])
846 AT_CHECK([test -d micro-suite.dir], [1])
847 AT_CHECK([test -d sub1/micro-suite.dir], [0])
848 AT_CHECK([$CONFIG_SHELL ./micro-suite -C sub1 --clean])
849 AT_CHECK([test -f sub1/micro-suite.log], [1])
850 AT_CHECK([test -d sub1/micro-suite.dir], [1])
851 dnl check specifying an absolute path to run in.
852 AT_CHECK([$CONFIG_SHELL ./micro-suite --directory="`pwd`/sub2"],
854 AT_CHECK([test -f micro-suite.log], [1])
855 AT_CHECK([test -f sub2/micro-suite.log], [0])
856 AT_CHECK([$CONFIG_SHELL ./micro-suite --clean --directory="`pwd`/sub2"])
857 AT_CHECK([test -f sub2/micro-suite.log], [1])
858 AT_CHECK([test -f sub2/micro-suite.dir], [1])
859 dnl check for failure detection with bad, missing, or empty directory.
860 AT_CHECK([$CONFIG_SHELL ./micro-suite -C nonesuch || exit 1], [1], [ignore], [ignore])
861 AT_CHECK([$CONFIG_SHELL ./micro-suite -C ''], [1], [ignore], [ignore])
862 AT_CHECK([$CONFIG_SHELL ./micro-suite -C - || exit 1], [1], [ignore], [ignore])
863 AT_CHECK([$CONFIG_SHELL ./micro-suite -C], [1], [ignore], [ignore])
864 dnl check that --help overrides bad directory selection.
865 AT_CHECK([$CONFIG_SHELL ./micro-suite -C nonesuch --help], [0], [ignore], [])
874 AT_CHECK_AT_PREP([b],
902 # AT_CHECK_BANNERS(TESTSUITE-OPTIONS, PATTERN1, COUNT1, PATTERN2, COUNT2)
903 m4_define([AT_CHECK_BANNERS],
904 [AT_CHECK([$CONFIG_SHELL ./b $1], [], [stdout])
905 AT_CHECK_EGREP([$2], m4_if([$3], [0], [1], [0]), [$3])
906 AT_CHECK_EGREP([$4], m4_if([$5], [0], [1], [0]), [$5])
909 AT_CHECK_BANNERS([], [first], [1], [second], [1])
910 AT_CHECK_BANNERS([-k zero], [first], [0], [second], [0])
911 AT_CHECK_BANNERS([1], [first], [0], [second], [0])
912 AT_CHECK_BANNERS([-2], [first], [1], [second], [0])
913 AT_CHECK_BANNERS([-3], [first], [1], [second], [0])
914 AT_CHECK_BANNERS([-k one], [first], [1], [second], [0])
915 AT_CHECK_BANNERS([3-4], [first], [1], [second], [0])
916 AT_CHECK_BANNERS([3-5], [first], [1], [second], [1])
917 AT_CHECK_BANNERS([4-5], [first], [0], [second], [1])
918 AT_CHECK_BANNERS([3-], [first], [1], [second], [1])
919 AT_CHECK_BANNERS([-k a], [first], [1], [second], [1])
920 AT_CHECK_BANNERS([4], [first], [0], [second], [0])
921 AT_CHECK_BANNERS([4-], [first], [0], [second], [1])
922 AT_CHECK_BANNERS([-k two], [first], [0], [second], [0])
923 AT_CHECK_BANNERS([1 4], [first], [0], [second], [0])
924 AT_CHECK_BANNERS([-k three], [first], [0], [second], [1])
925 AT_CHECK_BANNERS([5], [first], [0], [second], [0])
926 AT_CHECK_BANNERS([5-], [first], [0], [second], [1])
933 AT_SETUP([Keywords and ranges])
935 AT_CHECK_AT_PREP([k],
944 AT_SETUP(second) # 03
949 AT_KEYWORDS([key1 key2])
950 AT_KEYWORDS([m4_echo([Key1])])
968 AT_SETUP(test10) # 10
972 dnl check that AT_KEYWORDS does not duplicate words
973 AT_CHECK([grep -i 'key1.*key1' k], [1])
974 dnl check that -k requires an argument
975 AT_CHECK([$CONFIG_SHELL ./k -k], [1], [], [ignore])
977 # AT_CHECK_KEYS(TESTSUITE-OPTIONS, PATTERN1, COUNT1, PATTERN2, COUNT2)
978 m4_define([AT_CHECK_KEYS],
979 [AT_CHECK([$CONFIG_SHELL ./k $1], 0, [stdout])
980 AT_CHECK_EGREP([$2], 0, [$3])
981 AT_CHECK_EGREP([$4], 1, [$5])
984 AT_CHECK_KEYS([-k key1], [first|both], [2], [none|second], [0])
985 AT_CHECK_KEYS([-k key2], [second|both], [2], [none|first], [0])
986 AT_CHECK_KEYS([-k key1,key2], [both], [1], [none|first|second], [0])
987 AT_CHECK_KEYS([-k key1 -k key2], [first|second|both], [3], [none], [0])
988 AT_CHECK_KEYS([-k '!key1'], [none|second], [2], [first|both], [0])
989 AT_CHECK_KEYS([-k '!key2'], [none|first], [2], [second|both], [0])
990 AT_CHECK_KEYS([-k '!key1,key2'], [second], [1], [none|first|both], [0])
991 AT_CHECK_KEYS([-k 'key1,!key2'], [first], [1], [none|second|both], [0])
992 AT_CHECK_KEYS([-k '!key1,!key2'], [none], [1], [first|second|both], [0])
993 AT_CHECK_KEYS([-k '!key1' -k KEY2], [none|second|both], [3], [first], [0])
994 AT_CHECK_KEYS([-k key1 -k '!key2'], [none|first|both], [3], [second], [0])
995 AT_CHECK_KEYS([-k '!KEY1' -k '!key2'], [none|first|second], [3], [both], [0])
997 AT_CHECK_KEYS([-k none], [none], [1], [first|second|both], [0])
998 AT_CHECK_KEYS([-k key1,both], [both], [1], [none|first|second], [0])
999 AT_CHECK_KEYS([-k key1 -k both], [first|both], [2], [none|second], [0])
1000 AT_CHECK_KEYS([-k none,first], [successful], [1], [none|first|second|both], [0])
1001 AT_CHECK_KEYS([-k none,first,second,both], [successful], [1], [none|first|second|both], [0])
1002 AT_CHECK_KEYS([-k !none,first], [first], [1], [none|second|both], [0])
1004 AT_CHECK_KEYS([-k '.*eco.*'], [second], [1], [none|first|both], [0])
1005 AT_CHECK_KEYS([-k 'ECO'], [successful], [1], [none|first|second|both], [0])
1006 AT_CHECK_KEYS([-k '.*eco'], [successful], [1], [none|first|second|both], [0])
1007 AT_CHECK_KEYS([-k 'eco.*'], [successful], [1], [none|first|second|both], [0])
1008 AT_CHECK_KEYS([-k 'fir.*'], [first], [1], [none|second|both], [0])
1010 AT_CHECK_KEYS([1-2], [none|first], [2], [second|both], [0])
1011 AT_CHECK_KEYS([01-002 08], [none|first], [2], [second|both], [0])
1012 AT_CHECK_KEYS([1-3 2-1], [none|first|second], [3], [both], [0])
1013 AT_CHECK_KEYS([-3], [none|first|second], [3], [both], [0])
1014 AT_CHECK_KEYS([4-], [both], [1], [none|first|second], [0])
1015 AT_CHECK_KEYS([010], [test10], [1], [none|first|second|both], [0])
1016 AT_CHECK_KEYS([-k second 4-], [second|both], [2], [none|first], [0])
1018 AT_CHECK([$CONFIG_SHELL ./k 0], [1], [ignore], [ignore])
1019 AT_CHECK([$CONFIG_SHELL ./k 0-], [1], [ignore], [ignore])
1020 AT_CHECK([$CONFIG_SHELL ./k -0], [1], [ignore], [ignore])
1021 AT_CHECK([$CONFIG_SHELL ./k 11], [1], [ignore], [ignore])
1022 AT_CHECK([$CONFIG_SHELL ./k 11-], [1], [ignore], [ignore])
1023 AT_CHECK([$CONFIG_SHELL ./k 1-011], [1], [ignore], [ignore])
1024 AT_CHECK([$CONFIG_SHELL ./k -k nonexistent], [0], [ignore])
1026 AT_CHECK_KEYS([--list -k nonexistent], [KEYWORDS], [1], [first|second|both], [0])
1027 AT_CHECK_KEYS([--list 1], [none], [1], [first|second|both], [0])
1028 AT_CHECK_KEYS([--list 01], [none], [1], [first|second|both], [0])
1029 AT_CHECK_KEYS([--list -k none -k first], [none|first], [2], [second|both], [0])
1033 ## ----------------- ##
1034 ## Keyword wrapping. ##
1035 ## ----------------- ##
1036 AT_SETUP([Keyword wrapping])
1038 AT_CHECK_AT_PREP([k],
1041 AT_KEYWORDS([a1 b1 c1 d1 e1 f1 g1 h1 i1 j1 k1 l1 m1 n1 o1 p1 q1 r1 s1 t1])
1042 AT_KEYWORDS([u1 v1 w1 x1 y1 z1])
1043 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])
1045 AT_SETUP([test with long keywords])
1047 [this-is-a-long-keyword-that-cannot-be-wrapped-so-we-exceed-the-length-limit-here])
1048 # surrounded by short ones
1051 [another-very-long-keyword-that-hits-the-line-length-limit-bla-bla-bla-bla])
1056 AT_CHECK_KEYS([-l], [.{80}], [1], [.{87}], [0])
1060 m4_define([AT_SKIP_PARALLEL_TESTS],
1061 [# Per BUGS, we have not yet figured out how to run parallel tests cleanly
1062 # under dash and some ksh variants. For now, only run this test under
1063 # limited conditions; help is appreciated in widening this test base.
1064 AT_SKIP_IF([${CONFIG_SHELL-$SHELL} -c 'test -z "${BASH_VERSION+set}]]dnl
1065 [[${ZSH_VERSION+set}${TEST_PARALLEL_AUTOTEST+set}"'])
1066 # The parallel scheduler requires mkfifo and job control to work.
1067 AT_CHECK([mkfifo fifo || exit 77])
1068 AT_CHECK([${CONFIG_SHELL-$SHELL} -c '(set -m && set +m) || exit 77'],
1073 ## ----------------------- ##
1074 ## parallel test execution ##
1075 ## ----------------------- ##
1077 AT_SETUP([parallel test execution])
1079 # This test tries to ensure that -j runs tests in parallel.
1080 # Such a test is inherently racy, because there are no real-time
1081 # guarantees about scheduling delays. So we try to minimize
1082 # the chance to lose the race.
1084 # The time needed for a micro-suite consisting of NTESTS tests each
1085 # sleeping for a second is estimated by
1086 # startup + ntests * (serial_overhead + 1 / njobs)
1088 # in absence of major scheduling delays. This leads to side conditions:
1089 # - NTESTS should be high, so the STARTUP time is small compared to the
1090 # test run time, and scheduling delays can even out; it should not be
1091 # too high, to not slow down the testsuite unnecessarily,
1092 # - the number of concurrent jobs NJOBS should not be too low, so the
1093 # race is not lost so easily; it should not be too high, to avoid fork
1094 # failures on tightly limited systems. 4 seems a good compromise
1095 # here, considering that Autotest spawns several other processes.
1096 # - STARTUP is assumed to be the same for parallel and serial runs, so
1097 # the latter can estimate the former.
1098 # - To avoid unportable output from time measurement commands, spawn
1099 # both a parallel and a serial testsuite run; check that the former
1100 # completes before the latter has completed a fraction SERIAL_NTESTS
1101 # of the tests (the serial run is executed in a subdirectory), plus
1102 # some additional time to allow for compensation of SERIAL_OVERHEAD.
1103 # - when adding this time to the serial test execution, an initial delay
1104 # SERIAL_DELAY of the serial test helps to avoid unreliable scheduling
1105 # due to the startup burst of the suites.
1107 dnl total number of tests.
1108 m4_define([AT_PARALLEL_NTESTS], [16])
1109 dnl number of jobs to run in parallel.
1110 m4_define([AT_PARALLEL_NJOBS], [4])
1111 dnl number of tests to run serially, as comparison.
1112 m4_define([AT_PARALLEL_SERIAL_NTESTS],
1113 m4_eval(AT_PARALLEL_NTESTS / AT_PARALLEL_NJOBS))
1114 dnl initial delay of serial run, to compensate for SERIAL_OVERHEAD.
1115 dnl This corresponds to 0.67 s of overhead per test.
1116 m4_define([AT_PARALLEL_SERIAL_DELAY],
1117 m4_eval((AT_PARALLEL_NTESTS - AT_PARALLEL_SERIAL_NTESTS + 1) * 2 / 3))
1120 AT_CHECK_AT_PREP([micro-suite],
1121 [[AT_INIT([suite to test parallel execution])
1122 m4_for([count], [1], ]]AT_PARALLEL_NTESTS[[, [],
1123 [AT_SETUP([test number count])
1129 # Even if parallel jobs are not supported, the command line must work.
1130 AT_CHECK([$CONFIG_SHELL ./micro-suite --help | grep " --jobs"], [0], [ignore])
1131 AT_CHECK([$CONFIG_SHELL ./micro-suite -j2foo], [1], [], [stderr])
1132 AT_CHECK([grep 'non-numeric argument' stderr], [], [ignore])
1133 AT_CHECK([$CONFIG_SHELL ./micro-suite --jobs=foo], [1], [], [stderr])
1134 AT_CHECK([grep 'non-numeric argument' stderr], [], [ignore])
1136 AT_SKIP_PARALLEL_TESTS
1138 # Ensure that all tests run, and lines are not split.
1139 AT_CHECK([$CONFIG_SHELL ./micro-suite -j[]AT_PARALLEL_NJOBS], [], [stdout])
1140 AT_CHECK([grep -c '^.\{53\}ok' stdout], [], [AT_PARALLEL_NTESTS
1142 # Running one test with -j should produce correctly formatted output:
1143 AT_CHECK([$CONFIG_SHELL ./micro-suite -j 3], [], [stdout])
1144 AT_CHECK([grep -c '^.\{53\}ok' stdout], [], [1
1146 # Specifying more jobs than tests should not hang:
1147 AT_CHECK([$CONFIG_SHELL ./micro-suite -j3 3], [], [stdout])
1148 AT_CHECK([grep -c '^.\{53\}ok' stdout], [], [1
1150 # Not even with zero tests:
1151 AT_CHECK([$CONFIG_SHELL ./micro-suite -j -k nomatch], [], [ignore])
1152 AT_CHECK([$CONFIG_SHELL ./micro-suite -j3 -k nomatch], [], [ignore])
1156 # Unfortunately, the return value of wait is unreliable,
1157 # so we check that kill fails.
1158 AT_CHECK([$CONFIG_SHELL ./micro-suite --jobs=[]AT_PARALLEL_NJOBS & ]dnl
1159 [sleep AT_PARALLEL_SERIAL_DELAY && ]dnl
1160 [cd serial && $CONFIG_SHELL ../micro-suite -AT_PARALLEL_SERIAL_NTESTS >/dev/null && ]dnl
1161 [{ kill $! && exit 1; :; }], [], [stdout], [ignore])
1162 AT_CHECK([grep -c '^.\{53\}ok' stdout], [], [AT_PARALLEL_NTESTS
1164 AT_CHECK([grep 'AT_PARALLEL_NTESTS tests' stdout], [], [ignore])
1168 AT_CHECK_AT_TEST([parallel truth],
1169 [AT_CHECK([:], 0, [], [])],
1170 [], [], [], [], [AT_SKIP_PARALLEL_TESTS],
1173 AT_CHECK_AT_TEST([parallel fallacy],
1174 [AT_CHECK([false], [], [], [])],
1175 [], [1], [], [ignore], [AT_SKIP_PARALLEL_TESTS],
1176 [AT_CHECK([grep failed micro-suite.log], [], [ignore])], [-j])
1178 AT_CHECK_AT_TEST([parallel skip],
1179 [AT_CHECK([echo output; echo irrelevant >&2; exit 77], 0, [mismatch], [])],
1180 [], [], [], [], [AT_SKIP_PARALLEL_TESTS],
1181 [AT_CHECK([grep skipped micro-suite.log], [], [ignore])], [-j])
1183 AT_CHECK_AT_TEST([parallel syntax error],
1189 AT_SETUP([another test])
1191 [], [0], [], [], [AT_SKIP_PARALLEL_TESTS],
1192 [dnl Until we can find a way to avoid catastrophic failure (ash) or
1193 dnl lack of failure (zsh), skip the rest of this test on such shells.
1195 AT_CHECK([${CONFIG_SHELL-$SHELL} -c 'case `. ./syntax; echo $?` in
1197 esac'], [0], [ignore], [ignore])
1198 AT_CHECK([$CONFIG_SHELL ./micro-suite -j], [1], [ignore], [stderr])
1199 AT_CHECK([grep "unable to parse test group: 2" stderr], [0], [ignore])],
1202 AT_CHECK_AT_TEST([parallel errexit],
1205 AT_SETUP([barrier test])
1208 AT_SETUP([test that should not be run])
1210 [], [1], [stdout], [stderr], [AT_SKIP_PARALLEL_TESTS],
1211 [AT_CHECK([test -f micro-suite.log], [1])
1212 touch micro-suite.log # shut up AT_CAPTURE_FILE.
1213 AT_CHECK([grep "should not be run" stdout], [1])
1214 AT_CHECK([grep "[[12]] .* inhibited subsequent" stderr], [], [ignore])],
1218 AT_SETUP([parallel autotest and signal handling])
1220 AT_SKIP_PARALLEL_TESTS
1223 # (1) interrupt `./testsuite -jN'
1224 # (2) interrupt `make check TESTSUITEFLAGS=-jN'
1225 # (3) no trailing verbose/trace output
1226 # (4) exit status should be 128+signal
1233 AT_CHECK_AT_PREP([micro-suite],
1234 [[AT_INIT([suite to test parallel execution])
1235 AT_SETUP([test number 1])
1238 AT_SETUP([test number 2])
1241 AT_SETUP([test number 3])
1244 AT_SETUP([killer test])
1245 AT_CHECK([kill -$signal $suite_pid])
1247 m4_for([count], [5], [7], [],
1248 [AT_SETUP([test number count])
1254 AT_DATA([Makefile.in],
1257 TESTSUITE = ./micro-suite
1259 $(SHELL) '$(TESTSUITE)' $(TESTSUITEFLAGS)
1263 AT_CHECK([$CONFIG_SHELL $abs_top_builddir/config.status --file=Makefile:Makefile.in],
1266 # Test INT and TERM.
1267 for signal in 2 15; do
1269 AS_VAR_ARITH([expected_status], [128 + $signal])
1272 AT_CHECK([$CONFIG_SHELL ./micro-suite], [$expected_status],
1274 # Both stderr and the log should contain the notification about the signal.
1275 AT_CHECK([grep 'bailing out' stderr], [], [ignore])
1276 AT_CHECK([grep 'bailing out' micro-suite.log], [], [ignore])
1277 # There should be no junk job status output.
1278 AT_CHECK([[grep '[iI]nterrupt[ ]' stderr]], [1])
1281 AT_CHECK([$CONFIG_SHELL ./micro-suite --jobs=3], [$expected_status],
1283 AT_CHECK([grep 'bailing out' stderr], [], [ignore])
1284 AT_CHECK([grep 'bailing out' micro-suite.log], [], [ignore])
1285 # We'd like to check this here, too, but some shells do not allow to
1286 # turn off job control.
1287 # AT_CHECK([[grep '[iI]nterrupt[ ]' stderr]], [1])
1289 # Ditto with `make' in the loop.
1292 # Need to eliminate outer TESTSUITEFLAGS here.
1293 # Need to normalize exit status here: some make implementations
1294 # exit 1 (BSD make), some exit 2 (GNU make).
1295 AT_CHECK([$MAKE check TESTSUITEFLAGS=; ]dnl
1296 [case $? in 1|2) exit 1;; *) exit $?;; esac],
1297 [1], [ignore], [stderr])
1298 AT_CHECK([grep 'bailing out' stderr], [], [ignore])
1299 AT_CHECK([grep 'bailing out' micro-suite.log], [], [ignore])
1300 # Ditto, parallel case.
1301 AT_CHECK([$MAKE check TESTSUITEFLAGS=--jobs=3; ]dnl
1302 [case $? in 1|2) exit 1;; *) exit $?;; esac],
1303 [1], [ignore], [stderr])
1304 AT_CHECK([grep 'bailing out' stderr], [], [ignore])
1305 AT_CHECK([grep 'bailing out' micro-suite.log], [], [ignore])
1310 # The most important part here is that things should not hang, nor
1311 # get out of hand. OTOH, if the shell sets the default handler to
1312 # ignore PIPE (pdksh, dash), there is little we can do about having the
1313 # test run; it's only the output that won't be there. So all we check
1314 # for is that, if test 7 didn't run serially, then it shouldn't be
1315 # run in the parallel case either; the intermediate tests serve as
1317 # Note that stderr may contain "Broken pipe" errors.
1318 AT_CHECK([($CONFIG_SHELL ./micro-suite -d -3 5-; echo $? >status) | sed 5q],
1319 [], [stdout], [stderr])
1320 AT_CHECK([grep '5.*ok' stdout], [1])
1321 # Apparently some shells don't get around to creating 'status' any more.
1322 # And ksh93 on FreeBSD uses 256 + 13 instead of 128 + 13
1323 AT_CHECK([test ! -s status || grep 141 status || grep 269 status],
1325 AT_CHECK([if test -f micro-suite.dir/7/micro-suite.log; then ]dnl
1326 [ echo "shell ignores SIGPIPE" > sigpipe-stamp ]dnl
1329 AT_CHECK([$CONFIG_SHELL ./micro-suite -d -3 5- --jobs=2 | sed 5q], [], [stdout], [ignore])
1330 AT_CHECK([grep '5.*ok' stdout], [1])
1331 AT_CHECK([test -s sigpipe-stamp || test ! -f micro-suite.dir/7/micro-suite.log], [0])
1335 ## ------------------- ##
1336 ## srcdir propagation. ##
1337 ## ------------------- ##
1339 AT_SETUP([srcdir propagation])
1341 mkdir pkg vpath-outside vpath-abs
1342 mkdir pkg/t pkg/vpath-inside
1346 AT_DATA([pkg/configure.ac], [[AC_INIT
1347 AC_CONFIG_TESTDIR([t])
1350 cp "$abs_top_srcdir/build-aux/install-sh" pkg
1356 AT_CHECK_AT_PREP([suite],
1357 [[AT_INIT([suite to check srcdir])
1358 AT_SETUP([my only test])
1359 AT_CHECK([test -f "$top_srcdir"/a && test -f "$srcdir"/b])
1361 ]], [], [], [], [pkg/t])
1363 rm -f pkg/t/atconfig
1365 # Build directory totally outside source directory.
1367 AT_CHECK([../pkg/configure $configure_options], [0], [ignore])
1369 AT_CHECK([../../pkg/t/suite], [0], [ignore])
1370 AT_CHECK([../../pkg/t/suite -v], [0], [stdout])
1371 AT_CHECK([grep '^\.\./\.\./pkg/t/suite.at' stdout], [0], [ignore])
1374 # Build directory totally outside source directory (absolute).
1377 AT_CHECK(["$my_srcdir"/configure $configure_options], [0], [ignore])
1379 AT_CHECK(["$my_srcdir"/t/suite], [0], [ignore])
1380 AT_CHECK(["$my_srcdir"/t/suite -v], [0], [stdout])
1381 AT_CHECK([grep '..*/t/suite.at' stdout], [0], [ignore])
1384 # Build directory as subdirectory of source directory.
1386 AT_CHECK([../configure $configure_options], [0], [ignore])
1388 AT_CHECK([../../t/suite], [0], [ignore])
1389 AT_CHECK([../../t/suite -v], [0], [stdout])
1390 AT_CHECK([grep '^\.\./\.\./t/suite.at' stdout], [0], [ignore])
1393 # Build directory as parent of source directory.
1394 AT_CHECK([pkg/configure $configure_options], [0], [ignore])
1396 AT_CHECK([../pkg/t/suite], [0], [ignore])
1397 AT_CHECK([../pkg/t/suite -v], [0], [stdout])
1398 AT_CHECK([grep '^\.\./pkg/t/suite.at' stdout], [0], [ignore])
1401 # Build directory as source directory.
1405 AT_CHECK([./suite], [0], [ignore])
1406 AT_CHECK([./suite -v], [0], [stdout])
1407 AT_CHECK([grep '^\./suite.at' stdout], [0], [ignore])
1413 ## ------------------------------ ##
1414 ## whitespace in absolute testdir ##
1415 ## ------------------------------ ##
1417 AT_SETUP([whitespace in absolute testdir])
1419 dir='dir with whitespace'
1425 AT_CHECK_AT_PREP([suite],
1426 [[AT_INIT([suite to check srcdir])
1427 AT_SETUP([my only test])
1428 AT_CHECK([test -f "$top_srcdir"/a])
1431 AT_CHECK([top_srcdir=$wd ./suite], [0], [ignore])
1432 AT_CHECK([top_srcdir=$wd ./suite -d], [0], [ignore])
1433 AT_CHECK([cd suite.dir/1 && ./run top_srcdir="$wd"], [0], [ignore], [ignore])
1437 ## ------------------ ##
1438 ## unusual file names ##
1439 ## ------------------ ##
1441 AT_SETUP([unusual file names])
1443 AT_DATA_AUTOTEST([d@&t@nl.at],
1444 [[AT_SETUP([test one])
1445 m4_pattern_allow([^dnl$])
1446 AT_CHECK([test "]m4_dquote(AT_LINE)[" = dn[]l.at:3])
1451 AT_DATA_AUTOTEST([sub/"two spaces".at],
1452 [[AT_SETUP([test two])
1453 AT_CHECK([test "]m4_dquote(AT_LINE)[" = "two spaces.at:2"])
1457 AT_CHECK_AT_PREP([suite],
1458 [[AT_INIT([suite to check included file names])
1459 m4_include([d][nl.at])
1460 m4_include([sub/two spaces.at])
1462 AT_CHECK([$CONFIG_SHELL ./suite], [0], [stdout])
1463 AT_CHECK([grep 'two spaces' suite.log], [1])
1467 ## ------------------------- ##
1468 ## Erlang EUnit unit tests. ##
1469 ## ------------------------- ##
1471 AT_SETUP([Erlang Eunit unit tests])
1472 AT_KEYWORDS([Erlang])
1475 AT_DATA([configure.ac], [[AC_INIT
1476 AC_ERLANG_PATH_ERL([no])
1477 AC_ERLANG_PATH_ERLC([no])
1478 if test "$ERL" = "no" || test "$ERLC" = "no"; then
1483 AC_ERLANG_CHECK_LIB([eunit], [HAVE_EUNIT=yes], [HAVE_EUNIT=no])
1485 AC_SUBST([HAVE_ERLANG])
1486 AC_SUBST([HAVE_EUNIT])
1488 AC_CONFIG_TESTDIR([t])
1489 AC_CONFIG_FILES([s/compile], [chmod +x s/compile])
1490 AC_CONFIG_FILES([erlang.conf])
1494 # File to pass info back to us
1495 AT_DATA([erlang.conf.in],
1496 [[HAVE_ERLANG=@HAVE_ERLANG@
1497 HAVE_EUNIT=@HAVE_EUNIT@
1500 # Erlang module to test:
1501 AT_DATA([s/testme.erl],
1509 # Corresponding Eunit unit test module:
1510 AT_DATA([s/testme_tests.erl],
1511 [[-module(testme_tests).
1512 -include_lib("eunit/include/eunit.hrl").
1513 foo_one_test() -> ?assertEqual(one, testme:foo(1)).
1514 foo_two_test() -> ?assertEqual(two, testme:foo(2)).
1515 foo_other_test() -> ?assertEqual(other, testme:foo(42)).
1518 # Compilation script:
1519 AT_DATA([s/compile.in],
1520 [["@ERLC@" -b beam testme.erl testme_tests.erl
1523 AT_CHECK_AT_PREP([suite],
1524 [[AT_INIT([suite to check EUnit integration])
1525 AT_SETUP([my only test])
1526 AT_CHECK_EUNIT([my_testsuite], [{module, testme}],
1527 [-pa "${abs_top_builddir}/s"])
1529 ]], [], [], [], [t])
1535 AT_CHECK([grep '^ERL='\''.*'\' t/atconfig], [], [ignore])
1536 AT_CHECK([grep '^ERLC='\''.*'\' t/atconfig], [], [ignore])
1537 AT_CHECK([grep '^ERLCFLAGS='\''.*'\' t/atconfig], [], [ignore])
1539 if test "$HAVE_ERLANG" = yes && test "$HAVE_EUNIT" = yes; then
1540 AT_CHECK([cd s && $CONFIG_SHELL ./compile])
1543 AT_CHECK([cd t && $CONFIG_SHELL ./suite], [], [ignore])
1545 if test "$HAVE_EUNIT" = yes; then
1546 AT_CHECK([grep 1.*successful t/suite.log], [], [ignore])
1547 AT_CHECK([grep skipped t/suite.log], [1], [ignore])
1549 AT_CHECK([grep 1.*skipped t/suite.log], [], [ignore])
1550 AT_CHECK([grep 0.*successful t/suite.log], [], [ignore])