5 # Copyright (C) 2004-2017 Free Software Foundation, Inc.
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21 # AT_DATA_AUTOTEST(FILE-NAME, CONTENTS)
22 # -------------------------------------
23 # Escape the invalid tokens with @&t@.
24 m4_define([AT_DATA_AUTOTEST],
26 [m4_bpatsubst([$2], [\(@.\)\(.@\)\|\(m4\|AS\|AT\)\(_\)\|\(d\)\(nl\)],
27 [\1\3\5@&t@\2\4\6])])])
30 # AT_CHECK_AT_PREP(NAME, SUITE-CODE, [STATUS = 0], [STDOUT], [STDERR],
32 # --------------------------------------------------------------------
33 # Create a new testsuite named NAME that runs a minimal Autotest test suite,
34 # SUITE-CODE. Do not use `testsuite' for NAME, or the log file it generates
35 # will overwrite the log that the Autoconf test produces when managing
36 # this test case. STATUS, STDOUT, and STDERR pass directly to the AT_CHECK
37 # that compiles the testsuite. DIR can specify a particular subdirectory
38 # where the testsuite should live.
39 m4_define([AT_CHECK_AT_PREP],
40 [AT_KEYWORDS([autotest])dnl
41 dnl overquote AT_dir, to make it easier to use
42 m4_pushdef([AT_dir], m4_ifval([$6], [[[$6]]], [.]))dnl
44 AT_CAPTURE_FILE(AT_dir[/$1.log])dnl
46 AT_DATA_AUTOTEST(AT_dir[/package.m4],
47 [[m4_define([AT_PACKAGE_NAME], [GNU Nonsense])
48 m4_define([AT_PACKAGE_TARNAME], [nonsense])
49 m4_define([AT_PACKAGE_VERSION], [1.0])
50 m4_define([AT_PACKAGE_STRING], [GNU Nonsense 1.0])
51 m4_define([AT_PACKAGE_BUGREPORT], [bug-autoconf@gnu.org])
54 AT_DATA_AUTOTEST(AT_dir[/$1.at], [$2])
55 AT_CHECK([cat >m4_default([$6], [.])/atconfig <<EOF
56 at_testdir=m4_default([$6], [.])
61 abs_top_srcdir='`pwd`'
63 abs_top_builddir='`pwd`'
65 m4_ifval([$6], [(cd AT_dir])
66 AT_CHECK_AUTOM4TE([--language=autotest -o $1 $1.at], [$3], [$4], [$5])
68 m4_popdef([AT_dir])dnl
71 # AT_CHECK_AT(TITLE, SUITE-CODE, [XFAIL-CONDITION], [STATUS = 0],
72 # [STDOUT = ignore], STDERR, [PRE-TEST-CODE],
73 # [POST-TEST-CODE], [SUITE-ARGS])
74 # ---------------------------------------------------------------
75 # Create a new test named TITLE that runs a minimal Autotest test suite,
76 # SUITE-CODE with additional SUITE-ARGS, once without and once with
77 # '-v -x' added. Call AT_XFAIL_IF with XFAIL-CONDITION. Pass STDERR
78 # directly to the AT_CHECK that calls the minimal test suite, STDOUT to
79 # the AT_CHECK without '-v -x'; ignore stdout for the latter.
80 # Run PRE-TEST-CODE at the top level after the micro-suite is created, but
81 # before it is run, and POST-TEST-CODE after the micro-suite has been run.
82 m4_define([AT_CHECK_AT],
85 AT_CHECK_AT_PREP([micro-suite], [$2])
87 AT_CHECK([$CONFIG_SHELL ./micro-suite $9], m4_default([$4], 0),
88 m4_default([$5], [ignore]), [$6])
89 AT_CHECK([$CONFIG_SHELL ./micro-suite -v -x $9], m4_default([$4], 0),
95 # AT_CHECK_AT_TEST(TITLE, SUITE-SNIPPET, ...)
96 # -------------------------------------------
97 # Wrapper for AT_CHECK_AT that surrounds SUITE-SNIPPET with a boilerplate
98 # AT_INIT, AT_SETUP, and AT_CLEANUP and passes other arguments verbatim.
99 m4_define([AT_CHECK_AT_TEST],
102 AT_INIT([artificial test suite])
103 AT_SETUP([my only test])
106 ]], m4_shift2($@))]) # AT_CHECK_AT_TEST
108 # AT_CHECK_AT_SYNTAX(TITLE, SUITE, MESSAGE)
109 # -----------------------------------------
110 # Create a test named TITLE that tries compiling SUITE with syntax
111 # errors with autotest. Expect a failed compilation, and grep for
112 # MESSAGE occurring within the error output.
113 m4_define([AT_CHECK_AT_SYNTAX],
115 AT_CHECK_AT_PREP([micro-suite], [$2], [1], [], [stderr])
116 AT_CHECK([grep '$3' stderr], [0], [ignore])
118 ])# AT_CHECK_AT_SYNTAX
123 m4_define([AT_NO_CMDSUBST],
124 [if (eval 'foo=$(echo bar) && test "$foo" = bar') >/dev/null 2>&1; then ]dnl
127 # AT_CHECK_EGREP(PATTERN, STATUS, COUNT)
128 # --------------------------------------
129 # Run grep -E, counting how many times PATTERN occurs in the file 'stdout',
130 # and expecting exit STATUS and output COUNT.
131 m4_define([AT_CHECK_EGREP],
132 [AT_CHECK([$EGREP -c '$1' stdout], [$2], [$3
141 # Ensure the FSF notice as well as the user-provided one are present
142 # in the head of the testsuite as well as the --version output.
144 AT_CHECK_AT([AT@&t@_COPYRIGHT],
145 [[AT_INIT([Testing AT@&t@_COPYRIGHT])
146 AT_COPYRIGHT([[This is just a test notice, not a real one, so let's avoid
147 words that may be matched by scanners for legal things,
148 causing extra work for distributors.
149 Multi-line values should be supported.
151 ]], [], [], [stdout], [], [], [
152 AT_CHECK([grep 'Copyright.*Free Software Foundation' stdout], [], [ignore])
153 AT_CHECK([grep 'This is just a test notice' stdout], [], [ignore])
154 AT_CHECK([sed 50q micro-suite | grep 'Copyright.*Free Software Foundation'],
156 AT_CHECK([sed 50q micro-suite | grep 'This is just a test notice'],
165 AT_CHECK_AT_TEST([AT@&t@_DATA], [
166 AT_CHECK([test -f file1], [1])
168 AT_CHECK([test -f file1 && test ! -s file1])
169 AT_CHECK([echo hi > file1])
170 AT_DATA([file1], [[]])
171 AT_CHECK([test -f file1 && test ! -s file1])
173 AT_DATA([$file], [[$file
175 AT_CHECK([echo '$file' > file3])
176 AT_CHECK([cmp file2 file3])
180 ## ------------------ ##
181 ## AT_DATA_UNQUOTED. ##
182 ## ------------------ ##
184 AT_CHECK_AT_TEST([AT@&t@_DATA_UNQUOTED], [
185 AT_CHECK([test -f file1], [1])
187 AT_CHECK([test -f file1 && test ! -s file1])
188 AT_CHECK([echo hi > file1])
189 AT_DATA([file1], [[]])
190 AT_CHECK([test -f file1 && test ! -s file1])
192 AT_DATA_UNQUOTED([$file], [[$file
194 AT_CHECK([echo file2 > file3])
195 AT_CHECK([cmp file2 file3])
199 ## ------------------ ##
200 ## Empty test suite. ##
201 ## ------------------ ##
203 # This is not a sensible thing to do, but the user should not get an unhelpful
205 AT_CHECK_AT([Empty test suite],
206 [[AT_INIT([empty test suite])
209 AT_CHECK_AT([Banner-only test suite],
210 [[AT_INIT([empty test suite])
214 # Next level of emptiness.
215 AT_CHECK_AT_TEST([Empty test], [])
217 # And finally, an empty check should not cause a syntax error.
218 AT_CHECK_AT_TEST([Empty check], [AT_CHECK])
220 # Check for sensible error messages for common bugs.
221 AT_CHECK_AT_SYNTAX([AT@&t@_SETUP without AT@&t@_INIT],
222 [[AT_SETUP([only test])
225 ]], [AT@&t@_SETUP: missing AT@&t@_INIT detected])
227 AT_CHECK_AT_SYNTAX([AT@&t@_BANNER without AT@&t@_INIT],
228 [[AT_BANNER([just a banner])
229 ]], [AT@&t@_BANNER: missing AT@&t@_INIT detected])
231 AT_CHECK_AT_SYNTAX([AT@&t@_CLEANUP without AT@&t@_INIT],
233 ]], [AT@&t@_CLEANUP: missing AT@&t@_INIT detected])
235 AT_CHECK_AT_SYNTAX([Missing AT@&t@_CLEANUP],
236 [[AT_INIT([incomplete test suite])
237 AT_SETUP([only test])
239 ]], [missing AT@&t@_CLEANUP detected])
241 AT_CHECK_AT_SYNTAX([AT@&t@_FAIL_IF without AT@&t@_SETUP],
242 [[AT_INIT([incomplete test suite])
244 ]], [AT@&t@_FAIL_IF: missing AT@&t@_SETUP detected])
246 AT_CHECK_AT_SYNTAX([AT@&t@_SKIP_IF without AT@&t@_SETUP],
247 [[AT_INIT([incomplete test suite])
249 ]], [AT@&t@_SKIP_IF: missing AT@&t@_SETUP detected])
251 AT_CHECK_AT_SYNTAX([AT@&t@_CHECK without AT@&t@_SETUP],
252 [[AT_INIT([incomplete test suite])
254 ]], [AT@&t@_CHECK: missing AT@&t@_SETUP detected])
256 AT_CHECK_AT_SYNTAX([AT@&t@_DATA without AT@&t@_SETUP],
257 [[AT_INIT([incomplete test suite])
259 ]], [AT@&t@_DATA: missing AT@&t@_SETUP detected])
261 AT_CHECK_AT_SYNTAX([AT@&t@_XFAIL_IF without AT@&t@_SETUP],
262 [[AT_INIT([incomplete test suite])
264 ]], [AT@&t@_XFAIL_IF: missing AT@&t@_SETUP detected])
266 AT_CHECK_AT_SYNTAX([AT@&t@_KEYWORDS without AT@&t@_SETUP],
267 [[AT_INIT([incomplete test suite])
268 AT_KEYWORDS([keyword])
269 ]], [AT@&t@_KEYWORDS: missing AT@&t@_SETUP detected])
271 AT_CHECK_AT_SYNTAX([AT@&t@_CLEANUP without AT@&t@_SETUP],
272 [[AT_INIT([incomplete test suite])
274 ]], [AT@&t@_CLEANUP: missing AT@&t@_SETUP detected])
276 AT_CHECK_AT_SYNTAX([AT@&t@_BANNER inside AT@&t@_SETUP],
277 [[AT_INIT([incomplete test suite])
278 AT_SETUP([only test])
282 ]], [AT@&t@_BANNER: nested AT@&t@_SETUP detected])
284 AT_CHECK_AT_SYNTAX([AT@&t@_SETUP inside AT@&t@_SETUP],
285 [[AT_INIT([incomplete test suite])
286 AT_SETUP([only test])
287 AT_SETUP([nested test])
292 ]], [AT@&t@_SETUP: nested AT@&t@_SETUP detected])
294 AT_CHECK_AT_SYNTAX([Multiple AT@&t@_INIT],
295 [[AT_INIT([[suite, take one]])
297 ]], [AT@&t@_INIT: invoked multiple times])
299 # Check for tested programs. autoconf should only appear once.
300 AT_CHECK_AT([Tested programs],
301 [[AT_INIT([programs test suite])
302 AT_TESTED([autoconf autom4te])
303 AT_TESTED([autoconf])
304 ]], [], [], [], [], [],
305 [AT_CHECK([[sed -n 's|.*/\([^ /]* --version\)|\1|p' micro-suite.log]], [],
310 AT_CHECK_AT([Startup error messages],
312 AT_SETUP([only test])
315 ]], [], [], [], [], [],
316 [AT_CHECK([sed -n '/exec AS_MESSAGE_LOG_FD/q; />&AS_MESSAGE_LOG_FD/p' < micro-suite])])
318 ## ----------------- ##
319 ## Status handling. ##
320 ## ----------------- ##
322 AT_CHECK_AT_TEST([Truth],
323 [AT_CHECK([:], 0, [], [])])
325 AT_CHECK_AT_TEST([Fallacy],
326 [AT_CHECK([false], [], [], [])],
327 [], [1], [], [ignore], [],
328 [AT_CHECK([grep failed micro-suite.log], [], [ignore])])
330 AT_CHECK_AT_TEST([Skip],
331 [AT_CHECK([echo output; echo irrelevant >&2; exit 77], 0, [mismatch], [])],
333 [AT_CHECK([grep skipped micro-suite.log], [], [ignore])])
335 AT_CHECK_AT_TEST([Hard fail],
338 AT_SETUP([another test])
340 AT_CHECK([exit 99])],
341 [], [1], [], [ignore], [],
342 [AT_CHECK([grep '2 failed unexpectedly' micro-suite.log], [], [ignore])
343 AT_CHECK([grep '^[[12]].*ok' micro-suite.log], [1])])
345 AT_CHECK_AT_TEST([AT@&t@_FAIL_IF],
352 AT_FAIL_IF([test x = y])
358 AT_FAIL_IF([test x = x])
361 AT_FAIL_IF([test $foo = x])],
362 [], [1], [stdout], [ignore], [],
363 [AT_CHECK([grep '1 5 failed' stdout], [], [ignore], [ignore])])
365 AT_CHECK_AT_TEST([AT@&t@_SKIP_IF],
372 AT_SKIP_IF([test x = y])
378 AT_SKIP_IF([test x = x])
381 AT_SKIP_IF([test $foo = x])],
383 [AT_CHECK([grep '2.*skipped' micro-suite.log], [], [ignore], [ignore])])
385 AT_CHECK_AT_TEST([Syntax error],
391 AT_SETUP([another test])
394 [dnl Until we can find a way to avoid catastrophic failure (ash) or
395 dnl lack of failure (zsh), skip the rest of this test on such shells.
397 AT_CHECK([${CONFIG_SHELL-$SHELL} -c 'case `. ./syntax; echo $?` in
399 esac'], [0], [ignore], [ignore])
400 AT_CHECK([${CONFIG_SHELL-$SHELL} ./micro-suite], [1], [ignore], [stderr])
401 AT_CHECK([grep "unable to parse test group: 2" stderr], [0], [ignore])],
404 AT_CHECK_AT_TEST([errexit],
407 AT_SETUP([test that should not be run])
410 AT_SETUP([xpassing test])
414 AT_SETUP([another test that should not be run])
417 AT_SETUP([skipping test])
420 AT_SETUP([xfailing test])
424 AT_SETUP([a test that should be run])
426 AT_SETUP([hard failure])
430 AT_SETUP([yet another test that should not be run])],
431 [], [1], [stdout], [stderr], [],
432 [AT_CHECK([test -f micro-suite.log], [1])
433 touch micro-suite.log # shut up AT_CAPTURE_FILE.
434 AT_CHECK([grep "should not be run" stdout], [1])
435 AT_CHECK([grep "1 .* inhibited subsequent" stderr], [], [ignore])
436 AT_CHECK([$CONFIG_SHELL ./micro-suite --errexit 3-], [1], [stdout], [stderr])
437 AT_CHECK([grep "should not be run" stdout], [1])
438 AT_CHECK([grep "1 .* inhibited subsequent" stderr], [], [ignore])
439 AT_CHECK([$CONFIG_SHELL ./micro-suite --errexit 5-], [1], [stdout], [stderr])
440 AT_CHECK([grep "should be run" stdout], [0], [ignore])
441 AT_CHECK([grep "should not be run" stdout], [1])
442 AT_CHECK([grep "inhibited subsequent" stderr], [], [ignore])],
446 AT_CHECK_AT_TEST([at_status],
447 [AT_CHECK([exit $mystatus], [$expected], [], [],
448 [AT_CHECK([echo run-if-fail: $at_status], [], [ignore])],
449 [AT_CHECK([echo run-if-pass: $at_status], [], [ignore])])
451 AT_SETUP([test with nested checks])
452 AT_CHECK([exit $mystatus], [$expected], [], [],
453 [AT_CHECK([exit $mystatus], [$expected], [], [],
454 [AT_CHECK([echo inner run-if-fail: $at_status], [],
456 [], [], [stdout], [],
458 AT_CHECK([grep 'inner run-if-fail: 42' stdout], [], [ignore])
459 AT_CHECK([$CONFIG_SHELL ./micro-suite -x -v 1 mystatus=0 expected=0], [], [stdout])
460 AT_CHECK([grep 'run-if-pass: 0' stdout], [], [ignore])
461 AT_CHECK([$CONFIG_SHELL ./micro-suite -x -v 1 mystatus=42 expected=0], [], [stdout])
462 AT_CHECK([grep 'run-if-fail: 42' stdout], [], [ignore])
463 AT_CHECK([$CONFIG_SHELL ./micro-suite -x -v 1 mystatus=0 expected=42], [], [stdout])
464 AT_CHECK([grep 'run-if-fail: 0' stdout], [], [ignore])
465 AT_CHECK([$CONFIG_SHELL ./micro-suite -x -v 1 mystatus=42 expected=42], [], [stdout])
466 AT_CHECK([grep 'run-if-pass: 42' stdout], [], [ignore])
468 [-v mystatus=42 expected=1
472 AT_CHECK_AT_TEST([AT@&t@_CHECK execution environment],
473 [dnl The first test should fail, so we enter RUN-IF-FAIL.
474 AT_CHECK([test "$state" != before], [], [], [],
476 AT_CHECK([:]) dnl need this so we do not bail out at this point.
478 dnl This should pass, so we enter RUN-IF-PASS.
479 AT_CHECK([test "$state" = run-if-fail], [], [], [], [],
481 AT_CHECK([test "$state" = run-if-pass])
482 dnl However, COMMANDS are run inside a subshell, so do not change state.
483 AT_CHECK([state=broken; false], [], [], [],
484 [AT_CHECK([test "$state" = run-if-pass])])
485 AT_CHECK([state=broken], [], [], [], [],
486 [AT_CHECK([test "$state" = run-if-pass])])
488 [], [], [], [], [], [], [state=before])
491 AT_CHECK_AT_TEST([unquoted output],
492 [m4_define([backtick], [`])
494 AT_CHECK_UNQUOTED([echo 'a"b backtick`'], [],
495 [${a}"`echo 'b '`\`\backtick]m4_newline)],
496 [], [], [], [], [AT_KEYWORDS([AT@&t@_CHECK_UNQUOTED])])
498 AT_CHECK_AT_TEST([Trace output],
499 [AT_CHECK([echo some longer longer longer command piped | ]dnl
500 [sed 's,into some other longer longer longer command,,'],
501 [], [some longer longer longer command piped
504 AT_CHECK_AT([Logging],
505 [[AT_INIT([artificial test suite])
506 dnl intentionally write failing tests, to see what gets logged
508 AT_CHECK([echo magicstring01], [1], [ignore])
511 AT_CHECK([echo magicstring02 >&2], [1], [], [ignore])
514 AT_CHECK([echo magicstring03], [1], [ignore-nolog])
517 AT_CHECK([echo magicstring04 >&2], [1], [], [ignore-nolog])
520 AT_CHECK([echo magicstring05], [1], [stdout])
523 AT_CHECK([echo magicstring06 >&2], [1], [], [stderr])
526 AT_CHECK([echo magicstring07], [1], [stdout-nolog])
529 AT_CHECK([echo magicstring08 >&2], [1], [], [stderr-nolog])
532 echo magicstring09 > expout
533 AT_CHECK([echo magicstring09], [1], [expout])
536 echo magicstring10 > experr
537 AT_CHECK([echo magicstring10 >&2], [1], [], [experr])
539 ]], [], [1], [], [ignore], [],
540 [AT_CHECK([$CONFIG_SHELL ./micro-suite], [1], [ignore-nolog], [ignore-nolog])
541 AT_CHECK([grep '^magicstring' micro-suite.log], [],
549 AT_CHECK_AT([Binary output],
550 [[AT_INIT([artificial test suite])
551 AT_SETUP([pass: no trailing newline])
552 AT_CHECK([printf short], [0], [stdout-nolog])
553 AT_CHECK([cat stdout], [0], [[short]])
555 AT_SETUP([pass: non-printing characters])
556 AT_CHECK([printf '\1\n' >&2], [0], [], [stderr-nolog])
557 printf '\1\n' > expout
558 AT_CHECK([cat stderr], [0], [expout])
560 AT_SETUP([pass: long lines])
563 str=$str$str$str$str$str$str$str$str$str$str
564 str=$str$str$str$str$str$str$str$str$str$str
565 str=$str$str$str$str$str
566 AT_CHECK_UNQUOTED([echo $str], [0], [[$str]m4_newline])
568 AT_SETUP([fail: no trailing newline])
569 AT_CHECK([printf short], [0], [stdout-nolog])
570 AT_CHECK([cat stdout], [0], [[long]])
572 AT_SETUP([fail: non-printing characters])
573 AT_CHECK([printf '\1\n' >&2], [0], [], [stderr-nolog])
574 printf '\2\n' > expout
575 AT_CHECK([cat stderr], [0], [expout])
577 AT_SETUP([fail: long lines])
580 str=$str$str$str$str$str$str$str$str$str$str
581 str=$str$str$str$str$str$str$str$str$str$str
582 str=$str$str$str$str$str
583 AT_CHECK_UNQUOTED([echo x$str], [0], [[${str}x]m4_newline])
585 ]], [], [0], [], [], [],
586 [AT_CHECK([$CONFIG_SHELL ./micro-suite 4], [1], [ignore], [ignore])
587 AT_CHECK([$CONFIG_SHELL ./micro-suite 5], [1], [ignore], [ignore])
588 AT_CHECK([$CONFIG_SHELL ./micro-suite 6], [1], [ignore], [ignore])], [1-3])
591 AT_CHECK_AT_TEST([Cleanup],
592 [AT_CHECK([test ! -f cleanup.success && test ! -f cleanup.failure])
593 AT_XFAIL_IF([$xfail])
594 AT_CHECK_UNQUOTED([exit $value], [ignore], [$output],
595 [], [touch cleanup.failure], [touch cleanup.success])],
597 [AT_KEYWORDS([AT@&t@_CHECK_UNQUOTED])
598 output=; export output],
599 [AT_CHECK([test -d micro-suite.dir/1])
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=1], [], [ignore])
604 AT_CHECK([test -f micro-suite.dir/1/cleanup.success])
605 AT_CHECK([test ! -f micro-suite.dir/1/cleanup.failure])
607 AT_CHECK([$CONFIG_SHELL ./micro-suite xfail=: value=0],
608 [1], [ignore], [ignore])
609 AT_CHECK([test -f micro-suite.dir/1/cleanup.success])
610 AT_CHECK([test ! -f micro-suite.dir/1/cleanup.failure])
612 AT_CHECK([$CONFIG_SHELL ./micro-suite -d xfail=false value=1 output=mismatch],
613 [1], [ignore], [ignore])
614 AT_CHECK([test ! -f micro-suite.dir/1/cleanup.success])
615 AT_CHECK([test -f micro-suite.dir/1/cleanup.failure])
617 AT_CHECK([$CONFIG_SHELL ./micro-suite -d xfail=false value=77], [], [ignore])
618 AT_CHECK([test ! -f micro-suite.dir/1/cleanup.success])
619 AT_CHECK([test ! -f micro-suite.dir/1/cleanup.failure])
621 AT_CHECK([$CONFIG_SHELL ./micro-suite -d xfail=false value=99],
622 [1], [ignore], [ignore])
623 AT_CHECK([test ! -f micro-suite.dir/1/cleanup.success])
624 AT_CHECK([test ! -f micro-suite.dir/1/cleanup.failure])
625 ], [-d xfail=false value=0])
627 ## ----------------------------------------------------- ##
628 ## Newlines and command substitutions in test commands. ##
629 ## ----------------------------------------------------- ##
631 AT_CHECK_AT_TEST([Literal multiline command],
632 [AT_CHECK([echo Auto'
637 AT_CHECK_AT_TEST([Multiline parameter expansion],
640 AT_CHECK([echo "$FOO"], 0, [one
644 AT_CHECK_AT_TEST([Backquote command substitution],
645 [AT_CHECK([echo `echo hi`], 0, [hi
649 AT_CHECK_AT_TEST([Multiline backquote command substitution],
650 [AT_DATA([myfile],[foo
653 AT_CHECK([echo "`cat myfile`"], 0, [foo
657 AT_CHECK_AT_TEST([Parenthetical command substitution],
658 [AT_CHECK([echo $(echo hi)], 0, [hi
662 AT_CHECK_AT_TEST([Multiline parenthetical command substitution],
663 [AT_DATA([myfile],[foo
666 AT_CHECK([echo "$(cat myfile)"], 0, [foo
672 AT_CHECK_AT_TEST([Shell comment in command],
674 AT_CHECK([$my_echo one [#] two], [], [one
678 ## ------------------------- ##
679 ## ${...} in test commands. ##
680 ## ------------------------- ##
682 # If this invalid parameter expansion capsizes the test suite, the entire
683 # AT_SETUP ... AT_CLEANUP subshell will exit, and the commands it runs will
684 # appear to have succeeded. Therefore, we verify a failing test case.
686 AT_CHECK_AT_TEST([Invalid brace-enclosed parameter expansion],
687 [AT_CHECK([echo '${=invalid}'], 0, [wrong])], [false], 1, ignore, ignore)
690 ## ---------------------------- ##
691 ## M4 macros in test commands. ##
692 ## ---------------------------- ##
694 AT_CHECK_AT_TEST([Multiline command from M4 expansion],
695 [m4_define([GNU], ['foo
697 AT_CHECK([echo GNU], 0, [foo
701 AT_CHECK_AT_TEST([Double-M4-quoted command],
702 [m4_define([GNU], ['foo
704 AT_CHECK([[echo GNU]], 0, [[GNU
708 AT_CHECK_AT_TEST([Metacharacters in command from M4 expansion],
709 [m4_define([GNU], [\"`])
710 AT_CHECK([echo '\"`' [GNU] 'GNU'], 0, [GNU [G][NU] [\"`
714 ## -------------------------------------- ##
715 ## Backslash-<newline> in test commands. ##
716 ## -------------------------------------- ##
718 AT_CHECK_AT_TEST([BS-newline in command],
719 [AT_CHECK([echo Auto"\
723 AT_CHECK_AT_TEST([^BS-newline in command],
728 AT_CHECK_AT_TEST([BSx641-newline in command],
729 [AT_CHECK([printf '%s\n' Auto"\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
730 "conf], 0, [Auto\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\conf
733 AT_CHECK_AT_TEST([BS-BS-newline in command],
734 [AT_CHECK([printf '%s\n' Auto"\\
739 # A `^BS-BS-newline in command' test will run a command named `\'. No, thanks.
741 AT_CHECK_AT_TEST([BSx640-newline in command],
742 [AT_CHECK([printf '%s\n' Auto"\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
743 "conf], 0, [Auto\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
747 # This command has both escaped and unescaped newlines.
748 AT_CHECK_AT_TEST([Newline-CODE-BS-newline in command],
749 [AT_CHECK([printf '%s\n' Auto'
755 AT_CHECK_AT_TEST([Single-quote-BS-newline in command],
756 [AT_CHECK([printf '%s\n' Auto'\
761 AT_CHECK_AT_TEST([Single-quote-newline-BS-newline in command],
762 [AT_CHECK([printf '%s\n' Auto'
770 ## ----------------- ##
771 ## Input from stdin. ##
772 ## ----------------- ##
774 AT_SETUP([Input from stdin])
776 AT_CHECK_AT_PREP([micro-suite],
778 AT_SETUP([please enter hello<RETURN><EOF>])
779 AT_CHECK([cat], [], [hello
784 AT_CHECK([echo hello | $CONFIG_SHELL ./micro-suite], [], [ignore])
785 AT_CHECK([$CONFIG_SHELL ./micro-suite </dev/null], [1], [ignore], [ignore])
790 ## ------------------------------- ##
791 ## Funny characters in test names. ##
792 ## ------------------------------- ##
794 # AT_CHECK_AT_TITLE(TITLE, TITLE-TO-TEST, EXPANDED-TITLE-TO-TEST,
795 # [XFAIL-CONDITION], [COLUMN = 53])
796 # ---------------------------------------------------------------
797 # Create a new test named TITLE that runs an Autotest test suite
798 # comprised of a trivial test named TITLE-TO-TEST, which expands
799 # to EXPANDED-TITLE-TO-TEST. XFAIL-CONDITION passes verbatim to
800 # AT_CHECK_AT. Verify that `ok' prints at COLUMN.
801 m4_define([AT_CHECK_AT_TITLE],
804 m4_define([macro_name], [[macro_expanded]])
805 m4_define([macro_expanded], [[macro_overexpanded]])
806 m4_define([macro_backquote], [`])
807 m4_define([macro_single_quote], ['])
808 m4_define([macro_double_quote], ["])
809 ]]dnl restore font-lock: "
810 [[m4_define([macro_backslash], [\])
811 m4_define([macro_echo], [$][1])
812 AT_INIT([artificial test suite])
816 ]], [$4], [], [], [], [],
817 dnl This sed script checks for two things - that the output is properly
818 dnl expanded, and that the 'ok' starts on the right column.
819 [AT_KEYWORDS([m4@&t@_expand])
820 AT_CHECK([[$CONFIG_SHELL ./micro-suite |
823 s/[^:]*: \(.*[^ ]\)[ ]*ok.*/\1/p
825 s/^.\{]]]m4_default($5, 53)[[[\}ok.*/ok/p
830 dnl This sed script checks for two things - that -v output doesn't have
831 dnl an empty $at_srcdir expansion, and that the 'testing ...' line
832 dnl contains the test group title.
833 AT_CHECK([[$CONFIG_SHELL ./micro-suite -v |
834 sed -n 's/.*testing \(.*\) \.\.\./\1/p; /^\/micro-suite\.at:/p']],,
837 AT_CHECK([[$CONFIG_SHELL ./micro-suite -l |
838 sed -n 's/.*[0-9]: [^ ][^ ]*[ ][ ]*\(.*[^ ]\)[ ]*/\1/p']],,
841 AT_CHECK([[sed -n 's/[^.]*\. \(.*\) ([^)]*): ok.*/\1/p' micro-suite.log]],,
846 m4_define([AT_CHECK_AT_TITLE_CHAR],
847 [AT_CHECK_AT_TITLE([$1 in a test title], [A $2 in my name],
848 [A ]m4_ifval([$3], [[$3]], [[$2]])[ in my name], $4, $5)])
850 AT_CHECK_AT_TITLE_CHAR([Backquote], [`])
851 AT_CHECK_AT_TITLE_CHAR([Single-quote], ['])
852 AT_CHECK_AT_TITLE_CHAR([Double-quote], ["])
853 dnl restore font-lock: "
854 AT_CHECK_AT_TITLE_CHAR([Backslash], [\])
855 AT_CHECK_AT_TITLE_CHAR([Brackets], [[[]]], [[]])
856 AT_CHECK_AT_TITLE_CHAR([Left bracket], [@<:@], [@<:@])
857 AT_CHECK_AT_TITLE_CHAR([Right bracket], [@:>@], [@:>@])
858 AT_CHECK_AT_TITLE_CHAR([Quoted pound], [[#]], [#])
859 AT_CHECK_AT_TITLE_CHAR([Pound], [#])
860 AT_CHECK_AT_TITLE_CHAR([Quoted comma], [[,]], [,])
861 AT_CHECK_AT_TITLE_CHAR([Comma], [,])
862 dnl this test also hits quadrigraphs for ()
863 AT_CHECK_AT_TITLE_CHAR([Parentheses], [(@{:@)@:}@], [(())])
864 AT_CHECK_AT_TITLE_CHAR([Left paren], [[(]], [(])
865 AT_CHECK_AT_TITLE_CHAR([Right paren], [[)]], [)])
867 AT_CHECK_AT_TITLE_CHAR([Quoted Macro], [[macro_name]], [macro_name])
868 AT_CHECK_AT_TITLE_CHAR([Macro], [macro_name], [macro_expanded])
869 AT_CHECK_AT_TITLE_CHAR([Macro with backquote], [macro_backquote], [`])
870 AT_CHECK_AT_TITLE_CHAR([Macro with single-quote], [macro_single_quote], ['])
871 AT_CHECK_AT_TITLE_CHAR([Macro with double-quote], [macro_double_quote], ["])
872 dnl restore font-lock: "
873 AT_CHECK_AT_TITLE_CHAR([Macro with backslash], [macro_backslash], [\])
874 AT_CHECK_AT_TITLE_CHAR([Macro echoing macro], [macro_echo([macro_name])],
876 AT_CHECK_AT_TITLE_CHAR([Macro echoing single-quote], [macro_echo(['])], ['])
877 AT_CHECK_AT_TITLE_CHAR([Long test title], [0123456789012345678901234567890123])
878 AT_CHECK_AT_TITLE_CHAR([Longer test title],
879 [01234567890123456789012345678901234], [], [], [54])
882 ## ----------------------- ##
883 ## Long test source lines. ##
884 ## ----------------------- ##
886 # Create a test file that has more than 99 words in a line, for Solaris awk.
887 # While at that, try out the limit of 2000 bytes in a text file line.
889 AT_CHECK_AT_TEST([Long test source lines],
890 [m4_for([nnn], [1], [999], [], [: ])
892 ], [], [], [], [ignore], [],
893 [AT_CHECK([$CONFIG_SHELL ./micro-suite -k skipalltests], [], [ignore], [ignore])
897 ## ---------------- ##
898 ## Huge testsuite. ##
899 ## ---------------- ##
901 # Ensure we don't hit line length limits with large test suites.
903 AT_CHECK_AT_TEST([Huge testsuite],
904 [m4_for([nnn], [1], [1999], [],
908 ], [], [], [], [ignore], [], [], [1999])
911 ## ----------------- ##
912 ## Debugging a test. ##
913 ## ----------------- ##
915 AT_CHECK_AT_TEST([Debugging a successful test],
916 [AT_CHECK([:])], [], [], [], [ignore], [],
917 [# Without options, when all tests pass, no test directory should exist.
918 AT_CHECK([test -d micro-suite.dir/1 && exit 42
919 $CONFIG_SHELL ./micro-suite -d 1], [], [ignore], [ignore])
920 # Running with -d should leave a reproducible test group.
921 # Also, running the test script from the test group locks the
922 # directory from removal on some platforms; the script should still be
923 # able to run even if rmdir fails.
924 AT_CHECK([(cd micro-suite.dir/1 && ./run)], [], [ignore], [ignore])
925 # Running a debugging script implies -d.
926 AT_CHECK([(cd micro-suite.dir/1 && ./run)], [], [ignore], [ignore])
929 AT_CHECK_AT_TEST([Debugging script and environment],
930 [AT_CHECK([test "$MY_VAR" = pass || exit 42])],
931 [], [1], [], [ignore], [], [
932 # Changing environment outside of debugging script is not preserved.
933 AT_CHECK([(cd micro-suite.dir/1 && MY_VAR=pass ./run)],
934 [0], [ignore], [ignore])
935 AT_CHECK([(cd micro-suite.dir/1 && ./run)],
936 [1], [ignore], [ignore])
937 # Changing environment as argument to debugging script is preserved.
938 AT_CHECK([(cd micro-suite.dir/1; ./run MY_VAR=pass)],
939 [0], [ignore], [ignore])
940 AT_CHECK([(cd micro-suite.dir/1; ./run)],
941 [0], [ignore], [ignore])
944 # The run script must still be valid when shell metacharacters are passed
945 # in via an environment option.
946 AT_CHECK_AT_TEST([Debugging a failed test],
947 [AT_CHECK([test "$MY_VAR" = "one space" || exit 42])],
948 [], [1], [], [ignore], [], [
949 AT_CHECK([(cd micro-suite.dir/1 && ./run MY_VAR='two spaces')],
950 [1], [ignore], [ignore])
951 AT_CHECK([(cd micro-suite.dir/1 && ./run MY_VAR='one space')],
952 [0], [ignore], [ignore])
956 # Setting default variable values via atlocal.
957 AT_CHECK_AT_TEST([Using atlocal],
958 [AT_CHECK([test "x$MY_VAR" = "xodd; 'string" || exit 42])],
959 [], [1], [ignore], [ignore], [], [
960 dnl check that command line can set variable
961 AT_CHECK([$CONFIG_SHELL ./micro-suite MY_VAR="odd; 'string"], [0], [ignore])
962 dnl check that command line overrides environment
963 AT_CHECK([MY_VAR="odd; 'string" $CONFIG_SHELL ./micro-suite MY_VAR=unset],
964 [1], [ignore], [ignore])
965 dnl check that atlocal can give it a default
966 AT_CHECK([cat <<EOF >atlocal
967 MY_VAR="odd; 'string"
969 dnl Also populate enough of atlocal to do what atconfig normally does.
975 abs_top_srcdir='`pwd`'
977 abs_top_builddir='`pwd`'
980 AT_CHECK([$CONFIG_SHELL ./micro-suite], [0], [ignore])
981 dnl check that atlocal overrides environment
982 AT_CHECK([MY_VAR=unset $CONFIG_SHELL ./micro-suite], [0], [ignore])
983 dnl check that command line overrides atlocal
984 AT_CHECK([$CONFIG_SHELL ./micro-suite MY_VAR=], [1], [ignore], [ignore])
985 dnl check that syntax error is detected
986 AT_CHECK([$CONFIG_SHELL ./micro-suite =], [1], [], [ignore], [ignore])
987 AT_CHECK([$CONFIG_SHELL ./micro-suite 1=2], [1], [], [ignore], [ignore])
991 # Controlling where the testsuite is run.
992 AT_CHECK_AT_TEST([Choosing where testsuite is run],
993 [AT_CHECK([:])], [], [], [], [], [], [
994 dnl AT_CHECK_AT_TEST tests the default of running in `.'.
995 AT_CHECK([$CONFIG_SHELL ./micro-suite --clean])
996 AT_CHECK([test -f micro-suite.log], [1])
997 AT_CHECK([test -d micro-suite.dir], [1])
998 AT_CHECK([mkdir sub1 sub2])
999 dnl check specifying a different relative path to run in.
1000 AT_CHECK([$CONFIG_SHELL ./micro-suite -C sub1], [0], [ignore], [])
1001 AT_CHECK([test -f micro-suite.log], [1])
1002 AT_CHECK([test -f sub1/micro-suite.log], [0])
1003 AT_CHECK([test -d micro-suite.dir], [1])
1004 AT_CHECK([test -d sub1/micro-suite.dir], [0])
1005 AT_CHECK([$CONFIG_SHELL ./micro-suite -C sub1 --clean])
1006 AT_CHECK([test -f sub1/micro-suite.log], [1])
1007 AT_CHECK([test -d sub1/micro-suite.dir], [1])
1008 dnl check specifying an absolute path to run in.
1009 AT_CHECK([$CONFIG_SHELL ./micro-suite --directory="`pwd`/sub2"],
1011 AT_CHECK([test -f micro-suite.log], [1])
1012 AT_CHECK([test -f sub2/micro-suite.log], [0])
1013 AT_CHECK([$CONFIG_SHELL ./micro-suite --clean --directory="`pwd`/sub2"])
1014 AT_CHECK([test -f sub2/micro-suite.log], [1])
1015 AT_CHECK([test -f sub2/micro-suite.dir], [1])
1016 dnl check for failure detection with bad, missing, or empty directory.
1017 AT_CHECK([$CONFIG_SHELL ./micro-suite -C nonesuch || exit 1], [1], [ignore], [ignore])
1018 AT_CHECK([$CONFIG_SHELL ./micro-suite -C ''], [1], [ignore], [ignore])
1019 AT_CHECK([$CONFIG_SHELL ./micro-suite -C - || exit 1], [1], [ignore], [ignore])
1020 AT_CHECK([$CONFIG_SHELL ./micro-suite -C], [1], [ignore], [ignore])
1021 dnl check that --help overrides bad directory selection.
1022 AT_CHECK([$CONFIG_SHELL ./micro-suite -C nonesuch --help], [0], [ignore], [])
1027 AT_CHECK_AT_TEST([recheck],
1030 AT_SETUP([failing test])
1033 AT_SETUP([xpassing test])
1037 AT_SETUP([xfailing test])
1040 ], [], [], [], [], [], [
1041 AT_CHECK([$CONFIG_SHELL ./micro-suite --recheck], [0], [stdout])
1042 AT_CHECK([grep "0 tests were successful" stdout], [0], [ignore])
1044 AT_CHECK([$CONFIG_SHELL ./micro-suite], [1], [ignore], [ignore])
1045 AT_CHECK([grep 'only test' micro-suite.log], [0], [ignore])
1046 AT_CHECK([$CONFIG_SHELL ./micro-suite --recheck], [1], [ignore], [ignore])
1047 AT_CHECK([grep 'only test' micro-suite.log], [1])
1048 AT_CHECK([grep 'xfailing' micro-suite.log], [1])
1049 AT_CHECK([grep 'failing test' micro-suite.log], [0], [ignore])
1050 AT_CHECK([grep 'xpassing test' micro-suite.log], [0], [ignore])
1052 AT_CHECK([$CONFIG_SHELL ./micro-suite --clean], [0])
1053 AT_CHECK([test -f micro-suite.log], [1])
1055 dnl check specifying a different relative path to run in.
1056 AT_CHECK([mkdir sub1])
1057 AT_CHECK([$CONFIG_SHELL ./micro-suite -C sub1], [1], [ignore], [ignore])
1058 AT_CHECK([test -f micro-suite.log], [1])
1059 AT_CHECK([test -f sub1/micro-suite.log], [0])
1060 AT_CHECK([$CONFIG_SHELL ./micro-suite -C sub1 --recheck --list], [0], [stdout])
1061 AT_CHECK([grep 'only test' stdout], [1])
1062 AT_CHECK([grep 'xfailing test' stdout], [1])
1063 AT_CHECK([grep 'failing test' stdout], [0], [ignore])
1064 AT_CHECK([grep 'xpassing test' stdout], [0], [ignore])
1065 AT_CHECK([$CONFIG_SHELL ./micro-suite -C sub1 --recheck], [1], [ignore],
1067 AT_CHECK([grep 'failing test' sub1/micro-suite.log], [0], [ignore])
1068 AT_CHECK([grep 'xpassing test' sub1/micro-suite.log], [0], [ignore])
1077 AT_CHECK_AT_PREP([b],
1100 AT_SETUP(three a)# 6
1103 AT_SETUP(three b)# 7
1108 # AT_CHECK_BANNERS(TESTSUITE-OPTIONS, PATTERN1, COUNT1, PATTERN2, COUNT2)
1109 m4_define([AT_CHECK_BANNERS],
1110 [AT_CHECK([$CONFIG_SHELL ./b $1], [], [stdout])
1111 AT_CHECK_EGREP([$2], m4_if([$3], [0], [1], [0]), [$3])
1112 AT_CHECK_EGREP([$4], m4_if([$5], [0], [1], [0]), [$5])
1115 AT_CHECK_BANNERS([], [first], [1], [second], [1])
1116 AT_CHECK_BANNERS([-k zero], [first], [0], [second], [0])
1117 AT_CHECK_BANNERS([1], [first], [0], [second], [0])
1118 AT_CHECK_BANNERS([-2], [first], [1], [second], [0])
1119 AT_CHECK_BANNERS([-3], [first], [1], [second], [0])
1120 AT_CHECK_BANNERS([-k one], [first], [1], [second], [0])
1121 AT_CHECK_BANNERS([3-4], [first], [1], [second], [0])
1122 dnl There should be an empty line separating the first category from the
1124 AT_CHECK([sed -n '/one b/,/two a/p' stdout | grep '^$'], [0], [ignore])
1125 AT_CHECK_BANNERS([3-6], [first], [1], [second], [1])
1126 AT_CHECK_BANNERS([4-6], [first], [0], [second], [1])
1127 AT_CHECK_BANNERS([3-], [first], [1], [second], [1])
1128 AT_CHECK_BANNERS([-k a], [first], [1], [second], [1])
1129 AT_CHECK_BANNERS([4], [first], [0], [second], [0])
1130 AT_CHECK_BANNERS([4-], [first], [0], [second], [1])
1131 AT_CHECK_BANNERS([-k two], [first], [0], [second], [0])
1132 AT_CHECK_BANNERS([1 4], [first], [0], [second], [0])
1133 AT_CHECK_BANNERS([-k three], [first], [0], [second], [1])
1134 AT_CHECK_BANNERS([5], [first], [0], [second], [0])
1135 AT_CHECK_BANNERS([5-], [first], [0], [second], [1])
1142 AT_SETUP([Keywords and ranges])
1144 AT_CHECK_AT_PREP([k],
1149 AT_SETUP(first) # 02
1153 AT_SETUP(second) # 03
1158 AT_KEYWORDS([key1 key2])
1159 AT_KEYWORDS([m4_echo([Key1])])
1162 AT_SETUP(test5) # 05
1165 AT_SETUP(test6) # 06
1168 AT_SETUP(test7) # 07
1171 AT_SETUP(test8) # 08
1174 AT_SETUP(test9) # 09
1177 AT_SETUP(test10) # 10
1181 dnl check that AT_KEYWORDS does not duplicate words
1182 AT_CHECK([grep -i 'key1.*key1' k], [1])
1183 dnl check that -k requires an argument
1184 AT_CHECK([$CONFIG_SHELL ./k -k], [1], [], [ignore])
1186 # AT_CHECK_KEYS(TESTSUITE-OPTIONS, PATTERN1, COUNT1, PATTERN2, COUNT2)
1187 m4_define([AT_CHECK_KEYS],
1188 [AT_CHECK([$CONFIG_SHELL ./k $1], 0, [stdout])
1189 AT_CHECK_EGREP([$2], 0, [$3])
1190 AT_CHECK_EGREP([$4], 1, [$5])
1193 AT_CHECK_KEYS([-k key1], [first|both], [2], [none|second], [0])
1194 AT_CHECK_KEYS([-k key2], [second|both], [2], [none|first], [0])
1195 AT_CHECK_KEYS([-k key1,key2], [both], [1], [none|first|second], [0])
1196 AT_CHECK_KEYS([-k key1 -k key2], [first|second|both], [3], [none], [0])
1197 AT_CHECK_KEYS([-k '!key1'], [none|second], [2], [first|both], [0])
1198 AT_CHECK_KEYS([-k '!key2'], [none|first], [2], [second|both], [0])
1199 AT_CHECK_KEYS([-k '!key1,key2'], [second], [1], [none|first|both], [0])
1200 AT_CHECK_KEYS([-k 'key1,!key2'], [first], [1], [none|second|both], [0])
1201 AT_CHECK_KEYS([-k '!key1,!key2'], [none], [1], [first|second|both], [0])
1202 AT_CHECK_KEYS([-k '!key1' -k KEY2], [none|second|both], [3], [first], [0])
1203 AT_CHECK_KEYS([-k key1 -k '!key2'], [none|first|both], [3], [second], [0])
1204 AT_CHECK_KEYS([-k '!KEY1' -k '!key2'], [none|first|second], [3], [both], [0])
1206 AT_CHECK_KEYS([-k none], [none], [1], [first|second|both], [0])
1207 AT_CHECK_KEYS([-k key1,both], [both], [1], [none|first|second], [0])
1208 AT_CHECK_KEYS([-k key1 -k both], [first|both], [2], [none|second], [0])
1209 AT_CHECK_KEYS([-k none,first], [successful], [1], [none|first|second|both], [0])
1210 AT_CHECK_KEYS([-k none,first,second,both], [successful], [1], [none|first|second|both], [0])
1211 AT_CHECK_KEYS([-k !none,first], [first], [1], [none|second|both], [0])
1213 AT_CHECK_KEYS([-k '.*eco.*'], [second], [1], [none|first|both], [0])
1214 AT_CHECK_KEYS([-k 'ECO'], [successful], [1], [none|first|second|both], [0])
1215 AT_CHECK_KEYS([-k '.*eco'], [successful], [1], [none|first|second|both], [0])
1216 AT_CHECK_KEYS([-k 'eco.*'], [successful], [1], [none|first|second|both], [0])
1217 AT_CHECK_KEYS([-k 'fir.*'], [first], [1], [none|second|both], [0])
1219 AT_CHECK_KEYS([1-2], [none|first], [2], [second|both], [0])
1220 AT_CHECK_KEYS([01-002 08], [none|first], [2], [second|both], [0])
1221 AT_CHECK_KEYS([1-3 2-1], [none|first|second], [3], [both], [0])
1222 AT_CHECK_KEYS([-3], [none|first|second], [3], [both], [0])
1223 AT_CHECK_KEYS([4-], [both], [1], [none|first|second], [0])
1224 AT_CHECK_KEYS([010], [test10], [1], [none|first|second|both], [0])
1225 AT_CHECK_KEYS([-k second 4-], [second|both], [2], [none|first], [0])
1227 AT_CHECK([$CONFIG_SHELL ./k 0], [1], [ignore], [ignore])
1228 AT_CHECK([$CONFIG_SHELL ./k 0-], [1], [ignore], [ignore])
1229 AT_CHECK([$CONFIG_SHELL ./k -0], [1], [ignore], [ignore])
1230 AT_CHECK([$CONFIG_SHELL ./k 11], [1], [ignore], [ignore])
1231 AT_CHECK([$CONFIG_SHELL ./k 11-], [1], [ignore], [ignore])
1232 AT_CHECK([$CONFIG_SHELL ./k 1-011], [1], [ignore], [ignore])
1233 AT_CHECK([$CONFIG_SHELL ./k -k nonexistent], [0], [ignore])
1235 AT_CHECK_KEYS([--list -k nonexistent], [KEYWORDS], [1], [first|second|both], [0])
1236 AT_CHECK_KEYS([--list 1], [none], [1], [first|second|both], [0])
1237 AT_CHECK_KEYS([--list 01], [none], [1], [first|second|both], [0])
1238 AT_CHECK_KEYS([--list -k none -k first], [none|first], [2], [second|both], [0])
1242 ## ----------------- ##
1243 ## Keyword wrapping. ##
1244 ## ----------------- ##
1245 AT_SETUP([Keyword wrapping])
1247 AT_CHECK_AT_PREP([k],
1250 AT_KEYWORDS([a1 b1 c1 d1 e1 f1 g1 h1 i1 j1 k1 l1 m1 n1 o1 p1 q1 r1 s1 t1])
1251 AT_KEYWORDS([u1 v1 w1 x1 y1 z1])
1252 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])
1254 AT_SETUP([test with long keywords])
1256 [this-is-a-long-keyword-that-cannot-be-wrapped-so-we-exceed-the-length-limit-here])
1257 # surrounded by short ones
1260 [another-very-long-keyword-that-hits-the-line-length-limit-bla-bla-bla-bla])
1265 AT_CHECK_KEYS([-l], [.{80}], [1], [.{87}], [0])
1274 AT_CHECK_AT([AT@&t@_ARG_OPTION],
1276 AT_INIT([artificial test suite])
1277 AT_ARG_OPTION([frob fro fr f],
1278 [AS_HELP_STRING([-f, --frob], [frobnicate the test run])],
1279 [frob=$at_optarg], [frob=default])
1280 AT_ARG_OPTION([opt-with-hyphen],
1281 [AS_HELP_STRING([--opt-with-hyphen], [option name with hypen])])
1282 AT_ARG_OPTION([ping],
1283 [AS_HELP_STRING([--ping], [ping on every encounter])],
1285 AT_SETUP([test argument handling])
1286 AT_CHECK([test "$frob" = "$FROB"])
1287 AT_CHECK([test "$at_arg_frob" = "$FROB_ARG"])
1289 AT_SETUP([test hyphen normalization])
1290 AT_CHECK([test "$at_arg_opt_with_hyphen" = "$expected"])
1293 [], [], [stdout], [], [],
1294 [# We already invoked --help.
1295 AT_CHECK([grep ' -f, --frob.*frobnicate' stdout], [], [ignore])
1297 '1 FROB=default FROB_ARG=false' \
1298 '1 -f FROB=: FROB_ARG=:' \
1299 '1 --fr FROB=: FROB_ARG=:' \
1300 '1 --fro FROB=: FROB_ARG=:' \
1301 '1 --frob FROB=: FROB_ARG=:' \
1302 '1 --no-f FROB=false FROB_ARG=false' \
1303 '1 --no-fr FROB=false FROB_ARG=false' \
1304 '1 --no-fro FROB=false FROB_ARG=false' \
1305 '1 --no-frob FROB=false FROB_ARG=false' \
1306 '2 expected=false' \
1307 '2 --opt-with-hyphen expected=:' \
1308 '2 --no-opt-with-hyphen expected=false'
1310 AT_CHECK([$CONFIG_SHELL ./micro-suite -x $args], [], [ignore])
1312 AT_CHECK([$CONFIG_SHELL ./micro-suite 2 --ping --no-ping --ping expected=false],
1314 AT_CHECK([grep -c ping stdout], [], [[3
1319 ## ----------------- ##
1320 ## AT_ARG_OPTION_ARG ##
1321 ## ----------------- ##
1323 AT_CHECK_AT([AT@&t@_ARG_OPTION_ARG],
1325 AT_INIT([artificial test suite])
1326 AT_ARG_OPTION_ARG([frob fro fr f],
1327 [AS_HELP_STRING([-f, --frob=FOO], [frobnicate FOO])],
1328 [frob=$at_optarg], [frob=default])
1329 AT_ARG_OPTION_ARG([opt-with-hyphen],
1330 [AS_HELP_STRING([--opt-with-hyphen=ARG],
1331 [option name with hypen])])
1332 AT_ARG_OPTION_ARG([ping],
1333 [AS_HELP_STRING([--ping], [ping on every encounter])],
1335 AT_SETUP([test argument handling])
1336 AT_CHECK([test "$frob" = "$FROB"])
1337 AT_CHECK([test "$at_arg_frob" = "$FROB_ARG"])
1339 AT_SETUP([test hyphen normalization])
1340 AT_CHECK([test "$at_arg_opt_with_hyphen" = "$expected"])
1343 [], [], [stdout], [], [],
1344 [# We already invoked --help.
1345 AT_CHECK([grep ' -f, --frob.*frobnicate' stdout], [], [ignore])
1346 AT_CHECK([$CONFIG_SHELL ./micro-suite -x --frob], [1], [ignore], [stderr])
1347 AT_CHECK([grep 'requires an argument' stderr], [], [ignore])
1348 AT_CHECK([$CONFIG_SHELL ./micro-suite -x --no-frob], [1], [ignore], [stderr])
1349 AT_CHECK([grep 'invalid option' stderr], [], [ignore])
1351 '1 FROB=default FROB_ARG=' \
1352 '1 -f bar FROB=bar FROB_ARG=bar' \
1353 '1 --fr bar FROB=bar FROB_ARG=bar' \
1354 '1 --fro bar FROB=bar FROB_ARG=bar' \
1355 '1 --frob bar FROB=bar FROB_ARG=bar' \
1356 '1 -f=bar FROB=bar FROB_ARG=bar' \
1357 '1 --fr=bar FROB=bar FROB_ARG=bar' \
1358 '1 --fro=bar FROB=bar FROB_ARG=bar' \
1359 '1 --frob=bar FROB=bar FROB_ARG=bar' \
1361 '2 --opt-with-hyphen=baz expected=baz'
1363 AT_CHECK([$CONFIG_SHELL ./micro-suite -x $args], [], [ignore])
1365 AT_CHECK([$CONFIG_SHELL ./micro-suite 2 --ping=1 --ping=2 expected=],
1367 AT_CHECK([grep -c ping stdout], [], [[2
1372 m4_define([AT_SKIP_PARALLEL_TESTS],
1373 [# Per BUGS, we have not yet figured out how to run parallel tests cleanly
1374 # under dash and some ksh variants. For now, only run this test under
1375 # limited conditions; help is appreciated in widening this test base.
1376 AT_SKIP_IF([${CONFIG_SHELL-$SHELL} -c 'test -z "${BASH_VERSION+set}]]dnl
1377 [[${ZSH_VERSION+set}${TEST_PARALLEL_AUTOTEST+set}"'])
1378 # The parallel scheduler requires mkfifo and job control to work.
1379 AT_CHECK([mkfifo fifo || exit 77])
1380 AT_CHECK([${CONFIG_SHELL-$SHELL} -c '(set -m && set +m) || exit 77'],
1385 ## ----------------------- ##
1386 ## parallel test execution ##
1387 ## ----------------------- ##
1389 AT_SETUP([parallel test execution])
1391 # This test tries to ensure that -j runs tests in parallel.
1392 # Such a test is inherently racy, because there are no real-time
1393 # guarantees about scheduling delays. So we try to minimize
1394 # the chance to lose the race.
1396 # The time needed for a micro-suite consisting of NTESTS tests each
1397 # sleeping for a second is estimated by
1398 # startup + ntests * (serial_overhead + 1 / njobs)
1400 # in absence of major scheduling delays. This leads to side conditions:
1401 # - NTESTS should be high, so the STARTUP time is small compared to the
1402 # test run time, and scheduling delays can even out; it should not be
1403 # too high, to not slow down the testsuite unnecessarily,
1404 # - the number of concurrent jobs NJOBS should not be too low, so the
1405 # race is not lost so easily; it should not be too high, to avoid fork
1406 # failures on tightly limited systems. 4 seems a good compromise
1407 # here, considering that Autotest spawns several other processes.
1408 # - STARTUP is assumed to be the same for parallel and serial runs, so
1409 # the latter can estimate the former.
1410 # - To avoid unportable output from time measurement commands, spawn
1411 # both a parallel and a serial testsuite run; check that the former
1412 # completes before the latter has completed a fraction SERIAL_NTESTS
1413 # of the tests (the serial run is executed in a subdirectory), plus
1414 # some additional time to allow for compensation of SERIAL_OVERHEAD.
1415 # - when adding this time to the serial test execution, an initial delay
1416 # SERIAL_DELAY of the serial test helps to avoid unreliable scheduling
1417 # due to the startup burst of the suites.
1419 dnl total number of tests.
1420 m4_define([AT_PARALLEL_NTESTS], [16])
1421 dnl number of jobs to run in parallel.
1422 m4_define([AT_PARALLEL_NJOBS], [4])
1423 dnl number of tests to run serially, as comparison.
1424 m4_define([AT_PARALLEL_SERIAL_NTESTS],
1425 m4_eval(AT_PARALLEL_NTESTS / AT_PARALLEL_NJOBS))
1426 dnl initial delay of serial run, to compensate for SERIAL_OVERHEAD.
1427 dnl This corresponds to 0.67 s of overhead per test.
1428 m4_define([AT_PARALLEL_SERIAL_DELAY],
1429 m4_eval((AT_PARALLEL_NTESTS - AT_PARALLEL_SERIAL_NTESTS + 1) * 2 / 3))
1432 AT_CHECK_AT_PREP([micro-suite],
1433 [[AT_INIT([suite to test parallel execution])
1434 m4_for([count], [1], ]]AT_PARALLEL_NTESTS[[, [],
1435 [AT_SETUP([test number count])
1441 # Even if parallel jobs are not supported, the command line must work.
1442 AT_CHECK([$CONFIG_SHELL ./micro-suite --help | grep " --jobs"], [0], [ignore])
1443 AT_CHECK([$CONFIG_SHELL ./micro-suite -j2foo], [1], [], [stderr])
1444 AT_CHECK([grep 'non-numeric argument' stderr], [], [ignore])
1445 AT_CHECK([$CONFIG_SHELL ./micro-suite --jobs=foo], [1], [], [stderr])
1446 AT_CHECK([grep 'non-numeric argument' stderr], [], [ignore])
1448 AT_SKIP_PARALLEL_TESTS
1450 # Ensure that all tests run, and lines are not split.
1451 AT_CHECK([$CONFIG_SHELL ./micro-suite -j[]AT_PARALLEL_NJOBS], [], [stdout])
1452 AT_CHECK([grep -c '^.\{53\}ok' stdout], [], [AT_PARALLEL_NTESTS
1454 # Running one test with -j should produce correctly formatted output:
1455 AT_CHECK([$CONFIG_SHELL ./micro-suite -j 3], [], [stdout])
1456 AT_CHECK([grep -c '^.\{53\}ok' stdout], [], [1
1458 # Specifying more jobs than tests should not hang:
1459 AT_CHECK([$CONFIG_SHELL ./micro-suite -j3 3], [], [stdout])
1460 AT_CHECK([grep -c '^.\{53\}ok' stdout], [], [1
1462 # Not even with zero tests:
1463 AT_CHECK([$CONFIG_SHELL ./micro-suite -j -k nomatch], [], [ignore])
1464 AT_CHECK([$CONFIG_SHELL ./micro-suite -j3 -k nomatch], [], [ignore])
1468 # Unfortunately, the return value of wait is unreliable,
1469 # so we check that kill fails.
1470 AT_CHECK([$CONFIG_SHELL ./micro-suite --jobs=[]AT_PARALLEL_NJOBS & ]dnl
1471 [sleep AT_PARALLEL_SERIAL_DELAY && ]dnl
1472 [cd serial && $CONFIG_SHELL ../micro-suite -AT_PARALLEL_SERIAL_NTESTS >/dev/null && ]dnl
1473 [{ kill $! && exit 1; :; }], [], [stdout], [ignore])
1474 AT_CHECK([grep -c '^.\{53\}ok' stdout], [], [AT_PARALLEL_NTESTS
1476 AT_CHECK([grep 'AT_PARALLEL_NTESTS tests' stdout], [], [ignore])
1480 AT_CHECK_AT_TEST([parallel truth],
1481 [AT_CHECK([:], 0, [], [])],
1482 [], [], [], [], [AT_SKIP_PARALLEL_TESTS],
1485 AT_CHECK_AT_TEST([parallel fallacy],
1486 [AT_CHECK([false], [], [], [])],
1487 [], [1], [], [ignore], [AT_SKIP_PARALLEL_TESTS],
1488 [AT_CHECK([grep failed micro-suite.log], [], [ignore])], [-j])
1490 AT_CHECK_AT_TEST([parallel skip],
1491 [AT_CHECK([echo output; echo irrelevant >&2; exit 77], 0, [mismatch], [])],
1492 [], [], [], [], [AT_SKIP_PARALLEL_TESTS],
1493 [AT_CHECK([grep skipped micro-suite.log], [], [ignore])], [-j])
1495 AT_CHECK_AT_TEST([parallel syntax error],
1501 AT_SETUP([another test])
1503 [], [0], [], [], [AT_SKIP_PARALLEL_TESTS],
1504 [dnl Until we can find a way to avoid catastrophic failure (ash) or
1505 dnl lack of failure (zsh), skip the rest of this test on such shells.
1507 AT_CHECK([${CONFIG_SHELL-$SHELL} -c 'case `. ./syntax; echo $?` in
1509 esac'], [0], [ignore], [ignore])
1510 AT_CHECK([${CONFIG_SHELL-$SHELL} ./micro-suite -j], [1], [ignore], [stderr])
1511 AT_CHECK([grep "unable to parse test group: 2" stderr], [0], [ignore])],
1514 AT_CHECK_AT_TEST([parallel errexit],
1517 AT_SETUP([barrier test])
1520 AT_SETUP([test that should not be run])
1522 [], [1], [stdout], [stderr], [AT_SKIP_PARALLEL_TESTS],
1523 [AT_CHECK([test -f micro-suite.log], [1])
1524 touch micro-suite.log # shut up AT_CAPTURE_FILE.
1525 AT_CHECK([grep "should not be run" stdout], [1])
1526 AT_CHECK([grep "[[12]] .* inhibited subsequent" stderr], [], [ignore])],
1530 AT_SETUP([parallel autotest and signal handling])
1532 AT_SKIP_PARALLEL_TESTS
1535 # (1) interrupt `./testsuite -jN'
1536 # (2) interrupt `make check TESTSUITEFLAGS=-jN'
1537 # (3) no trailing verbose/trace output
1538 # (4) exit status should be 128+signal
1545 AT_CHECK_AT_PREP([micro-suite],
1546 [[AT_INIT([suite to test parallel execution])
1547 AT_SETUP([test number 1])
1550 AT_SETUP([test number 2])
1553 AT_SETUP([test number 3])
1556 AT_SETUP([killer test])
1557 AT_CHECK([kill -$signal $suite_pid])
1559 m4_for([count], [5], [7], [],
1560 [AT_SETUP([test number count])
1566 AT_DATA([Makefile.in],
1569 TESTSUITE = ./micro-suite
1571 $(SHELL) '$(TESTSUITE)' $(TESTSUITEFLAGS)
1575 AT_CHECK([$CONFIG_SHELL $abs_top_builddir/config.status --file=Makefile:Makefile.in],
1578 # Test INT and TERM.
1579 for signal in 2 15; do
1581 AS_VAR_ARITH([expected_status], [128 + $signal])
1584 AT_CHECK([$CONFIG_SHELL ./micro-suite], [$expected_status],
1586 # Both stderr and the log should contain the notification about the signal.
1587 AT_CHECK([grep 'bailing out' stderr], [], [ignore])
1588 AT_CHECK([grep 'bailing out' micro-suite.log], [], [ignore])
1589 # There should be no junk job status output.
1590 AT_CHECK([[grep '[iI]nterrupt[ ]' stderr]], [1])
1593 AT_CHECK([$CONFIG_SHELL ./micro-suite --jobs=3], [$expected_status],
1595 AT_CHECK([grep 'bailing out' stderr], [], [ignore])
1596 AT_CHECK([grep 'bailing out' micro-suite.log], [], [ignore])
1597 # We'd like to check this here, too, but some shells do not allow to
1598 # turn off job control.
1599 # AT_CHECK([[grep '[iI]nterrupt[ ]' stderr]], [1])
1601 # Ditto with `make' in the loop.
1604 # Need to eliminate outer TESTSUITEFLAGS here.
1605 # Need to normalize exit status here: some make implementations
1606 # exit 1 (BSD make), some exit 2 (GNU make).
1607 AT_CHECK([$MAKE check TESTSUITEFLAGS=; ]dnl
1608 [case $? in 1|2) exit 1;; *) exit $?;; esac],
1609 [1], [ignore], [stderr])
1610 AT_CHECK([grep 'bailing out' stderr], [], [ignore])
1611 AT_CHECK([grep 'bailing out' micro-suite.log], [], [ignore])
1612 # Ditto, parallel case.
1613 AT_CHECK([$MAKE check TESTSUITEFLAGS=--jobs=3; ]dnl
1614 [case $? in 1|2) exit 1;; *) exit $?;; esac],
1615 [1], [ignore], [stderr])
1616 AT_CHECK([grep 'bailing out' stderr], [], [ignore])
1617 AT_CHECK([grep 'bailing out' micro-suite.log], [], [ignore])
1622 # The most important part here is that things should not hang, nor
1623 # get out of hand. OTOH, if the shell sets the default handler to
1624 # ignore PIPE (pdksh, dash), there is little we can do about having the
1625 # test run; it's only the output that won't be there. So all we check
1626 # for is that, if test 7 didn't run serially, then it shouldn't be
1627 # run in the parallel case either; the intermediate tests serve as
1629 # Note that stderr may contain "Broken pipe" errors.
1630 AT_CHECK([($CONFIG_SHELL ./micro-suite -d -3 5-; echo $? >status) | sed 5q],
1631 [], [stdout], [stderr])
1632 AT_CHECK([grep '5.*ok' stdout], [1])
1633 # Apparently some shells don't get around to creating 'status' any more.
1634 # And ksh93 on FreeBSD uses 256 + 13 instead of 128 + 13
1635 AT_CHECK([test ! -s status || grep 141 status || grep 269 status],
1637 AT_CHECK([if test -f micro-suite.dir/7/micro-suite.log; then ]dnl
1638 [ echo "shell ignores SIGPIPE" > sigpipe-stamp ]dnl
1641 AT_CHECK([$CONFIG_SHELL ./micro-suite -d -3 5- --jobs=2 | sed 5q], [], [stdout], [ignore])
1642 AT_CHECK([grep '5.*ok' stdout], [1])
1643 AT_CHECK([test -s sigpipe-stamp || test ! -f micro-suite.dir/7/micro-suite.log], [0])
1648 # Avoid running into a regression when mkfifo does not work.
1649 AT_CHECK_AT_TEST([parallel args but non-working mkfifo],
1652 AT_SETUP([second test])
1655 [], [], [stdout], [stderr],
1656 [AT_SKIP_PARALLEL_TESTS
1658 cat >bin/mkfifo <<\EOF
1663 PATH=`pwd`/bin:$PATH
1666 [AT_CHECK([grep 'second test' stdout], [], [ignore])
1671 AT_CHECK_AT_TEST([colored test results],
1688 AT_SETUP([hardfail])
1691 ], [], [], [], [], [], [
1696 red=`printf '\033@<:@0;31m'`
1697 grn=`printf '\033@<:@0;32m'`
1698 lgn=`printf '\033@<:@1;32m'`
1699 blu=`printf '\033@<:@1;34m'`
1700 std=`printf '\033@<:@m'`
1702 # Check that grep can parse nonprinting characters.
1703 # BSD 'grep' works from a pipe, but not a seekable file.
1704 # GNU or BSD 'grep -a' works on files, but is not portable.
1705 AT_CHECK([case `echo "$std" | grep .` in #'' restore font-lock
1708 esac], [], [ignore], [],
1709 [echo "grep can't parse nonprinting characters" >&2])
1711 if echo 'ab*c' | grep -F 'ab*c' >/dev/null 2>&1; then
1718 AT_CHECK([$CONFIG_SHELL ./micro-suite], [1], [stdout], [stderr])
1719 for color in "$red" "$grn" "$lgn" "$blu"; do
1720 AT_CHECK([cat stdout stderr | $FGREP "$color"], [1])
1723 # Color of test group results.
1724 AT_CHECK([$CONFIG_SHELL ./micro-suite --color=always], [1], [stdout], [stderr])
1725 AT_CHECK([cat stdout | grep " only " | $FGREP "$grn"], [], [ignore])
1726 AT_CHECK([cat stdout | grep " fail " | $FGREP "$red"], [], [ignore])
1727 AT_CHECK([cat stdout | grep " xfail " | $FGREP "$lgn"], [], [ignore])
1728 AT_CHECK([cat stdout | grep " xpass " | $FGREP "$red"], [], [ignore])
1729 AT_CHECK([cat stdout | grep " skip " | $FGREP "$blu"], [], [ignore])
1730 AT_CHECK([cat stdout | grep " hardfail " | $FGREP "$red"], [], [ignore])
1731 AT_CHECK([cat stderr | grep ERROR | $FGREP "$red"], [], [ignore])
1733 # The summary is green if all tests were successful, light green if all
1734 # behaved as expected, and red otherwise.
1735 AT_CHECK([$CONFIG_SHELL ./micro-suite --color=always 1 -k skip],
1737 AT_CHECK([cat stdout | grep 'test.*successful' | $FGREP "$grn"],
1739 AT_CHECK([$CONFIG_SHELL ./micro-suite --color=always 1 -k xfail -k skip],
1741 AT_CHECK([cat stdout | grep 'as expected' | $FGREP "$lgn"], [], [ignore])
1742 AT_CHECK([$CONFIG_SHELL ./micro-suite --color=always -k fail],
1743 [1], [ignore], [stderr])
1744 AT_CHECK([cat stderr | grep ERROR | $FGREP "$red"], [], [ignore])
1745 AT_CHECK([$CONFIG_SHELL ./micro-suite --color=always -k xpass],
1746 [1], [ignore], [stderr])
1747 AT_CHECK([cat stderr | grep ERROR | $FGREP "$red"], [], [ignore])
1748 AT_CHECK([$CONFIG_SHELL ./micro-suite --color=always -k hardfail],
1749 [1], [ignore], [stderr])
1750 AT_CHECK([cat stderr | grep ERROR | $FGREP "$red"], [], [ignore])
1751 # Reset color on verbose output.
1756 ## ------------------- ##
1757 ## srcdir propagation. ##
1758 ## ------------------- ##
1760 AT_SETUP([srcdir propagation])
1761 AT_KEYWORDS([AC_@&t@CONFIG_TESTDIR])
1763 mkdir pkg vpath-outside vpath-abs
1764 mkdir pkg/t pkg/vpath-inside
1768 AT_DATA([pkg/configure.ac], [[AC_INIT
1769 AC_CONFIG_TESTDIR([t])
1772 cp "$abs_top_srcdir/build-aux/install-sh" pkg
1778 AT_CHECK_AT_PREP([suite],
1779 [[AT_INIT([suite to check srcdir])
1780 AT_SETUP([my only test])
1781 AT_CHECK([test -f "$top_srcdir"/a && test -f "$srcdir"/b])
1783 ]], [], [], [], [pkg/t])
1785 rm -f pkg/t/atconfig
1787 # Build directory totally outside source directory.
1789 AT_CHECK([../pkg/configure $configure_options], [0], [ignore])
1791 AT_CHECK([../../pkg/t/suite], [0], [ignore])
1792 AT_CHECK([../../pkg/t/suite -v], [0], [stdout])
1793 AT_CHECK([grep '^\.\./\.\./pkg/t/suite.at' stdout], [0], [ignore])
1796 # Build directory totally outside source directory (absolute).
1799 AT_CHECK(["$my_srcdir"/configure $configure_options], [0], [ignore])
1801 AT_CHECK(["$my_srcdir"/t/suite], [0], [ignore])
1802 AT_CHECK(["$my_srcdir"/t/suite -v], [0], [stdout])
1803 AT_CHECK([grep '..*/t/suite.at' stdout], [0], [ignore])
1806 # Build directory as subdirectory of source directory.
1808 AT_CHECK([../configure $configure_options], [0], [ignore])
1810 AT_CHECK([../../t/suite], [0], [ignore])
1811 AT_CHECK([../../t/suite -v], [0], [stdout])
1812 AT_CHECK([grep '^\.\./\.\./t/suite.at' stdout], [0], [ignore])
1815 # Build directory as parent of source directory.
1816 AT_CHECK([pkg/configure $configure_options], [0], [ignore])
1818 AT_CHECK([../pkg/t/suite], [0], [ignore])
1819 AT_CHECK([../pkg/t/suite -v], [0], [stdout])
1820 AT_CHECK([grep '^\.\./pkg/t/suite.at' stdout], [0], [ignore])
1823 # Build directory as source directory.
1827 AT_CHECK([./suite], [0], [ignore])
1828 AT_CHECK([./suite -v], [0], [stdout])
1829 AT_CHECK([grep '^\./suite.at' stdout], [0], [ignore])
1835 ## ------------------------------ ##
1836 ## whitespace in absolute testdir ##
1837 ## ------------------------------ ##
1839 AT_SETUP([whitespace in absolute testdir])
1841 dir='dir with whitespace'
1847 AT_CHECK_AT_PREP([suite],
1848 [[AT_INIT([suite to check srcdir])
1849 AT_SETUP([my only test])
1850 AT_CHECK([test -f "$top_srcdir"/a])
1853 AT_CHECK([top_srcdir=$wd ./suite], [0], [ignore])
1854 AT_CHECK([top_srcdir=$wd ./suite -d], [0], [ignore])
1855 AT_CHECK([cd suite.dir/1 && ./run top_srcdir="$wd"], [0], [ignore], [ignore])
1859 ## ------------------ ##
1860 ## unusual file names ##
1861 ## ------------------ ##
1863 AT_SETUP([unusual file names])
1865 AT_DATA_AUTOTEST([d@&t@nl.at],
1866 [[AT_SETUP([test one])
1867 m4_pattern_allow([^dnl$])
1868 AT_CHECK([test "]m4_dquote(AT_LINE)[" = dn[]l.at:3])
1873 AT_DATA_AUTOTEST([sub/"two spaces".at],
1874 [[AT_SETUP([test two])
1875 AT_CHECK([test "]m4_dquote(AT_LINE)[" = "two spaces.at:2"])
1879 AT_CHECK_AT_PREP([suite],
1880 [[AT_INIT([suite to check included file names])
1881 m4_include([d][nl.at])
1882 m4_include([sub/two spaces.at])
1884 AT_CHECK([$CONFIG_SHELL ./suite], [0], [stdout])
1885 AT_CHECK([grep 'two spaces' suite.log], [1])
1889 ## --------------- ##
1890 ## C executables. ##
1891 ## --------------- ##
1893 AT_SETUP([C unit tests])
1894 AT_KEYWORDS([AC_@&t@CONFIG_TESTDIR])
1895 AT_KEYWORDS([AT_@&t@TESTED])
1898 AT_DATA([configure.ac], [[AC_INIT
1900 AC_CONFIG_TESTDIR([t], [.])
1901 AC_CONFIG_FILES([Makefile])
1906 AT_DATA([testprog.c],
1907 [[int main(int argc) { return argc == 2 ? 0 : 1; }
1911 AT_DATA([Makefile.in],
1915 testprog@EXEEXT@: testprog.o
1916 testprog.o: testprog.c
1917 .SUFFIXES: .c .o @EXEEXT@
1925 AT_CHECK_AT_PREP([suite],
1926 [[AT_INIT([suite to check C programs])
1927 AT_TESTED([testprog$EXEEXT])
1928 AT_SETUP([my only test])
1929 AT_CHECK([testprog$EXEEXT foo], [0])
1930 AT_CHECK([testprog$EXEEXT], [1])
1932 ]], [], [], [], [t])
1937 AT_CHECK([grep '^EXEEXT='\''.*'\' t/atconfig], [], [ignore])
1938 AT_CHECK([make], [], [ignore])
1939 AT_CHECK([cd t && $CONFIG_SHELL ./suite], [], [ignore])
1940 AT_CHECK([grep 1.*successful t/suite.log], [], [ignore])
1944 ## -------------------------------------- ##
1945 ## C executables (force .exe extension). ##
1946 ## -------------------------------------- ##
1948 AT_SETUP([C unit tests (EXEEXT)])
1949 AT_KEYWORDS([AC_@&t@CONFIG_TESTDIR])
1950 AT_KEYWORDS([AT_@&t@TESTED])
1953 AT_DATA([configure.ac], [[AC_INIT
1955 case $ac_cv_exeext in
1960 AC_SUBST([EXEEXT], [$ac_cv_exeext])
1961 AC_CONFIG_TESTDIR([t], [.])
1962 AC_CONFIG_FILES([Makefile])
1967 AT_DATA([testprog.c],
1968 [[int main(int argc) { return argc == 2 ? 0 : 1; }
1972 AT_DATA([Makefile.in],
1976 testprog@EXEEXT@: testprog.o
1977 testprog.o: testprog.c
1978 .SUFFIXES: .c .o @EXEEXT@
1986 AT_CHECK_AT_PREP([suite],
1987 [[AT_INIT([suite to check C programs])
1988 AT_TESTED([testprog$EXEEXT])
1989 AT_SETUP([my only test])
1990 AT_CHECK([testprog$EXEEXT foo], [0])
1991 AT_CHECK([testprog$EXEEXT], [1])
1993 ]], [], [], [], [t])
1998 AT_CHECK([grep '^EXEEXT='\''.*'\' t/atconfig], [], [ignore])
1999 AT_CHECK([make], [], [ignore])
2000 AT_CHECK([cd t && $CONFIG_SHELL ./suite], [], [ignore])
2001 AT_CHECK([grep 1.*successful t/suite.log], [], [ignore])
2005 ## ------------------------- ##
2006 ## Erlang EUnit unit tests. ##
2007 ## ------------------------- ##
2009 AT_SETUP([Erlang Eunit unit tests])
2010 AT_KEYWORDS([Erlang])
2011 AT_KEYWORDS([AC_@&t@CONFIG_TESTDIR])
2014 AT_DATA([configure.ac], [[AC_INIT
2015 AC_ERLANG_PATH_ERL([no])
2016 AC_ERLANG_PATH_ERLC([no])
2017 if test "$ERL" = "no" || test "$ERLC" = "no"; then
2022 AC_ERLANG_CHECK_LIB([eunit], [HAVE_EUNIT=yes], [HAVE_EUNIT=no])
2024 AC_SUBST([HAVE_ERLANG])
2025 AC_SUBST([HAVE_EUNIT])
2027 AC_CONFIG_TESTDIR([t])
2028 AC_CONFIG_FILES([s/compile], [chmod +x s/compile])
2029 AC_CONFIG_FILES([erlang.conf])
2033 # File to pass info back to us
2034 AT_DATA([erlang.conf.in],
2035 [[HAVE_ERLANG=@HAVE_ERLANG@
2036 HAVE_EUNIT=@HAVE_EUNIT@
2039 # Erlang module to test:
2040 AT_DATA([s/testme.erl],
2048 # Corresponding Eunit unit test module:
2049 AT_DATA([s/testme_tests.erl],
2050 [[-module(testme_tests).
2051 -include_lib("eunit/include/eunit.hrl").
2052 foo_one_test() -> ?assertEqual(one, testme:foo(1)).
2053 foo_two_test() -> ?assertEqual(two, testme:foo(2)).
2054 foo_other_test() -> ?assertEqual(other, testme:foo(42)).
2057 # Compilation script:
2058 AT_DATA([s/compile.in],
2059 [["@ERLC@" -b beam testme.erl testme_tests.erl
2062 AT_CHECK_AT_PREP([suite],
2063 [[AT_INIT([suite to check EUnit integration])
2064 AT_SETUP([my only test])
2065 AT_CHECK_EUNIT([my_testsuite], [{module, testme}],
2066 [-pa "${abs_top_builddir}/s"])
2068 ]], [], [], [], [t])
2074 AT_CHECK([grep '^ERL='\''.*'\' t/atconfig], [], [ignore])
2075 AT_CHECK([grep '^ERLC='\''.*'\' t/atconfig], [], [ignore])
2076 AT_CHECK([grep '^ERLCFLAGS='\''.*'\' t/atconfig], [], [ignore])
2078 if test "$HAVE_ERLANG" = yes && test "$HAVE_EUNIT" = yes; then
2079 AT_CHECK([cd s && $CONFIG_SHELL ./compile])
2082 AT_CHECK([cd t && $CONFIG_SHELL ./suite], [], [ignore])
2084 if test "$HAVE_EUNIT" = yes; then
2085 AT_CHECK([grep 1.*successful t/suite.log], [], [ignore])
2086 AT_CHECK([grep skipped t/suite.log], [1], [ignore])
2088 AT_CHECK([grep 1.*skipped t/suite.log], [], [ignore])
2089 AT_CHECK([grep 0.*successful t/suite.log], [], [ignore])