5 # Copyright (C) 2004-2011 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 occuring 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 ## Empty test suite. ##
182 ## ------------------ ##
184 # This is not a sensible thing to do, but the user should not get an unhelpful
186 AT_CHECK_AT([Empty test suite],
187 [[AT_INIT([empty test suite])
190 AT_CHECK_AT([Banner-only test suite],
191 [[AT_INIT([empty test suite])
195 # Next level of emptiness.
196 AT_CHECK_AT_TEST([Empty test], [])
198 # And finally, an empty check should not cause a syntax error.
199 AT_CHECK_AT_TEST([Empty check], [AT_CHECK])
201 # Check for sensible error messages for common bugs.
202 AT_CHECK_AT_SYNTAX([AT@&t@_SETUP without AT@&t@_INIT],
203 [[AT_SETUP([only test])
206 ]], [AT@&t@_SETUP: missing AT@&t@_INIT detected])
208 AT_CHECK_AT_SYNTAX([AT@&t@_BANNER without AT@&t@_INIT],
209 [[AT_BANNER([just a banner])
210 ]], [AT@&t@_BANNER: missing AT@&t@_INIT detected])
212 AT_CHECK_AT_SYNTAX([AT@&t@_CLEANUP without AT@&t@_INIT],
214 ]], [AT@&t@_CLEANUP: missing AT@&t@_INIT detected])
216 AT_CHECK_AT_SYNTAX([Missing AT@&t@_CLEANUP],
217 [[AT_INIT([incomplete test suite])
218 AT_SETUP([only test])
220 ]], [missing AT@&t@_CLEANUP detected])
222 AT_CHECK_AT_SYNTAX([AT@&t@_FAIL_IF without AT@&t@_SETUP],
223 [[AT_INIT([incomplete test suite])
225 ]], [AT@&t@_FAIL_IF: missing AT@&t@_SETUP detected])
227 AT_CHECK_AT_SYNTAX([AT@&t@_SKIP_IF without AT@&t@_SETUP],
228 [[AT_INIT([incomplete test suite])
230 ]], [AT@&t@_SKIP_IF: missing AT@&t@_SETUP detected])
232 AT_CHECK_AT_SYNTAX([AT@&t@_CHECK without AT@&t@_SETUP],
233 [[AT_INIT([incomplete test suite])
235 ]], [AT@&t@_CHECK: missing AT@&t@_SETUP detected])
237 AT_CHECK_AT_SYNTAX([AT@&t@_DATA without AT@&t@_SETUP],
238 [[AT_INIT([incomplete test suite])
240 ]], [AT@&t@_DATA: missing AT@&t@_SETUP detected])
242 AT_CHECK_AT_SYNTAX([AT@&t@_XFAIL_IF without AT@&t@_SETUP],
243 [[AT_INIT([incomplete test suite])
245 ]], [AT@&t@_XFAIL_IF: missing AT@&t@_SETUP detected])
247 AT_CHECK_AT_SYNTAX([AT@&t@_KEYWORDS without AT@&t@_SETUP],
248 [[AT_INIT([incomplete test suite])
249 AT_KEYWORDS([keyword])
250 ]], [AT@&t@_KEYWORDS: missing AT@&t@_SETUP detected])
252 AT_CHECK_AT_SYNTAX([AT@&t@_CLEANUP without AT@&t@_SETUP],
253 [[AT_INIT([incomplete test suite])
255 ]], [AT@&t@_CLEANUP: missing AT@&t@_SETUP detected])
257 AT_CHECK_AT_SYNTAX([AT@&t@_BANNER inside AT@&t@_SETUP],
258 [[AT_INIT([incomplete test suite])
259 AT_SETUP([only test])
263 ]], [AT@&t@_BANNER: nested AT@&t@_SETUP detected])
265 AT_CHECK_AT_SYNTAX([AT@&t@_SETUP inside AT@&t@_SETUP],
266 [[AT_INIT([incomplete test suite])
267 AT_SETUP([only test])
268 AT_SETUP([nested test])
273 ]], [AT@&t@_SETUP: nested AT@&t@_SETUP detected])
275 AT_CHECK_AT_SYNTAX([Multiple AT@&t@_INIT],
276 [[AT_INIT([[suite, take one]])
278 ]], [AT@&t@_INIT: invoked multiple times])
280 # Check for tested programs. autoconf should only appear once.
281 AT_CHECK_AT([Tested programs],
282 [[AT_INIT([programs test suite])
283 AT_TESTED([autoconf autom4te])
284 AT_TESTED([autoconf])
285 ]], [], [], [], [], [],
286 [AT_CHECK([[sed -n 's|.*/\([^ /]* --version\)|\1|p' micro-suite.log]], [],
291 AT_CHECK_AT([Startup error messages],
293 AT_SETUP([only test])
296 ]], [], [], [], [], [],
297 [AT_CHECK([sed -n '/exec AS_MESSAGE_LOG_FD/q; />&AS_MESSAGE_LOG_FD/p' < micro-suite])])
299 ## ----------------- ##
300 ## Status handling. ##
301 ## ----------------- ##
303 AT_CHECK_AT_TEST([Truth],
304 [AT_CHECK([:], 0, [], [])])
306 AT_CHECK_AT_TEST([Fallacy],
307 [AT_CHECK([false], [], [], [])],
308 [], [1], [], [ignore], [],
309 [AT_CHECK([grep failed micro-suite.log], [], [ignore])])
311 AT_CHECK_AT_TEST([Skip],
312 [AT_CHECK([echo output; echo irrelevant >&2; exit 77], 0, [mismatch], [])],
314 [AT_CHECK([grep skipped micro-suite.log], [], [ignore])])
316 AT_CHECK_AT_TEST([Hard fail],
319 AT_SETUP([another test])
321 AT_CHECK([exit 99])],
322 [], [1], [], [ignore], [],
323 [AT_CHECK([grep '2 failed unexpectedly' micro-suite.log], [], [ignore])
324 AT_CHECK([grep '^[[12]].*ok' micro-suite.log], [1])])
326 AT_CHECK_AT_TEST([AT@&t@_FAIL_IF],
333 AT_FAIL_IF([test x = y])
339 AT_FAIL_IF([test x = x])
342 AT_FAIL_IF([test $foo = x])],
343 [], [1], [stdout], [ignore], [],
344 [AT_CHECK([grep '1 5 failed' stdout], [], [ignore], [ignore])])
346 AT_CHECK_AT_TEST([AT@&t@_SKIP_IF],
353 AT_SKIP_IF([test x = y])
359 AT_SKIP_IF([test x = x])
362 AT_SKIP_IF([test $foo = x])],
364 [AT_CHECK([grep '2.*skipped' micro-suite.log], [], [ignore], [ignore])])
366 AT_CHECK_AT_TEST([Syntax error],
372 AT_SETUP([another test])
375 [dnl Until we can find a way to avoid catastrophic failure (ash) or
376 dnl lack of failure (zsh), skip the rest of this test on such shells.
378 AT_CHECK([${CONFIG_SHELL-$SHELL} -c 'case `. ./syntax; echo $?` in
380 esac'], [0], [ignore], [ignore])
381 AT_CHECK([$CONFIG_SHELL ./micro-suite], [1], [ignore], [stderr])
382 AT_CHECK([grep "unable to parse test group: 2" stderr], [0], [ignore])],
385 AT_CHECK_AT_TEST([errexit],
388 AT_SETUP([test that should not be run])
391 AT_SETUP([xpassing test])
395 AT_SETUP([another test that should not be run])
398 AT_SETUP([skipping test])
401 AT_SETUP([xfailing test])
405 AT_SETUP([a test that should be run])
407 AT_SETUP([hard failure])
411 AT_SETUP([yet another test that should not be run])],
412 [], [1], [stdout], [stderr], [],
413 [AT_CHECK([test -f micro-suite.log], [1])
414 touch micro-suite.log # shut up AT_CAPTURE_FILE.
415 AT_CHECK([grep "should not be run" stdout], [1])
416 AT_CHECK([grep "1 .* inhibited subsequent" stderr], [], [ignore])
417 AT_CHECK([$CONFIG_SHELL ./micro-suite --errexit 3-], [1], [stdout], [stderr])
418 AT_CHECK([grep "should not be run" stdout], [1])
419 AT_CHECK([grep "1 .* inhibited subsequent" stderr], [], [ignore])
420 AT_CHECK([$CONFIG_SHELL ./micro-suite --errexit 5-], [1], [stdout], [stderr])
421 AT_CHECK([grep "should be run" stdout], [0], [ignore])
422 AT_CHECK([grep "should not be run" stdout], [1])
423 AT_CHECK([grep "inhibited subsequent" stderr], [], [ignore])],
427 AT_CHECK_AT_TEST([at_status],
428 [AT_CHECK([exit $mystatus], [$expected], [], [],
429 [AT_CHECK([echo run-if-fail: $at_status], [], [ignore])],
430 [AT_CHECK([echo run-if-pass: $at_status], [], [ignore])])
432 AT_SETUP([test with nested checks])
433 AT_CHECK([exit $mystatus], [$expected], [], [],
434 [AT_CHECK([exit $mystatus], [$expected], [], [],
435 [AT_CHECK([echo inner run-if-fail: $at_status], [],
437 [], [], [stdout], [],
439 AT_CHECK([grep 'inner run-if-fail: 42' stdout], [], [ignore])
440 AT_CHECK([$CONFIG_SHELL ./micro-suite -x -v 1 mystatus=0 expected=0], [], [stdout])
441 AT_CHECK([grep 'run-if-pass: 0' stdout], [], [ignore])
442 AT_CHECK([$CONFIG_SHELL ./micro-suite -x -v 1 mystatus=42 expected=0], [], [stdout])
443 AT_CHECK([grep 'run-if-fail: 42' stdout], [], [ignore])
444 AT_CHECK([$CONFIG_SHELL ./micro-suite -x -v 1 mystatus=0 expected=42], [], [stdout])
445 AT_CHECK([grep 'run-if-fail: 0' stdout], [], [ignore])
446 AT_CHECK([$CONFIG_SHELL ./micro-suite -x -v 1 mystatus=42 expected=42], [], [stdout])
447 AT_CHECK([grep 'run-if-pass: 42' stdout], [], [ignore])
449 [-v mystatus=42 expected=1
453 AT_CHECK_AT_TEST([AT@&t@_CHECK execution environment],
454 [dnl The first test should fail, so we enter RUN-IF-FAIL.
455 AT_CHECK([test "$state" != before], [], [], [],
457 AT_CHECK([:]) dnl need this so we do not bail out at this point.
459 dnl This should pass, so we enter RUN-IF-PASS.
460 AT_CHECK([test "$state" = run-if-fail], [], [], [], [],
462 AT_CHECK([test "$state" = run-if-pass])
463 dnl However, COMMANDS are run inside a subshell, so do not change state.
464 AT_CHECK([state=broken; false], [], [], [],
465 [AT_CHECK([test "$state" = run-if-pass])])
466 AT_CHECK([state=broken], [], [], [], [],
467 [AT_CHECK([test "$state" = run-if-pass])])
469 [], [], [], [], [], [], [state=before])
472 AT_CHECK_AT_TEST([unquoted output],
473 [m4_define([backtick], [`])
475 AT_CHECK_UNQUOTED([echo 'a"b backtick`'], [],
476 [${a}"`echo 'b '`\`\backtick]m4_newline)],
477 [], [], [], [], [AT_KEYWORDS([AT@&t@_CHECK_UNQUOTED])])
479 AT_CHECK_AT_TEST([Trace output],
480 [AT_CHECK([echo some longer longer longer command piped | ]dnl
481 [sed 's,into some other longer longer longer command,,'],
482 [], [some longer longer longer command piped
485 AT_CHECK_AT([Logging],
486 [[AT_INIT([artificial test suite])
487 dnl intentionally write failing tests, to see what gets logged
489 AT_CHECK([echo magicstring01], [1], [ignore])
492 AT_CHECK([echo magicstring02 >&2], [1], [], [ignore])
495 AT_CHECK([echo magicstring03], [1], [ignore-nolog])
498 AT_CHECK([echo magicstring04 >&2], [1], [], [ignore-nolog])
501 AT_CHECK([echo magicstring05], [1], [stdout])
504 AT_CHECK([echo magicstring06 >&2], [1], [], [stderr])
507 AT_CHECK([echo magicstring07], [1], [stdout-nolog])
510 AT_CHECK([echo magicstring08 >&2], [1], [], [stderr-nolog])
513 echo magicstring09 > expout
514 AT_CHECK([echo magicstring09], [1], [expout])
517 echo magicstring10 > experr
518 AT_CHECK([echo magicstring10 >&2], [1], [], [experr])
520 ]], [], [1], [], [ignore], [],
521 [AT_CHECK([$CONFIG_SHELL ./micro-suite], [1], [ignore-nolog], [ignore-nolog])
522 AT_CHECK([grep '^magicstring' micro-suite.log], [],
530 AT_CHECK_AT([Binary output],
531 [[AT_INIT([artificial test suite])
532 AT_SETUP([pass: no trailing newline])
533 AT_CHECK([printf short], [0], [stdout-nolog])
534 AT_CHECK([cat stdout], [0], [[short]])
536 AT_SETUP([pass: non-printing characters])
537 AT_CHECK([printf '\1\n' >&2], [0], [], [stderr-nolog])
538 printf '\1\n' > expout
539 AT_CHECK([cat stderr], [0], [expout])
541 AT_SETUP([pass: long lines])
544 str=$str$str$str$str$str$str$str$str$str$str
545 str=$str$str$str$str$str$str$str$str$str$str
546 str=$str$str$str$str$str
547 AT_CHECK_UNQUOTED([echo $str], [0], [[$str]m4_newline])
549 AT_SETUP([fail: no trailing newline])
550 AT_CHECK([printf short], [0], [stdout-nolog])
551 AT_CHECK([cat stdout], [0], [[long]])
553 AT_SETUP([fail: non-printing characters])
554 AT_CHECK([printf '\1\n' >&2], [0], [], [stderr-nolog])
555 printf '\2\n' > expout
556 AT_CHECK([cat stderr], [0], [expout])
558 AT_SETUP([fail: long lines])
561 str=$str$str$str$str$str$str$str$str$str$str
562 str=$str$str$str$str$str$str$str$str$str$str
563 str=$str$str$str$str$str
564 AT_CHECK_UNQUOTED([echo x$str], [0], [[${str}x]m4_newline])
566 ]], [], [0], [], [], [],
567 [AT_CHECK([$CONFIG_SHELL ./micro-suite 4], [1], [ignore], [ignore])
568 AT_CHECK([$CONFIG_SHELL ./micro-suite 5], [1], [ignore], [ignore])
569 AT_CHECK([$CONFIG_SHELL ./micro-suite 6], [1], [ignore], [ignore])], [1-3])
572 AT_CHECK_AT_TEST([Cleanup],
573 [AT_CHECK([test ! -f cleanup.success && test ! -f cleanup.failure])
574 AT_XFAIL_IF([$xfail])
575 AT_CHECK_UNQUOTED([exit $value], [ignore], [$output],
576 [], [touch cleanup.failure], [touch cleanup.success])],
578 [AT_KEYWORDS([AT@&t@_CHECK_UNQUOTED])
579 output=; export output],
580 [AT_CHECK([test -d micro-suite.dir/1])
581 AT_CHECK([test -f micro-suite.dir/1/cleanup.success])
582 AT_CHECK([test ! -f micro-suite.dir/1/cleanup.failure])
584 AT_CHECK([$CONFIG_SHELL ./micro-suite -d xfail=false value=1], [], [ignore])
585 AT_CHECK([test -f micro-suite.dir/1/cleanup.success])
586 AT_CHECK([test ! -f micro-suite.dir/1/cleanup.failure])
588 AT_CHECK([$CONFIG_SHELL ./micro-suite xfail=: value=0],
589 [1], [ignore], [ignore])
590 AT_CHECK([test -f micro-suite.dir/1/cleanup.success])
591 AT_CHECK([test ! -f micro-suite.dir/1/cleanup.failure])
593 AT_CHECK([$CONFIG_SHELL ./micro-suite -d xfail=false value=1 output=mismatch],
594 [1], [ignore], [ignore])
595 AT_CHECK([test ! -f micro-suite.dir/1/cleanup.success])
596 AT_CHECK([test -f micro-suite.dir/1/cleanup.failure])
598 AT_CHECK([$CONFIG_SHELL ./micro-suite -d xfail=false value=77], [], [ignore])
599 AT_CHECK([test ! -f micro-suite.dir/1/cleanup.success])
600 AT_CHECK([test ! -f micro-suite.dir/1/cleanup.failure])
602 AT_CHECK([$CONFIG_SHELL ./micro-suite -d xfail=false value=99],
603 [1], [ignore], [ignore])
604 AT_CHECK([test ! -f micro-suite.dir/1/cleanup.success])
605 AT_CHECK([test ! -f micro-suite.dir/1/cleanup.failure])
606 ], [-d xfail=false value=0])
608 ## ----------------------------------------------------- ##
609 ## Newlines and command substitutions in test commands. ##
610 ## ----------------------------------------------------- ##
612 AT_CHECK_AT_TEST([Literal multiline command],
613 [AT_CHECK([echo Auto'
618 AT_CHECK_AT_TEST([Multiline parameter expansion],
621 AT_CHECK([echo "$FOO"], 0, [one
625 AT_CHECK_AT_TEST([Backquote command substitution],
626 [AT_CHECK([echo `echo hi`], 0, [hi
630 AT_CHECK_AT_TEST([Multiline backquote command substitution],
631 [AT_DATA([myfile],[foo
634 AT_CHECK([echo "`cat myfile`"], 0, [foo
638 AT_CHECK_AT_TEST([Parenthetical command substitution],
639 [AT_CHECK([echo $(echo hi)], 0, [hi
643 AT_CHECK_AT_TEST([Multiline parenthetical command substitution],
644 [AT_DATA([myfile],[foo
647 AT_CHECK([echo "$(cat myfile)"], 0, [foo
653 AT_CHECK_AT_TEST([Shell comment in command],
655 AT_CHECK([$my_echo one [#] two], [], [one
659 ## ------------------------- ##
660 ## ${...} in test commands. ##
661 ## ------------------------- ##
663 # If this invalid parameter expansion capsizes the test suite, the entire
664 # AT_SETUP ... AT_CLEANUP subshell will exit, and the commands it runs will
665 # appear to have succeeded. Therefore, we verify a failing test case.
667 AT_CHECK_AT_TEST([Invalid brace-enclosed parameter expansion],
668 [AT_CHECK([echo '${=invalid}'], 0, [wrong])], [false], 1, ignore, ignore)
671 ## ---------------------------- ##
672 ## M4 macros in test commands. ##
673 ## ---------------------------- ##
675 AT_CHECK_AT_TEST([Multiline command from M4 expansion],
676 [m4_define([GNU], ['foo
678 AT_CHECK([echo GNU], 0, [foo
682 AT_CHECK_AT_TEST([Double-M4-quoted command],
683 [m4_define([GNU], ['foo
685 AT_CHECK([[echo GNU]], 0, [[GNU
689 AT_CHECK_AT_TEST([Metacharacters in command from M4 expansion],
690 [m4_define([GNU], [\"`])
691 AT_CHECK([echo '\"`' [GNU] 'GNU'], 0, [GNU [G][NU] [\"`
695 ## -------------------------------------- ##
696 ## Backslash-<newline> in test commands. ##
697 ## -------------------------------------- ##
699 AT_CHECK_AT_TEST([BS-newline in command],
700 [AT_CHECK([echo Auto"\
704 AT_CHECK_AT_TEST([^BS-newline in command],
709 AT_CHECK_AT_TEST([BSx641-newline in command],
710 [AT_CHECK([printf '%s\n' Auto"\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
711 "conf], 0, [Auto\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\conf
714 AT_CHECK_AT_TEST([BS-BS-newline in command],
715 [AT_CHECK([printf '%s\n' Auto"\\
720 # A `^BS-BS-newline in command' test will run a command named `\'. No, thanks.
722 AT_CHECK_AT_TEST([BSx640-newline in command],
723 [AT_CHECK([printf '%s\n' Auto"\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
724 "conf], 0, [Auto\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
728 # This command has both escaped and unescaped newlines.
729 AT_CHECK_AT_TEST([Newline-CODE-BS-newline in command],
730 [AT_CHECK([printf '%s\n' Auto'
736 AT_CHECK_AT_TEST([Single-quote-BS-newline in command],
737 [AT_CHECK([printf '%s\n' Auto'\
742 AT_CHECK_AT_TEST([Single-quote-newline-BS-newline in command],
743 [AT_CHECK([printf '%s\n' Auto'
751 ## ----------------- ##
752 ## Input from stdin. ##
753 ## ----------------- ##
755 AT_SETUP([Input from stdin])
757 AT_CHECK_AT_PREP([micro-suite],
759 AT_SETUP([please enter hello<RETURN><EOF>])
760 AT_CHECK([cat], [], [hello
765 AT_CHECK([echo hello | $CONFIG_SHELL ./micro-suite], [], [ignore])
766 AT_CHECK([$CONFIG_SHELL ./micro-suite </dev/null], [1], [ignore], [ignore])
771 ## ------------------------------- ##
772 ## Funny characters in test names. ##
773 ## ------------------------------- ##
775 # AT_CHECK_AT_TITLE(TITLE, TITLE-TO-TEST, EXPANDED-TITLE-TO-TEST,
776 # [XFAIL-CONDITION], [COLUMN = 53])
777 # ---------------------------------------------------------------
778 # Create a new test named TITLE that runs an Autotest test suite
779 # comprised of a trivial test named TITLE-TO-TEST, which expands
780 # to EXPANDED-TITLE-TO-TEST. XFAIL-CONDITION passes verbatim to
781 # AT_CHECK_AT. Verify that `ok' prints at COLUMN.
782 m4_define([AT_CHECK_AT_TITLE],
785 m4_define([macro_name], [[macro_expanded]])
786 m4_define([macro_expanded], [[macro_overexpanded]])
787 m4_define([macro_backquote], [`])
788 m4_define([macro_single_quote], ['])
789 m4_define([macro_double_quote], ["])
790 ]]dnl restore font-lock: "
791 [[m4_define([macro_backslash], [\])
792 m4_define([macro_echo], [$][1])
793 AT_INIT([artificial test suite])
797 ]], [$4], [], [], [], [],
798 dnl This sed script checks for two things - that the output is properly
799 dnl expanded, and that the 'ok' starts on the right column.
800 [AT_KEYWORDS([m4@&t@_expand])
801 AT_CHECK([[$CONFIG_SHELL ./micro-suite |
804 s/[^:]*: \(.*[^ ]\)[ ]*ok.*/\1/p
806 s/^.\{]]]m4_default($5, 53)[[[\}ok.*/ok/p
811 dnl This sed script checks for two things - that -v output doesn't have
812 dnl an empty $at_srcdir expansion, and that the 'testing ...' line
813 dnl contains the test group title.
814 AT_CHECK([[$CONFIG_SHELL ./micro-suite -v |
815 sed -n 's/.*testing \(.*\) \.\.\./\1/p; /^\/micro-suite\.at:/p']],,
818 AT_CHECK([[$CONFIG_SHELL ./micro-suite -l |
819 sed -n 's/.*[0-9]: [^ ][^ ]*[ ][ ]*\(.*[^ ]\)[ ]*/\1/p']],,
822 AT_CHECK([[sed -n 's/[^.]*\. \(.*\) ([^)]*): ok.*/\1/p' micro-suite.log]],,
827 m4_define([AT_CHECK_AT_TITLE_CHAR],
828 [AT_CHECK_AT_TITLE([$1 in a test title], [A $2 in my name],
829 [A ]m4_ifval([$3], [[$3]], [[$2]])[ in my name], $4, $5)])
831 AT_CHECK_AT_TITLE_CHAR([Backquote], [`])
832 AT_CHECK_AT_TITLE_CHAR([Single-quote], ['])
833 AT_CHECK_AT_TITLE_CHAR([Double-quote], ["])
834 dnl restore font-lock: "
835 AT_CHECK_AT_TITLE_CHAR([Backslash], [\])
836 AT_CHECK_AT_TITLE_CHAR([Brackets], [[[]]], [[]])
837 AT_CHECK_AT_TITLE_CHAR([Left bracket], [@<:@], [@<:@])
838 AT_CHECK_AT_TITLE_CHAR([Right bracket], [@:>@], [@:>@])
839 AT_CHECK_AT_TITLE_CHAR([Quoted pound], [[#]], [#])
840 AT_CHECK_AT_TITLE_CHAR([Pound], [#])
841 AT_CHECK_AT_TITLE_CHAR([Quoted comma], [[,]], [,])
842 AT_CHECK_AT_TITLE_CHAR([Comma], [,])
843 dnl this test also hits quadrigraphs for ()
844 AT_CHECK_AT_TITLE_CHAR([Parentheses], [(@{:@)@:}@], [(())])
845 AT_CHECK_AT_TITLE_CHAR([Left paren], [[(]], [(])
846 AT_CHECK_AT_TITLE_CHAR([Right paren], [[)]], [)])
848 AT_CHECK_AT_TITLE_CHAR([Quoted Macro], [[macro_name]], [macro_name])
849 AT_CHECK_AT_TITLE_CHAR([Macro], [macro_name], [macro_expanded])
850 AT_CHECK_AT_TITLE_CHAR([Macro with backquote], [macro_backquote], [`])
851 AT_CHECK_AT_TITLE_CHAR([Macro with single-quote], [macro_single_quote], ['])
852 AT_CHECK_AT_TITLE_CHAR([Macro with double-quote], [macro_double_quote], ["])
853 dnl restore font-lock: "
854 AT_CHECK_AT_TITLE_CHAR([Macro with backslash], [macro_backslash], [\])
855 AT_CHECK_AT_TITLE_CHAR([Macro echoing macro], [macro_echo([macro_name])],
857 AT_CHECK_AT_TITLE_CHAR([Macro echoing single-quote], [macro_echo(['])], ['])
858 AT_CHECK_AT_TITLE_CHAR([Long test title], [0123456789012345678901234567890123])
859 AT_CHECK_AT_TITLE_CHAR([Longer test title],
860 [01234567890123456789012345678901234], [], [], [54])
863 ## ----------------------- ##
864 ## Long test source lines. ##
865 ## ----------------------- ##
867 # Create a test file that has more than 99 words in a line, for Solaris awk.
868 # While at that, try out the limit of 2000 bytes in a text file line.
870 AT_CHECK_AT_TEST([Long test source lines],
871 [m4_for([nnn], [1], [999], [], [: ])
873 ], [], [], [], [ignore], [],
874 [AT_CHECK([$CONFIG_SHELL ./micro-suite -k skipalltests], [], [ignore], [ignore])
878 ## ---------------- ##
879 ## Huge testsuite. ##
880 ## ---------------- ##
882 # Ensure we don't hit line length limits with large test suites.
884 AT_CHECK_AT_TEST([Huge testsuite],
885 [m4_for([nnn], [1], [1999], [],
889 ], [], [], [], [ignore], [], [], [1999])
892 ## ----------------- ##
893 ## Debugging a test. ##
894 ## ----------------- ##
896 AT_CHECK_AT_TEST([Debugging a successful test],
897 [AT_CHECK([:])], [], [], [], [ignore], [],
898 [# Without options, when all tests pass, no test directory should exist.
899 AT_CHECK([test -d micro-suite.dir/1 && exit 42
900 $CONFIG_SHELL ./micro-suite -d 1], [], [ignore], [ignore])
901 # Running with -d should leave a reproducible test group.
902 # Also, running the test script from the test group locks the
903 # directory from removal on some platforms; the script should still be
904 # able to run even if rmdir fails.
905 AT_CHECK([(cd micro-suite.dir/1 && ./run)], [], [ignore], [ignore])
906 # Running a debugging script implies -d.
907 AT_CHECK([(cd micro-suite.dir/1 && ./run)], [], [ignore], [ignore])
910 AT_CHECK_AT_TEST([Debugging script and environment],
911 [AT_CHECK([test "$MY_VAR" = pass || exit 42])],
912 [], [1], [], [ignore], [], [
913 # Changing environment outside of debugging script is not preserved.
914 AT_CHECK([(cd micro-suite.dir/1 && MY_VAR=pass ./run)],
915 [0], [ignore], [ignore])
916 AT_CHECK([(cd micro-suite.dir/1 && ./run)],
917 [1], [ignore], [ignore])
918 # Changing environment as argument to debugging script is preserved.
919 AT_CHECK([(cd micro-suite.dir/1; ./run MY_VAR=pass)],
920 [0], [ignore], [ignore])
921 AT_CHECK([(cd micro-suite.dir/1; ./run)],
922 [0], [ignore], [ignore])
925 # The run script must still be valid when shell metacharacters are passed
926 # in via an environment option.
927 AT_CHECK_AT_TEST([Debugging a failed test],
928 [AT_CHECK([test "$MY_VAR" = "one space" || exit 42])],
929 [], [1], [], [ignore], [], [
930 AT_CHECK([(cd micro-suite.dir/1 && ./run MY_VAR='two spaces')],
931 [1], [ignore], [ignore])
932 AT_CHECK([(cd micro-suite.dir/1 && ./run MY_VAR='one space')],
933 [0], [ignore], [ignore])
937 # Setting default variable values via atlocal.
938 AT_CHECK_AT_TEST([Using atlocal],
939 [AT_CHECK([test "x$MY_VAR" = "xodd; 'string" || exit 42])],
940 [], [1], [ignore], [ignore], [], [
941 dnl check that command line can set variable
942 AT_CHECK([$CONFIG_SHELL ./micro-suite MY_VAR="odd; 'string"], [0], [ignore])
943 dnl check that command line overrides environment
944 AT_CHECK([MY_VAR="odd; 'string" $CONFIG_SHELL ./micro-suite MY_VAR=unset],
945 [1], [ignore], [ignore])
946 dnl check that atlocal can give it a default
947 AT_CHECK([cat <<EOF >atlocal
948 MY_VAR="odd; 'string"
950 dnl Also populate enough of atlocal to do what atconfig normally does.
956 abs_top_srcdir='`pwd`'
958 abs_top_builddir='`pwd`'
961 AT_CHECK([$CONFIG_SHELL ./micro-suite], [0], [ignore])
962 dnl check that atlocal overrides environment
963 AT_CHECK([MY_VAR=unset $CONFIG_SHELL ./micro-suite], [0], [ignore])
964 dnl check that command line overrides atlocal
965 AT_CHECK([$CONFIG_SHELL ./micro-suite MY_VAR=], [1], [ignore], [ignore])
966 dnl check that syntax error is detected
967 AT_CHECK([$CONFIG_SHELL ./micro-suite =], [1], [], [ignore], [ignore])
968 AT_CHECK([$CONFIG_SHELL ./micro-suite 1=2], [1], [], [ignore], [ignore])
972 # Controlling where the testsuite is run.
973 AT_CHECK_AT_TEST([Choosing where testsuite is run],
974 [AT_CHECK([:])], [], [], [], [], [], [
975 dnl AT_CHECK_AT_TEST tests the default of running in `.'.
976 AT_CHECK([$CONFIG_SHELL ./micro-suite --clean])
977 AT_CHECK([test -f micro-suite.log], [1])
978 AT_CHECK([test -d micro-suite.dir], [1])
979 AT_CHECK([mkdir sub1 sub2])
980 dnl check specifying a different relative path to run in.
981 AT_CHECK([$CONFIG_SHELL ./micro-suite -C sub1], [0], [ignore], [])
982 AT_CHECK([test -f micro-suite.log], [1])
983 AT_CHECK([test -f sub1/micro-suite.log], [0])
984 AT_CHECK([test -d micro-suite.dir], [1])
985 AT_CHECK([test -d sub1/micro-suite.dir], [0])
986 AT_CHECK([$CONFIG_SHELL ./micro-suite -C sub1 --clean])
987 AT_CHECK([test -f sub1/micro-suite.log], [1])
988 AT_CHECK([test -d sub1/micro-suite.dir], [1])
989 dnl check specifying an absolute path to run in.
990 AT_CHECK([$CONFIG_SHELL ./micro-suite --directory="`pwd`/sub2"],
992 AT_CHECK([test -f micro-suite.log], [1])
993 AT_CHECK([test -f sub2/micro-suite.log], [0])
994 AT_CHECK([$CONFIG_SHELL ./micro-suite --clean --directory="`pwd`/sub2"])
995 AT_CHECK([test -f sub2/micro-suite.log], [1])
996 AT_CHECK([test -f sub2/micro-suite.dir], [1])
997 dnl check for failure detection with bad, missing, or empty directory.
998 AT_CHECK([$CONFIG_SHELL ./micro-suite -C nonesuch || exit 1], [1], [ignore], [ignore])
999 AT_CHECK([$CONFIG_SHELL ./micro-suite -C ''], [1], [ignore], [ignore])
1000 AT_CHECK([$CONFIG_SHELL ./micro-suite -C - || exit 1], [1], [ignore], [ignore])
1001 AT_CHECK([$CONFIG_SHELL ./micro-suite -C], [1], [ignore], [ignore])
1002 dnl check that --help overrides bad directory selection.
1003 AT_CHECK([$CONFIG_SHELL ./micro-suite -C nonesuch --help], [0], [ignore], [])
1008 AT_CHECK_AT_TEST([recheck],
1011 AT_SETUP([failing test])
1014 AT_SETUP([xpassing test])
1018 AT_SETUP([xfailing test])
1021 ], [], [], [], [], [], [
1022 AT_CHECK([$CONFIG_SHELL ./micro-suite --recheck], [0], [stdout])
1023 AT_CHECK([grep "0 tests were successful" stdout], [0], [ignore])
1025 AT_CHECK([$CONFIG_SHELL ./micro-suite], [1], [ignore], [ignore])
1026 AT_CHECK([grep 'only test' micro-suite.log], [0], [ignore])
1027 AT_CHECK([$CONFIG_SHELL ./micro-suite --recheck], [1], [ignore], [ignore])
1028 AT_CHECK([grep 'only test' micro-suite.log], [1])
1029 AT_CHECK([grep 'xfailing' micro-suite.log], [1])
1030 AT_CHECK([grep 'failing test' micro-suite.log], [0], [ignore])
1031 AT_CHECK([grep 'xpassing test' micro-suite.log], [0], [ignore])
1033 AT_CHECK([$CONFIG_SHELL ./micro-suite --clean], [0])
1034 AT_CHECK([test -f micro-suite.log], [1])
1036 dnl check specifying a different relative path to run in.
1037 AT_CHECK([mkdir sub1])
1038 AT_CHECK([$CONFIG_SHELL ./micro-suite -C sub1], [1], [ignore], [ignore])
1039 AT_CHECK([test -f micro-suite.log], [1])
1040 AT_CHECK([test -f sub1/micro-suite.log], [0])
1041 AT_CHECK([$CONFIG_SHELL ./micro-suite -C sub1 --recheck --list], [0], [stdout])
1042 AT_CHECK([grep 'only test' stdout], [1])
1043 AT_CHECK([grep 'xfailing test' stdout], [1])
1044 AT_CHECK([grep 'failing test' stdout], [0], [ignore])
1045 AT_CHECK([grep 'xpassing test' stdout], [0], [ignore])
1046 AT_CHECK([$CONFIG_SHELL ./micro-suite -C sub1 --recheck], [1], [ignore],
1048 AT_CHECK([grep 'failing test' sub1/micro-suite.log], [0], [ignore])
1049 AT_CHECK([grep 'xpassing test' sub1/micro-suite.log], [0], [ignore])
1058 AT_CHECK_AT_PREP([b],
1081 AT_SETUP(three a)# 6
1084 AT_SETUP(three b)# 7
1089 # AT_CHECK_BANNERS(TESTSUITE-OPTIONS, PATTERN1, COUNT1, PATTERN2, COUNT2)
1090 m4_define([AT_CHECK_BANNERS],
1091 [AT_CHECK([$CONFIG_SHELL ./b $1], [], [stdout])
1092 AT_CHECK_EGREP([$2], m4_if([$3], [0], [1], [0]), [$3])
1093 AT_CHECK_EGREP([$4], m4_if([$5], [0], [1], [0]), [$5])
1096 AT_CHECK_BANNERS([], [first], [1], [second], [1])
1097 AT_CHECK_BANNERS([-k zero], [first], [0], [second], [0])
1098 AT_CHECK_BANNERS([1], [first], [0], [second], [0])
1099 AT_CHECK_BANNERS([-2], [first], [1], [second], [0])
1100 AT_CHECK_BANNERS([-3], [first], [1], [second], [0])
1101 AT_CHECK_BANNERS([-k one], [first], [1], [second], [0])
1102 AT_CHECK_BANNERS([3-4], [first], [1], [second], [0])
1103 dnl There should be an empty line separating the first category from the
1105 AT_CHECK([sed -n '/one b/,/two a/p' stdout | grep '^$'], [0], [ignore])
1106 AT_CHECK_BANNERS([3-6], [first], [1], [second], [1])
1107 AT_CHECK_BANNERS([4-6], [first], [0], [second], [1])
1108 AT_CHECK_BANNERS([3-], [first], [1], [second], [1])
1109 AT_CHECK_BANNERS([-k a], [first], [1], [second], [1])
1110 AT_CHECK_BANNERS([4], [first], [0], [second], [0])
1111 AT_CHECK_BANNERS([4-], [first], [0], [second], [1])
1112 AT_CHECK_BANNERS([-k two], [first], [0], [second], [0])
1113 AT_CHECK_BANNERS([1 4], [first], [0], [second], [0])
1114 AT_CHECK_BANNERS([-k three], [first], [0], [second], [1])
1115 AT_CHECK_BANNERS([5], [first], [0], [second], [0])
1116 AT_CHECK_BANNERS([5-], [first], [0], [second], [1])
1123 AT_SETUP([Keywords and ranges])
1125 AT_CHECK_AT_PREP([k],
1130 AT_SETUP(first) # 02
1134 AT_SETUP(second) # 03
1139 AT_KEYWORDS([key1 key2])
1140 AT_KEYWORDS([m4_echo([Key1])])
1143 AT_SETUP(test5) # 05
1146 AT_SETUP(test6) # 06
1149 AT_SETUP(test7) # 07
1152 AT_SETUP(test8) # 08
1155 AT_SETUP(test9) # 09
1158 AT_SETUP(test10) # 10
1162 dnl check that AT_KEYWORDS does not duplicate words
1163 AT_CHECK([grep -i 'key1.*key1' k], [1])
1164 dnl check that -k requires an argument
1165 AT_CHECK([$CONFIG_SHELL ./k -k], [1], [], [ignore])
1167 # AT_CHECK_KEYS(TESTSUITE-OPTIONS, PATTERN1, COUNT1, PATTERN2, COUNT2)
1168 m4_define([AT_CHECK_KEYS],
1169 [AT_CHECK([$CONFIG_SHELL ./k $1], 0, [stdout])
1170 AT_CHECK_EGREP([$2], 0, [$3])
1171 AT_CHECK_EGREP([$4], 1, [$5])
1174 AT_CHECK_KEYS([-k key1], [first|both], [2], [none|second], [0])
1175 AT_CHECK_KEYS([-k key2], [second|both], [2], [none|first], [0])
1176 AT_CHECK_KEYS([-k key1,key2], [both], [1], [none|first|second], [0])
1177 AT_CHECK_KEYS([-k key1 -k key2], [first|second|both], [3], [none], [0])
1178 AT_CHECK_KEYS([-k '!key1'], [none|second], [2], [first|both], [0])
1179 AT_CHECK_KEYS([-k '!key2'], [none|first], [2], [second|both], [0])
1180 AT_CHECK_KEYS([-k '!key1,key2'], [second], [1], [none|first|both], [0])
1181 AT_CHECK_KEYS([-k 'key1,!key2'], [first], [1], [none|second|both], [0])
1182 AT_CHECK_KEYS([-k '!key1,!key2'], [none], [1], [first|second|both], [0])
1183 AT_CHECK_KEYS([-k '!key1' -k KEY2], [none|second|both], [3], [first], [0])
1184 AT_CHECK_KEYS([-k key1 -k '!key2'], [none|first|both], [3], [second], [0])
1185 AT_CHECK_KEYS([-k '!KEY1' -k '!key2'], [none|first|second], [3], [both], [0])
1187 AT_CHECK_KEYS([-k none], [none], [1], [first|second|both], [0])
1188 AT_CHECK_KEYS([-k key1,both], [both], [1], [none|first|second], [0])
1189 AT_CHECK_KEYS([-k key1 -k both], [first|both], [2], [none|second], [0])
1190 AT_CHECK_KEYS([-k none,first], [successful], [1], [none|first|second|both], [0])
1191 AT_CHECK_KEYS([-k none,first,second,both], [successful], [1], [none|first|second|both], [0])
1192 AT_CHECK_KEYS([-k !none,first], [first], [1], [none|second|both], [0])
1194 AT_CHECK_KEYS([-k '.*eco.*'], [second], [1], [none|first|both], [0])
1195 AT_CHECK_KEYS([-k 'ECO'], [successful], [1], [none|first|second|both], [0])
1196 AT_CHECK_KEYS([-k '.*eco'], [successful], [1], [none|first|second|both], [0])
1197 AT_CHECK_KEYS([-k 'eco.*'], [successful], [1], [none|first|second|both], [0])
1198 AT_CHECK_KEYS([-k 'fir.*'], [first], [1], [none|second|both], [0])
1200 AT_CHECK_KEYS([1-2], [none|first], [2], [second|both], [0])
1201 AT_CHECK_KEYS([01-002 08], [none|first], [2], [second|both], [0])
1202 AT_CHECK_KEYS([1-3 2-1], [none|first|second], [3], [both], [0])
1203 AT_CHECK_KEYS([-3], [none|first|second], [3], [both], [0])
1204 AT_CHECK_KEYS([4-], [both], [1], [none|first|second], [0])
1205 AT_CHECK_KEYS([010], [test10], [1], [none|first|second|both], [0])
1206 AT_CHECK_KEYS([-k second 4-], [second|both], [2], [none|first], [0])
1208 AT_CHECK([$CONFIG_SHELL ./k 0], [1], [ignore], [ignore])
1209 AT_CHECK([$CONFIG_SHELL ./k 0-], [1], [ignore], [ignore])
1210 AT_CHECK([$CONFIG_SHELL ./k -0], [1], [ignore], [ignore])
1211 AT_CHECK([$CONFIG_SHELL ./k 11], [1], [ignore], [ignore])
1212 AT_CHECK([$CONFIG_SHELL ./k 11-], [1], [ignore], [ignore])
1213 AT_CHECK([$CONFIG_SHELL ./k 1-011], [1], [ignore], [ignore])
1214 AT_CHECK([$CONFIG_SHELL ./k -k nonexistent], [0], [ignore])
1216 AT_CHECK_KEYS([--list -k nonexistent], [KEYWORDS], [1], [first|second|both], [0])
1217 AT_CHECK_KEYS([--list 1], [none], [1], [first|second|both], [0])
1218 AT_CHECK_KEYS([--list 01], [none], [1], [first|second|both], [0])
1219 AT_CHECK_KEYS([--list -k none -k first], [none|first], [2], [second|both], [0])
1223 ## ----------------- ##
1224 ## Keyword wrapping. ##
1225 ## ----------------- ##
1226 AT_SETUP([Keyword wrapping])
1228 AT_CHECK_AT_PREP([k],
1231 AT_KEYWORDS([a1 b1 c1 d1 e1 f1 g1 h1 i1 j1 k1 l1 m1 n1 o1 p1 q1 r1 s1 t1])
1232 AT_KEYWORDS([u1 v1 w1 x1 y1 z1])
1233 AT_KEYWORDS([a b c d e f g h i j k l m n o p q r s t u v w x y z])
1235 AT_SETUP([test with long keywords])
1237 [this-is-a-long-keyword-that-cannot-be-wrapped-so-we-exceed-the-length-limit-here])
1238 # surrounded by short ones
1241 [another-very-long-keyword-that-hits-the-line-length-limit-bla-bla-bla-bla])
1246 AT_CHECK_KEYS([-l], [.{80}], [1], [.{87}], [0])
1255 AT_CHECK_AT([AT@&t@_ARG_OPTION],
1257 AT_INIT([artificial test suite])
1258 AT_ARG_OPTION([frob fro fr f],
1259 [AS_HELP_STRING([-f, --frob], [frobnicate the test run])],
1260 [frob=$at_optarg], [frob=default])
1261 AT_ARG_OPTION([opt-with-hyphen],
1262 [AS_HELP_STRING([--opt-with-hyphen], [option name with hypen])])
1263 AT_ARG_OPTION([ping],
1264 [AS_HELP_STRING([--ping], [ping on every encounter])],
1266 AT_SETUP([test argument handling])
1267 AT_CHECK([test "$frob" = "$FROB"])
1268 AT_CHECK([test "$at_arg_frob" = "$FROB_ARG"])
1270 AT_SETUP([test hyphen normalization])
1271 AT_CHECK([test "$at_arg_opt_with_hyphen" = "$expected"])
1274 [], [], [stdout], [], [],
1275 [# We already invoked --help.
1276 AT_CHECK([grep ' -f, --frob.*frobnicate' stdout], [], [ignore])
1278 '1 FROB=default FROB_ARG=false' \
1279 '1 -f FROB=: FROB_ARG=:' \
1280 '1 --fr FROB=: FROB_ARG=:' \
1281 '1 --fro FROB=: FROB_ARG=:' \
1282 '1 --frob FROB=: FROB_ARG=:' \
1283 '1 --no-f FROB=false FROB_ARG=false' \
1284 '1 --no-fr FROB=false FROB_ARG=false' \
1285 '1 --no-fro FROB=false FROB_ARG=false' \
1286 '1 --no-frob FROB=false FROB_ARG=false' \
1287 '2 expected=false' \
1288 '2 --opt-with-hyphen expected=:' \
1289 '2 --no-opt-with-hyphen expected=false'
1291 AT_CHECK([$CONFIG_SHELL ./micro-suite -x $args], [], [ignore])
1293 AT_CHECK([$CONFIG_SHELL ./micro-suite 2 --ping --no-ping --ping expected=false],
1295 AT_CHECK([grep -c ping stdout], [], [[3
1300 ## ----------------- ##
1301 ## AT_ARG_OPTION_ARG ##
1302 ## ----------------- ##
1304 AT_CHECK_AT([AT@&t@_ARG_OPTION_ARG],
1306 AT_INIT([artificial test suite])
1307 AT_ARG_OPTION_ARG([frob fro fr f],
1308 [AS_HELP_STRING([-f, --frob=FOO], [frobnicate FOO])],
1309 [frob=$at_optarg], [frob=default])
1310 AT_ARG_OPTION_ARG([opt-with-hyphen],
1311 [AS_HELP_STRING([--opt-with-hyphen=ARG],
1312 [option name with hypen])])
1313 AT_ARG_OPTION_ARG([ping],
1314 [AS_HELP_STRING([--ping], [ping on every encounter])],
1316 AT_SETUP([test argument handling])
1317 AT_CHECK([test "$frob" = "$FROB"])
1318 AT_CHECK([test "$at_arg_frob" = "$FROB_ARG"])
1320 AT_SETUP([test hyphen normalization])
1321 AT_CHECK([test "$at_arg_opt_with_hyphen" = "$expected"])
1324 [], [], [stdout], [], [],
1325 [# We already invoked --help.
1326 AT_CHECK([grep ' -f, --frob.*frobnicate' stdout], [], [ignore])
1327 AT_CHECK([$CONFIG_SHELL ./micro-suite -x --frob], [1], [ignore], [stderr])
1328 AT_CHECK([grep 'requires an argument' stderr], [], [ignore])
1329 AT_CHECK([$CONFIG_SHELL ./micro-suite -x --no-frob], [1], [ignore], [stderr])
1330 AT_CHECK([grep 'invalid option' stderr], [], [ignore])
1332 '1 FROB=default FROB_ARG=' \
1333 '1 -f bar FROB=bar FROB_ARG=bar' \
1334 '1 --fr bar FROB=bar FROB_ARG=bar' \
1335 '1 --fro bar FROB=bar FROB_ARG=bar' \
1336 '1 --frob bar FROB=bar FROB_ARG=bar' \
1337 '1 -f=bar FROB=bar FROB_ARG=bar' \
1338 '1 --fr=bar FROB=bar FROB_ARG=bar' \
1339 '1 --fro=bar FROB=bar FROB_ARG=bar' \
1340 '1 --frob=bar FROB=bar FROB_ARG=bar' \
1342 '2 --opt-with-hyphen=baz expected=baz'
1344 AT_CHECK([$CONFIG_SHELL ./micro-suite -x $args], [], [ignore])
1346 AT_CHECK([$CONFIG_SHELL ./micro-suite 2 --ping=1 --ping=2 expected=],
1348 AT_CHECK([grep -c ping stdout], [], [[2
1353 m4_define([AT_SKIP_PARALLEL_TESTS],
1354 [# Per BUGS, we have not yet figured out how to run parallel tests cleanly
1355 # under dash and some ksh variants. For now, only run this test under
1356 # limited conditions; help is appreciated in widening this test base.
1357 AT_SKIP_IF([${CONFIG_SHELL-$SHELL} -c 'test -z "${BASH_VERSION+set}]]dnl
1358 [[${ZSH_VERSION+set}${TEST_PARALLEL_AUTOTEST+set}"'])
1359 # The parallel scheduler requires mkfifo and job control to work.
1360 AT_CHECK([mkfifo fifo || exit 77])
1361 AT_CHECK([${CONFIG_SHELL-$SHELL} -c '(set -m && set +m) || exit 77'],
1366 ## ----------------------- ##
1367 ## parallel test execution ##
1368 ## ----------------------- ##
1370 AT_SETUP([parallel test execution])
1372 # This test tries to ensure that -j runs tests in parallel.
1373 # Such a test is inherently racy, because there are no real-time
1374 # guarantees about scheduling delays. So we try to minimize
1375 # the chance to lose the race.
1377 # The time needed for a micro-suite consisting of NTESTS tests each
1378 # sleeping for a second is estimated by
1379 # startup + ntests * (serial_overhead + 1 / njobs)
1381 # in absence of major scheduling delays. This leads to side conditions:
1382 # - NTESTS should be high, so the STARTUP time is small compared to the
1383 # test run time, and scheduling delays can even out; it should not be
1384 # too high, to not slow down the testsuite unnecessarily,
1385 # - the number of concurrent jobs NJOBS should not be too low, so the
1386 # race is not lost so easily; it should not be too high, to avoid fork
1387 # failures on tightly limited systems. 4 seems a good compromise
1388 # here, considering that Autotest spawns several other processes.
1389 # - STARTUP is assumed to be the same for parallel and serial runs, so
1390 # the latter can estimate the former.
1391 # - To avoid unportable output from time measurement commands, spawn
1392 # both a parallel and a serial testsuite run; check that the former
1393 # completes before the latter has completed a fraction SERIAL_NTESTS
1394 # of the tests (the serial run is executed in a subdirectory), plus
1395 # some additional time to allow for compensation of SERIAL_OVERHEAD.
1396 # - when adding this time to the serial test execution, an initial delay
1397 # SERIAL_DELAY of the serial test helps to avoid unreliable scheduling
1398 # due to the startup burst of the suites.
1400 dnl total number of tests.
1401 m4_define([AT_PARALLEL_NTESTS], [16])
1402 dnl number of jobs to run in parallel.
1403 m4_define([AT_PARALLEL_NJOBS], [4])
1404 dnl number of tests to run serially, as comparison.
1405 m4_define([AT_PARALLEL_SERIAL_NTESTS],
1406 m4_eval(AT_PARALLEL_NTESTS / AT_PARALLEL_NJOBS))
1407 dnl initial delay of serial run, to compensate for SERIAL_OVERHEAD.
1408 dnl This corresponds to 0.67 s of overhead per test.
1409 m4_define([AT_PARALLEL_SERIAL_DELAY],
1410 m4_eval((AT_PARALLEL_NTESTS - AT_PARALLEL_SERIAL_NTESTS + 1) * 2 / 3))
1413 AT_CHECK_AT_PREP([micro-suite],
1414 [[AT_INIT([suite to test parallel execution])
1415 m4_for([count], [1], ]]AT_PARALLEL_NTESTS[[, [],
1416 [AT_SETUP([test number count])
1422 # Even if parallel jobs are not supported, the command line must work.
1423 AT_CHECK([$CONFIG_SHELL ./micro-suite --help | grep " --jobs"], [0], [ignore])
1424 AT_CHECK([$CONFIG_SHELL ./micro-suite -j2foo], [1], [], [stderr])
1425 AT_CHECK([grep 'non-numeric argument' stderr], [], [ignore])
1426 AT_CHECK([$CONFIG_SHELL ./micro-suite --jobs=foo], [1], [], [stderr])
1427 AT_CHECK([grep 'non-numeric argument' stderr], [], [ignore])
1429 AT_SKIP_PARALLEL_TESTS
1431 # Ensure that all tests run, and lines are not split.
1432 AT_CHECK([$CONFIG_SHELL ./micro-suite -j[]AT_PARALLEL_NJOBS], [], [stdout])
1433 AT_CHECK([grep -c '^.\{53\}ok' stdout], [], [AT_PARALLEL_NTESTS
1435 # Running one test with -j should produce correctly formatted output:
1436 AT_CHECK([$CONFIG_SHELL ./micro-suite -j 3], [], [stdout])
1437 AT_CHECK([grep -c '^.\{53\}ok' stdout], [], [1
1439 # Specifying more jobs than tests should not hang:
1440 AT_CHECK([$CONFIG_SHELL ./micro-suite -j3 3], [], [stdout])
1441 AT_CHECK([grep -c '^.\{53\}ok' stdout], [], [1
1443 # Not even with zero tests:
1444 AT_CHECK([$CONFIG_SHELL ./micro-suite -j -k nomatch], [], [ignore])
1445 AT_CHECK([$CONFIG_SHELL ./micro-suite -j3 -k nomatch], [], [ignore])
1449 # Unfortunately, the return value of wait is unreliable,
1450 # so we check that kill fails.
1451 AT_CHECK([$CONFIG_SHELL ./micro-suite --jobs=[]AT_PARALLEL_NJOBS & ]dnl
1452 [sleep AT_PARALLEL_SERIAL_DELAY && ]dnl
1453 [cd serial && $CONFIG_SHELL ../micro-suite -AT_PARALLEL_SERIAL_NTESTS >/dev/null && ]dnl
1454 [{ kill $! && exit 1; :; }], [], [stdout], [ignore])
1455 AT_CHECK([grep -c '^.\{53\}ok' stdout], [], [AT_PARALLEL_NTESTS
1457 AT_CHECK([grep 'AT_PARALLEL_NTESTS tests' stdout], [], [ignore])
1461 AT_CHECK_AT_TEST([parallel truth],
1462 [AT_CHECK([:], 0, [], [])],
1463 [], [], [], [], [AT_SKIP_PARALLEL_TESTS],
1466 AT_CHECK_AT_TEST([parallel fallacy],
1467 [AT_CHECK([false], [], [], [])],
1468 [], [1], [], [ignore], [AT_SKIP_PARALLEL_TESTS],
1469 [AT_CHECK([grep failed micro-suite.log], [], [ignore])], [-j])
1471 AT_CHECK_AT_TEST([parallel skip],
1472 [AT_CHECK([echo output; echo irrelevant >&2; exit 77], 0, [mismatch], [])],
1473 [], [], [], [], [AT_SKIP_PARALLEL_TESTS],
1474 [AT_CHECK([grep skipped micro-suite.log], [], [ignore])], [-j])
1476 AT_CHECK_AT_TEST([parallel syntax error],
1482 AT_SETUP([another test])
1484 [], [0], [], [], [AT_SKIP_PARALLEL_TESTS],
1485 [dnl Until we can find a way to avoid catastrophic failure (ash) or
1486 dnl lack of failure (zsh), skip the rest of this test on such shells.
1488 AT_CHECK([${CONFIG_SHELL-$SHELL} -c 'case `. ./syntax; echo $?` in
1490 esac'], [0], [ignore], [ignore])
1491 AT_CHECK([$CONFIG_SHELL ./micro-suite -j], [1], [ignore], [stderr])
1492 AT_CHECK([grep "unable to parse test group: 2" stderr], [0], [ignore])],
1495 AT_CHECK_AT_TEST([parallel errexit],
1498 AT_SETUP([barrier test])
1501 AT_SETUP([test that should not be run])
1503 [], [1], [stdout], [stderr], [AT_SKIP_PARALLEL_TESTS],
1504 [AT_CHECK([test -f micro-suite.log], [1])
1505 touch micro-suite.log # shut up AT_CAPTURE_FILE.
1506 AT_CHECK([grep "should not be run" stdout], [1])
1507 AT_CHECK([grep "[[12]] .* inhibited subsequent" stderr], [], [ignore])],
1511 AT_SETUP([parallel autotest and signal handling])
1513 AT_SKIP_PARALLEL_TESTS
1516 # (1) interrupt `./testsuite -jN'
1517 # (2) interrupt `make check TESTSUITEFLAGS=-jN'
1518 # (3) no trailing verbose/trace output
1519 # (4) exit status should be 128+signal
1526 AT_CHECK_AT_PREP([micro-suite],
1527 [[AT_INIT([suite to test parallel execution])
1528 AT_SETUP([test number 1])
1531 AT_SETUP([test number 2])
1534 AT_SETUP([test number 3])
1537 AT_SETUP([killer test])
1538 AT_CHECK([kill -$signal $suite_pid])
1540 m4_for([count], [5], [7], [],
1541 [AT_SETUP([test number count])
1547 AT_DATA([Makefile.in],
1550 TESTSUITE = ./micro-suite
1552 $(SHELL) '$(TESTSUITE)' $(TESTSUITEFLAGS)
1556 AT_CHECK([$CONFIG_SHELL $abs_top_builddir/config.status --file=Makefile:Makefile.in],
1559 # Test INT and TERM.
1560 for signal in 2 15; do
1562 AS_VAR_ARITH([expected_status], [128 + $signal])
1565 AT_CHECK([$CONFIG_SHELL ./micro-suite], [$expected_status],
1567 # Both stderr and the log should contain the notification about the signal.
1568 AT_CHECK([grep 'bailing out' stderr], [], [ignore])
1569 AT_CHECK([grep 'bailing out' micro-suite.log], [], [ignore])
1570 # There should be no junk job status output.
1571 AT_CHECK([[grep '[iI]nterrupt[ ]' stderr]], [1])
1574 AT_CHECK([$CONFIG_SHELL ./micro-suite --jobs=3], [$expected_status],
1576 AT_CHECK([grep 'bailing out' stderr], [], [ignore])
1577 AT_CHECK([grep 'bailing out' micro-suite.log], [], [ignore])
1578 # We'd like to check this here, too, but some shells do not allow to
1579 # turn off job control.
1580 # AT_CHECK([[grep '[iI]nterrupt[ ]' stderr]], [1])
1582 # Ditto with `make' in the loop.
1585 # Need to eliminate outer TESTSUITEFLAGS here.
1586 # Need to normalize exit status here: some make implementations
1587 # exit 1 (BSD make), some exit 2 (GNU make).
1588 AT_CHECK([$MAKE check TESTSUITEFLAGS=; ]dnl
1589 [case $? in 1|2) exit 1;; *) exit $?;; esac],
1590 [1], [ignore], [stderr])
1591 AT_CHECK([grep 'bailing out' stderr], [], [ignore])
1592 AT_CHECK([grep 'bailing out' micro-suite.log], [], [ignore])
1593 # Ditto, parallel case.
1594 AT_CHECK([$MAKE check TESTSUITEFLAGS=--jobs=3; ]dnl
1595 [case $? in 1|2) exit 1;; *) exit $?;; esac],
1596 [1], [ignore], [stderr])
1597 AT_CHECK([grep 'bailing out' stderr], [], [ignore])
1598 AT_CHECK([grep 'bailing out' micro-suite.log], [], [ignore])
1603 # The most important part here is that things should not hang, nor
1604 # get out of hand. OTOH, if the shell sets the default handler to
1605 # ignore PIPE (pdksh, dash), there is little we can do about having the
1606 # test run; it's only the output that won't be there. So all we check
1607 # for is that, if test 7 didn't run serially, then it shouldn't be
1608 # run in the parallel case either; the intermediate tests serve as
1610 # Note that stderr may contain "Broken pipe" errors.
1611 AT_CHECK([($CONFIG_SHELL ./micro-suite -d -3 5-; echo $? >status) | sed 5q],
1612 [], [stdout], [stderr])
1613 AT_CHECK([grep '5.*ok' stdout], [1])
1614 # Apparently some shells don't get around to creating 'status' any more.
1615 # And ksh93 on FreeBSD uses 256 + 13 instead of 128 + 13
1616 AT_CHECK([test ! -s status || grep 141 status || grep 269 status],
1618 AT_CHECK([if test -f micro-suite.dir/7/micro-suite.log; then ]dnl
1619 [ echo "shell ignores SIGPIPE" > sigpipe-stamp ]dnl
1622 AT_CHECK([$CONFIG_SHELL ./micro-suite -d -3 5- --jobs=2 | sed 5q], [], [stdout], [ignore])
1623 AT_CHECK([grep '5.*ok' stdout], [1])
1624 AT_CHECK([test -s sigpipe-stamp || test ! -f micro-suite.dir/7/micro-suite.log], [0])
1629 # Avoid running into a regression when mkfifo does not work.
1630 AT_CHECK_AT_TEST([parallel args but non-working mkfifo],
1633 AT_SETUP([second test])
1636 [], [], [stdout], [stderr],
1637 [AT_SKIP_PARALLEL_TESTS
1639 cat >bin/mkfifo <<\EOF
1644 PATH=`pwd`/bin:$PATH
1647 [AT_CHECK([grep 'second test' stdout], [], [ignore])
1652 AT_CHECK_AT_TEST([colored test results],
1669 AT_SETUP([hardfail])
1672 ], [], [], [], [], [], [
1677 red=`printf '\033@<:@0;31m'`
1678 grn=`printf '\033@<:@0;32m'`
1679 lgn=`printf '\033@<:@1;32m'`
1680 blu=`printf '\033@<:@1;34m'`
1681 std=`printf '\033@<:@m'`
1683 # Check that grep can parse nonprinting characters.
1684 # BSD 'grep' works from a pipe, but not a seekable file.
1685 # GNU or BSD 'grep -a' works on files, but is not portable.
1686 AT_CHECK([case `echo "$std" | grep .` in #'' restore font-lock
1689 esac], [], [ignore], [],
1690 [echo "grep can't parse nonprinting characters" >&2])
1692 if echo 'ab*c' | grep -F 'ab*c' >/dev/null 2>&1; then
1699 AT_CHECK([$CONFIG_SHELL ./micro-suite], [1], [stdout], [stderr])
1700 for color in "$red" "$grn" "$lgn" "$blu"; do
1701 AT_CHECK([cat stdout stderr | $FGREP "$color"], [1])
1704 # Color of test group results.
1705 AT_CHECK([$CONFIG_SHELL ./micro-suite --color=always], [1], [stdout], [stderr])
1706 AT_CHECK([cat stdout | grep " only " | $FGREP "$grn"], [], [ignore])
1707 AT_CHECK([cat stdout | grep " fail " | $FGREP "$red"], [], [ignore])
1708 AT_CHECK([cat stdout | grep " xfail " | $FGREP "$lgn"], [], [ignore])
1709 AT_CHECK([cat stdout | grep " xpass " | $FGREP "$red"], [], [ignore])
1710 AT_CHECK([cat stdout | grep " skip " | $FGREP "$blu"], [], [ignore])
1711 AT_CHECK([cat stdout | grep " hardfail " | $FGREP "$red"], [], [ignore])
1712 AT_CHECK([cat stderr | grep ERROR | $FGREP "$red"], [], [ignore])
1714 # The summary is green if all tests were successful, light green if all
1715 # behaved as expected, and red otherwise.
1716 AT_CHECK([$CONFIG_SHELL ./micro-suite --color=always 1 -k skip],
1718 AT_CHECK([cat stdout | grep 'test.*successful' | $FGREP "$grn"],
1720 AT_CHECK([$CONFIG_SHELL ./micro-suite --color=always 1 -k xfail -k skip],
1722 AT_CHECK([cat stdout | grep 'as expected' | $FGREP "$lgn"], [], [ignore])
1723 AT_CHECK([$CONFIG_SHELL ./micro-suite --color=always -k fail],
1724 [1], [ignore], [stderr])
1725 AT_CHECK([cat stderr | grep ERROR | $FGREP "$red"], [], [ignore])
1726 AT_CHECK([$CONFIG_SHELL ./micro-suite --color=always -k xpass],
1727 [1], [ignore], [stderr])
1728 AT_CHECK([cat stderr | grep ERROR | $FGREP "$red"], [], [ignore])
1729 AT_CHECK([$CONFIG_SHELL ./micro-suite --color=always -k hardfail],
1730 [1], [ignore], [stderr])
1731 AT_CHECK([cat stderr | grep ERROR | $FGREP "$red"], [], [ignore])
1732 # Reset color on verbose output.
1737 ## ------------------- ##
1738 ## srcdir propagation. ##
1739 ## ------------------- ##
1741 AT_SETUP([srcdir propagation])
1743 mkdir pkg vpath-outside vpath-abs
1744 mkdir pkg/t pkg/vpath-inside
1748 AT_DATA([pkg/configure.ac], [[AC_INIT
1749 AC_CONFIG_TESTDIR([t])
1752 cp "$abs_top_srcdir/build-aux/install-sh" pkg
1758 AT_CHECK_AT_PREP([suite],
1759 [[AT_INIT([suite to check srcdir])
1760 AT_SETUP([my only test])
1761 AT_CHECK([test -f "$top_srcdir"/a && test -f "$srcdir"/b])
1763 ]], [], [], [], [pkg/t])
1765 rm -f pkg/t/atconfig
1767 # Build directory totally outside source directory.
1769 AT_CHECK([../pkg/configure $configure_options], [0], [ignore])
1771 AT_CHECK([../../pkg/t/suite], [0], [ignore])
1772 AT_CHECK([../../pkg/t/suite -v], [0], [stdout])
1773 AT_CHECK([grep '^\.\./\.\./pkg/t/suite.at' stdout], [0], [ignore])
1776 # Build directory totally outside source directory (absolute).
1779 AT_CHECK(["$my_srcdir"/configure $configure_options], [0], [ignore])
1781 AT_CHECK(["$my_srcdir"/t/suite], [0], [ignore])
1782 AT_CHECK(["$my_srcdir"/t/suite -v], [0], [stdout])
1783 AT_CHECK([grep '..*/t/suite.at' stdout], [0], [ignore])
1786 # Build directory as subdirectory of source directory.
1788 AT_CHECK([../configure $configure_options], [0], [ignore])
1790 AT_CHECK([../../t/suite], [0], [ignore])
1791 AT_CHECK([../../t/suite -v], [0], [stdout])
1792 AT_CHECK([grep '^\.\./\.\./t/suite.at' stdout], [0], [ignore])
1795 # Build directory as parent of source directory.
1796 AT_CHECK([pkg/configure $configure_options], [0], [ignore])
1798 AT_CHECK([../pkg/t/suite], [0], [ignore])
1799 AT_CHECK([../pkg/t/suite -v], [0], [stdout])
1800 AT_CHECK([grep '^\.\./pkg/t/suite.at' stdout], [0], [ignore])
1803 # Build directory as source directory.
1807 AT_CHECK([./suite], [0], [ignore])
1808 AT_CHECK([./suite -v], [0], [stdout])
1809 AT_CHECK([grep '^\./suite.at' stdout], [0], [ignore])
1815 ## ------------------------------ ##
1816 ## whitespace in absolute testdir ##
1817 ## ------------------------------ ##
1819 AT_SETUP([whitespace in absolute testdir])
1821 dir='dir with whitespace'
1827 AT_CHECK_AT_PREP([suite],
1828 [[AT_INIT([suite to check srcdir])
1829 AT_SETUP([my only test])
1830 AT_CHECK([test -f "$top_srcdir"/a])
1833 AT_CHECK([top_srcdir=$wd ./suite], [0], [ignore])
1834 AT_CHECK([top_srcdir=$wd ./suite -d], [0], [ignore])
1835 AT_CHECK([cd suite.dir/1 && ./run top_srcdir="$wd"], [0], [ignore], [ignore])
1839 ## ------------------ ##
1840 ## unusual file names ##
1841 ## ------------------ ##
1843 AT_SETUP([unusual file names])
1845 AT_DATA_AUTOTEST([d@&t@nl.at],
1846 [[AT_SETUP([test one])
1847 m4_pattern_allow([^dnl$])
1848 AT_CHECK([test "]m4_dquote(AT_LINE)[" = dn[]l.at:3])
1853 AT_DATA_AUTOTEST([sub/"two spaces".at],
1854 [[AT_SETUP([test two])
1855 AT_CHECK([test "]m4_dquote(AT_LINE)[" = "two spaces.at:2"])
1859 AT_CHECK_AT_PREP([suite],
1860 [[AT_INIT([suite to check included file names])
1861 m4_include([d][nl.at])
1862 m4_include([sub/two spaces.at])
1864 AT_CHECK([$CONFIG_SHELL ./suite], [0], [stdout])
1865 AT_CHECK([grep 'two spaces' suite.log], [1])
1869 ## ------------------------- ##
1870 ## Erlang EUnit unit tests. ##
1871 ## ------------------------- ##
1873 AT_SETUP([Erlang Eunit unit tests])
1874 AT_KEYWORDS([Erlang])
1877 AT_DATA([configure.ac], [[AC_INIT
1878 AC_ERLANG_PATH_ERL([no])
1879 AC_ERLANG_PATH_ERLC([no])
1880 if test "$ERL" = "no" || test "$ERLC" = "no"; then
1885 AC_ERLANG_CHECK_LIB([eunit], [HAVE_EUNIT=yes], [HAVE_EUNIT=no])
1887 AC_SUBST([HAVE_ERLANG])
1888 AC_SUBST([HAVE_EUNIT])
1890 AC_CONFIG_TESTDIR([t])
1891 AC_CONFIG_FILES([s/compile], [chmod +x s/compile])
1892 AC_CONFIG_FILES([erlang.conf])
1896 # File to pass info back to us
1897 AT_DATA([erlang.conf.in],
1898 [[HAVE_ERLANG=@HAVE_ERLANG@
1899 HAVE_EUNIT=@HAVE_EUNIT@
1902 # Erlang module to test:
1903 AT_DATA([s/testme.erl],
1911 # Corresponding Eunit unit test module:
1912 AT_DATA([s/testme_tests.erl],
1913 [[-module(testme_tests).
1914 -include_lib("eunit/include/eunit.hrl").
1915 foo_one_test() -> ?assertEqual(one, testme:foo(1)).
1916 foo_two_test() -> ?assertEqual(two, testme:foo(2)).
1917 foo_other_test() -> ?assertEqual(other, testme:foo(42)).
1920 # Compilation script:
1921 AT_DATA([s/compile.in],
1922 [["@ERLC@" -b beam testme.erl testme_tests.erl
1925 AT_CHECK_AT_PREP([suite],
1926 [[AT_INIT([suite to check EUnit integration])
1927 AT_SETUP([my only test])
1928 AT_CHECK_EUNIT([my_testsuite], [{module, testme}],
1929 [-pa "${abs_top_builddir}/s"])
1931 ]], [], [], [], [t])
1937 AT_CHECK([grep '^ERL='\''.*'\' t/atconfig], [], [ignore])
1938 AT_CHECK([grep '^ERLC='\''.*'\' t/atconfig], [], [ignore])
1939 AT_CHECK([grep '^ERLCFLAGS='\''.*'\' t/atconfig], [], [ignore])
1941 if test "$HAVE_ERLANG" = yes && test "$HAVE_EUNIT" = yes; then
1942 AT_CHECK([cd s && $CONFIG_SHELL ./compile])
1945 AT_CHECK([cd t && $CONFIG_SHELL ./suite], [], [ignore])
1947 if test "$HAVE_EUNIT" = yes; then
1948 AT_CHECK([grep 1.*successful t/suite.log], [], [ignore])
1949 AT_CHECK([grep skipped t/suite.log], [1], [ignore])
1951 AT_CHECK([grep 1.*skipped t/suite.log], [], [ignore])
1952 AT_CHECK([grep 0.*successful t/suite.log], [], [ignore])