Prefer HTTPS to FTP and HTTP
[autoconf.git] / tests / autotest.at
blobbcfe00b448557b57c37a81eee2ee828dd2255179
1 #                                                       -*- Autotest -*-
3 AT_BANNER([Autotest.])
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 <https://www.gnu.org/licenses/>.
21 # AT_DATA_AUTOTEST(FILE-NAME, CONTENTS)
22 # -------------------------------------
23 # Escape the invalid tokens with @&t@.
24 m4_define([AT_DATA_AUTOTEST],
25 [AT_DATA([$1],
26 [m4_bpatsubst([$2], [\(@.\)\(.@\)\|\(m4\|AS\|AT\)\(_\)\|\(d\)\(nl\)],
27               [\1\3\5@&t@\2\4\6])])])
30 # AT_CHECK_AT_PREP(NAME, SUITE-CODE, [STATUS = 0], [STDOUT], [STDERR],
31 #                  [DIR = .])
32 # --------------------------------------------------------------------
33 # Create a new testsuite named NAME that runs a minimal Autotest test suite,
34 # SUITE-CODE.  Do not use `testsuite' for NAME, or the log file it generates
35 # will overwrite the log that the Autoconf test produces when managing
36 # this test case.  STATUS, STDOUT, and STDERR pass directly to the AT_CHECK
37 # that compiles the testsuite.  DIR can specify a particular subdirectory
38 # where the testsuite should live.
39 m4_define([AT_CHECK_AT_PREP],
40 [AT_KEYWORDS([autotest])dnl
41 dnl overquote AT_dir, to make it easier to use
42 m4_pushdef([AT_dir], m4_ifval([$6], [[[$6]]], [.]))dnl
43 dnl
44 AT_CAPTURE_FILE(AT_dir[/$1.log])dnl
45 dnl
46 AT_DATA_AUTOTEST(AT_dir[/package.m4],
47 [[m4_define([AT_PACKAGE_NAME],      [GNU Nonsense])
48 m4_define([AT_PACKAGE_TARNAME],   [nonsense])
49 m4_define([AT_PACKAGE_VERSION],   [1.0])
50 m4_define([AT_PACKAGE_STRING],    [GNU Nonsense 1.0])
51 m4_define([AT_PACKAGE_BUGREPORT], [bug-autoconf@gnu.org])
52 ]])
53 dnl
54 AT_DATA_AUTOTEST(AT_dir[/$1.at], [$2])
55 AT_CHECK([cat >m4_default([$6], [.])/atconfig <<EOF
56 at_testdir=m4_default([$6], [.])
57 abs_builddir='`pwd`'
58 at_srcdir=.
59 abs_srcdir='`pwd`'
60 at_top_srcdir=.
61 abs_top_srcdir='`pwd`'
62 at_top_build_prefix=
63 abs_top_builddir='`pwd`'
64 EOF])
65 m4_ifval([$6], [(cd AT_dir])
66 AT_CHECK_AUTOM4TE([--language=autotest -o $1 $1.at], [$3], [$4], [$5])
67 m4_ifval([$6], [)])
68 m4_popdef([AT_dir])dnl
69 ]) # AT_CHECK_AT_PREP
71 # AT_CHECK_AT(TITLE, SUITE-CODE, [XFAIL-CONDITION], [STATUS = 0],
72 #             [STDOUT = ignore], STDERR, [PRE-TEST-CODE],
73 #             [POST-TEST-CODE], [SUITE-ARGS])
74 # ---------------------------------------------------------------
75 # Create a new test named TITLE that runs a minimal Autotest test suite,
76 # SUITE-CODE with additional SUITE-ARGS, once without and once with
77 # '-v -x' added.  Call AT_XFAIL_IF with XFAIL-CONDITION.  Pass STDERR
78 # directly to the AT_CHECK that calls the minimal test suite, STDOUT to
79 # the AT_CHECK without '-v -x'; ignore stdout for the latter.
80 # Run PRE-TEST-CODE at the top level after the micro-suite is created, but
81 # before it is run, and POST-TEST-CODE after the micro-suite has been run.
82 m4_define([AT_CHECK_AT],
83 [AT_SETUP([$1])
84 AT_XFAIL_IF([$3])
85 AT_CHECK_AT_PREP([micro-suite], [$2])
87 AT_CHECK([$CONFIG_SHELL ./micro-suite $9],       m4_default([$4], 0),
88          m4_default([$5], [ignore]), [$6])
89 AT_CHECK([$CONFIG_SHELL ./micro-suite -v -x $9], m4_default([$4], 0),
90          [ignore], [$6])
92 AT_CLEANUP
93 ])# AT_CHECK_AT
95 # AT_CHECK_AT_TEST(TITLE, SUITE-SNIPPET, ...)
96 # -------------------------------------------
97 # Wrapper for AT_CHECK_AT that surrounds SUITE-SNIPPET with a boilerplate
98 # AT_INIT, AT_SETUP, and AT_CLEANUP and passes other arguments verbatim.
99 m4_define([AT_CHECK_AT_TEST],
100 [AT_CHECK_AT([$1],
102 AT_INIT([artificial test suite])
103 AT_SETUP([my only test])
105 AT_CLEANUP
106 ]], m4_shift2($@))]) # AT_CHECK_AT_TEST
108 # AT_CHECK_AT_SYNTAX(TITLE, SUITE, MESSAGE)
109 # -----------------------------------------
110 # Create a test named TITLE that tries compiling SUITE with syntax
111 # errors with autotest.  Expect a failed compilation, and grep for
112 # MESSAGE occurring within the error output.
113 m4_define([AT_CHECK_AT_SYNTAX],
114 [AT_SETUP([$1])
115 AT_CHECK_AT_PREP([micro-suite], [$2], [1], [], [stderr])
116 AT_CHECK([grep '$3' stderr], [0], [ignore])
117 AT_CLEANUP
118 ])# AT_CHECK_AT_SYNTAX
121 # AT_NO_CMDSUBST
122 # --------------
123 m4_define([AT_NO_CMDSUBST],
124 [if (eval 'foo=$(echo bar) && test "$foo" = bar') >/dev/null 2>&1; then ]dnl
125 [false; else :; fi])
127 # AT_CHECK_EGREP(PATTERN, STATUS, COUNT)
128 # --------------------------------------
129 # Run grep -E, counting how many times PATTERN occurs in the file 'stdout',
130 # and expecting exit STATUS and output COUNT.
131 m4_define([AT_CHECK_EGREP],
132 [AT_CHECK([$EGREP -c '$1' stdout], [$2], [$3
133 ], [ignore])
137 ## -------------- ##
138 ## AT_COPYRIGHT.  ##
139 ## -------------- ##
141 # Ensure the FSF notice as well as the user-provided one are present
142 # in the head of the testsuite as well as the --version output.
144 AT_CHECK_AT([AT@&t@_COPYRIGHT],
145 [[AT_INIT([Testing AT@&t@_COPYRIGHT])
146 AT_COPYRIGHT([[This is just a test notice, not a real one, so let's avoid
147 words that may be matched by scanners for legal things,
148 causing extra work for distributors.
149 Multi-line values should be supported.
151 ]], [], [], [stdout], [], [], [
152 AT_CHECK([grep 'Copyright.*Free Software Foundation' stdout], [], [ignore])
153 AT_CHECK([grep 'This is just a test notice' stdout], [], [ignore])
154 AT_CHECK([sed 50q micro-suite | grep 'Copyright.*Free Software Foundation'],
155          [], [ignore])
156 AT_CHECK([sed 50q micro-suite | grep 'This is just a test notice'],
157          [], [ignore])],
158 [--version])
161 ## --------- ##
162 ## AT_DATA.  ##
163 ## --------- ##
165 AT_CHECK_AT_TEST([AT@&t@_DATA], [
166 AT_CHECK([test -f file1], [1])
167 AT_DATA([file1])
168 AT_CHECK([test -f file1 && test ! -s file1])
169 AT_CHECK([echo hi > file1])
170 AT_DATA([file1], [[]])
171 AT_CHECK([test -f file1 && test ! -s file1])
172 file=file2
173 AT_DATA([$file], [[$file
175 AT_CHECK([echo '$file' > file3])
176 AT_CHECK([cmp file2 file3])
180 ## ------------------ ##
181 ## AT_DATA_UNQUOTED.  ##
182 ## ------------------ ##
184 AT_CHECK_AT_TEST([AT@&t@_DATA_UNQUOTED], [
185 AT_CHECK([test -f file1], [1])
186 AT_DATA([file1])
187 AT_CHECK([test -f file1 && test ! -s file1])
188 AT_CHECK([echo hi > file1])
189 AT_DATA([file1], [[]])
190 AT_CHECK([test -f file1 && test ! -s file1])
191 file=file2
192 AT_DATA_UNQUOTED([$file], [[$file
194 AT_CHECK([echo file2 > file3])
195 AT_CHECK([cmp file2 file3])
199 ## ------------------ ##
200 ## Empty test suite.  ##
201 ## ------------------ ##
203 # This is not a sensible thing to do, but the user should not get an unhelpful
204 # error message.
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])
211 AT_BANNER([banner])
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])
223 AT_CHECK([:])
224 AT_CLEANUP
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],
232 [[AT_CLEANUP
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])
238 AT_CHECK([:])
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])
243 AT_FAIL_IF([:])
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])
248 AT_SKIP_IF([:])
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])
253 AT_CHECK([:])
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])
258 AT_DATA([file])
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])
263 AT_XFAIL_IF([:])
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])
273 AT_CLEANUP
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])
279 AT_BANNER([banner])
280 AT_CHECK([:])
281 AT_CLEANUP
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])
288  AT_CHECK([:])
289  AT_CLEANUP
290 AT_CHECK([:])
291 AT_CLEANUP
292 ]], [AT@&t@_SETUP: nested AT@&t@_SETUP detected])
294 AT_CHECK_AT_SYNTAX([Multiple AT@&t@_INIT],
295 [[AT_INIT([[suite, take one]])
296 AT_INIT([repeat])
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]], [],
306 [[autoconf --version
307 autom4te --version
308 ]])])
310 AT_CHECK_AT([Startup error messages],
311 [[AT_INIT([[suite]])
312 AT_SETUP([only test])
313 AT_CHECK([:])
314 AT_CLEANUP
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], [])],
332   [], [], [], [], [],
333   [AT_CHECK([grep skipped micro-suite.log], [], [ignore])])
335 AT_CHECK_AT_TEST([Hard fail],
336   [AT_CHECK([exit 99])
337    AT_CLEANUP
338    AT_SETUP([another test])
339    AT_XFAIL_IF([:])
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],
346   [AT_FAIL_IF([:])
347   AT_CLEANUP
348   AT_SETUP
349   AT_FAIL_IF([false])
350   AT_CLEANUP
351   AT_SETUP
352   AT_FAIL_IF([test x = y])
353   AT_CLEANUP
354   AT_SETUP
355   AT_FAIL_IF([bah])
356   AT_CLEANUP
357   AT_SETUP
358   AT_FAIL_IF([test x = x])
359   AT_CLEANUP
360   AT_SETUP
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],
366   [AT_SKIP_IF([:])
367   AT_CLEANUP
368   AT_SETUP
369   AT_SKIP_IF([false])
370   AT_CLEANUP
371   AT_SETUP
372   AT_SKIP_IF([test x = y])
373   AT_CLEANUP
374   AT_SETUP
375   AT_SKIP_IF([bah])
376   AT_CLEANUP
377   AT_SETUP
378   AT_SKIP_IF([test x = x])
379   AT_CLEANUP
380   AT_SETUP
381   AT_SKIP_IF([test $foo = x])],
382   [], [], [], [], [],
383   [AT_CHECK([grep '2.*skipped' micro-suite.log], [], [ignore], [ignore])])
385 AT_CHECK_AT_TEST([Syntax error],
386   [AT_CHECK([:])
387    AT_CLEANUP
388    AT_SETUP([syntax])
389    AT_CHECK([if])
390    AT_CLEANUP
391    AT_SETUP([another test])
392    AT_CHECK([:])],
393   [], [0], [], [], [],
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.
396    echo 'if' > syntax
397    AT_CHECK([${CONFIG_SHELL-$SHELL} -c 'case `. ./syntax; echo $?` in
398                   0|"") exit 77;;
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])],
402   [1 3])
404 AT_CHECK_AT_TEST([errexit],
405   [AT_CHECK([false])
406    AT_CLEANUP
407    AT_SETUP([test that should not be run])
408    AT_CHECK([:])
409    AT_CLEANUP
410    AT_SETUP([xpassing test])
411    AT_XFAIL_IF([:])
412    AT_CHECK([:])
413    AT_CLEANUP
414    AT_SETUP([another test that should not be run])
415    AT_CHECK([:])
416    AT_CLEANUP
417    AT_SETUP([skipping test])
418    AT_CHECK([exit 77])
419    AT_CLEANUP
420    AT_SETUP([xfailing test])
421    AT_XFAIL_IF([:])
422    AT_CHECK([false])
423    AT_CLEANUP
424    AT_SETUP([a test that should be run])
425    AT_CLEANUP
426    AT_SETUP([hard failure])
427    AT_XFAIL_IF([:])
428    AT_CHECK([exit 99])
429    AT_CLEANUP
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])],
443   [--errexit])
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])])
450    AT_CLEANUP
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], [],
455                                 [ignore])])])],
456   [], [], [stdout], [],
457 [], [
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], [], [], [],
475             [state=run-if-fail
476              AT_CHECK([:]) dnl need this so we do not bail out at this point.
477             ])
478    dnl This should pass, so we enter RUN-IF-PASS.
479    AT_CHECK([test "$state" = run-if-fail], [], [], [], [],
480             [state=run-if-pass])
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])])
487   ],
488   [], [], [], [], [], [], [state=before])
491 AT_CHECK_AT_TEST([unquoted output],
492   [m4_define([backtick], [`])
493    a=a
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
502 ])])
504 AT_CHECK_AT([Logging],
505   [[AT_INIT([artificial test suite])
506     dnl intentionally write failing tests, to see what gets logged
507     AT_SETUP([one])
508     AT_CHECK([echo magicstring01], [1], [ignore])
509     AT_CLEANUP
510     AT_SETUP([two])
511     AT_CHECK([echo magicstring02 >&2], [1], [], [ignore])
512     AT_CLEANUP
513     AT_SETUP([three])
514     AT_CHECK([echo magicstring03], [1], [ignore-nolog])
515     AT_CLEANUP
516     AT_SETUP([four])
517     AT_CHECK([echo magicstring04 >&2], [1], [], [ignore-nolog])
518     AT_CLEANUP
519     AT_SETUP([five])
520     AT_CHECK([echo magicstring05], [1], [stdout])
521     AT_CLEANUP
522     AT_SETUP([six])
523     AT_CHECK([echo magicstring06 >&2], [1], [], [stderr])
524     AT_CLEANUP
525     AT_SETUP([seven])
526     AT_CHECK([echo magicstring07], [1], [stdout-nolog])
527     AT_CLEANUP
528     AT_SETUP([eight])
529     AT_CHECK([echo magicstring08 >&2], [1], [], [stderr-nolog])
530     AT_CLEANUP
531     AT_SETUP([nine])
532     echo magicstring09 > expout
533     AT_CHECK([echo magicstring09], [1], [expout])
534     AT_CLEANUP
535     AT_SETUP([ten])
536     echo magicstring10 > experr
537     AT_CHECK([echo magicstring10 >&2], [1], [], [experr])
538     AT_CLEANUP
539 ]], [], [1], [], [ignore], [],
540   [AT_CHECK([$CONFIG_SHELL ./micro-suite], [1], [ignore-nolog], [ignore-nolog])
541    AT_CHECK([grep '^magicstring' micro-suite.log], [],
542 [[magicstring01
543 magicstring02
544 magicstring05
545 magicstring06
546 ]])])
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]])
554     AT_CLEANUP
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])
559     AT_CLEANUP
560     AT_SETUP([pass: long lines])
561     # 5000 bytes in str
562     str=..........
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])
567     AT_CLEANUP
568     AT_SETUP([fail: no trailing newline])
569     AT_CHECK([printf short], [0], [stdout-nolog])
570     AT_CHECK([cat stdout], [0], [[long]])
571     AT_CLEANUP
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])
576     AT_CLEANUP
577     AT_SETUP([fail: long lines])
578     # 5000 bytes in str
579     str=..........
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])
584     AT_CLEANUP
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])],
596   [], [], [], [],
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'
633 'conf], 0, [Auto
634 conf
635 ], [])])
637 AT_CHECK_AT_TEST([Multiline parameter expansion],
638   [FOO='one
639 two'
640    AT_CHECK([echo "$FOO"], 0, [one
642 ], [])])
644 AT_CHECK_AT_TEST([Backquote command substitution],
645   [AT_CHECK([echo `echo hi`], 0, [hi
646 ], [])])
649 AT_CHECK_AT_TEST([Multiline backquote command substitution],
650   [AT_DATA([myfile],[foo
653    AT_CHECK([echo "`cat myfile`"], 0, [foo
655 ], [])])
657 AT_CHECK_AT_TEST([Parenthetical command substitution],
658   [AT_CHECK([echo $(echo hi)], 0, [hi
659 ], [])],
660   [AT_NO_CMDSUBST])
662 AT_CHECK_AT_TEST([Multiline parenthetical command substitution],
663   [AT_DATA([myfile],[foo
666    AT_CHECK([echo "$(cat myfile)"], 0, [foo
668 ], [])],
669   [AT_NO_CMDSUBST])
672 AT_CHECK_AT_TEST([Shell comment in command],
673   [my_echo=echo
674    AT_CHECK([$my_echo one [#] two], [], [one
675 ])])
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
696 bar'])
697    AT_CHECK([echo GNU], 0, [foo
699 ], [])])
701 AT_CHECK_AT_TEST([Double-M4-quoted command],
702   [m4_define([GNU], ['foo
703 bar'])
704    AT_CHECK([[echo GNU]], 0, [[GNU
705 ]], [])])
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] [\"`
711 ]], [])])
714 ## -------------------------------------- ##
715 ## Backslash-<newline> in test commands.  ##
716 ## -------------------------------------- ##
718 AT_CHECK_AT_TEST([BS-newline in command],
719   [AT_CHECK([echo Auto"\
720 "conf], 0, [Autoconf
721 ], [])])
723 AT_CHECK_AT_TEST([^BS-newline in command],
724   [AT_CHECK([\
725 echo GNU], 0, [GNU
726 ], [])])
728 AT_CHECK_AT_TEST([BSx641-newline in command],
729   [AT_CHECK([printf '%s\n' Auto"\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
730 "conf], 0, [Auto\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\conf
731 ], [])])
733 AT_CHECK_AT_TEST([BS-BS-newline in command],
734   [AT_CHECK([printf '%s\n' Auto"\\
735 "conf], 0, [Auto\
736 conf
737 ], [])])
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\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
744 conf
745 ], [])])
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'
750 'co\
751 nf], 0, [Auto
752 conf
753 ], [])])
755 AT_CHECK_AT_TEST([Single-quote-BS-newline in command],
756   [AT_CHECK([printf '%s\n' Auto'\
757 'conf], 0, [Auto\
758 conf
759 ], [])])
761 AT_CHECK_AT_TEST([Single-quote-newline-BS-newline in command],
762   [AT_CHECK([printf '%s\n' Auto'
764 'conf], 0, [Auto
766 conf
767 ], [])])
770 ## ----------------- ##
771 ## Input from stdin. ##
772 ## ----------------- ##
774 AT_SETUP([Input from stdin])
776 AT_CHECK_AT_PREP([micro-suite],
777 [[AT_INIT
778 AT_SETUP([please enter hello<RETURN><EOF>])
779 AT_CHECK([cat], [], [hello
781 AT_CLEANUP
784 AT_CHECK([echo hello | $CONFIG_SHELL ./micro-suite], [], [ignore])
785 AT_CHECK([$CONFIG_SHELL ./micro-suite </dev/null], [1], [ignore], [ignore])
787 AT_CLEANUP
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],
802 [AT_CHECK_AT([$1],
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])
813 AT_SETUP([$2])
814 AT_CHECK([:])
815 AT_CLEANUP
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 |
821             sed -n '/^  1:/{
823 s/[^:]*: \(.*[^  ]\)[    ]*ok.*/\1/p
825 s/^.\{]]]m4_default($5, 53)[[[\}ok.*/ok/p
826 }']],,
827 [[$3
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']],,
835 [[$3
837 AT_CHECK([[$CONFIG_SHELL ./micro-suite -l |
838            sed -n 's/.*[0-9]: [^         ][^     ]*[     ][      ]*\(.*[^        ]\)[    ]*/\1/p']],,
839 [[$3
841 AT_CHECK([[sed -n 's/[^.]*\. \(.*\) ([^)]*): ok.*/\1/p' micro-suite.log]],,
842 [[$3
844 ])])
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])],
875                        [macro_expanded])
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], [], [: ])
891 AT_CHECK([:])
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], [],
905 [AT_CLEANUP
906 AT_SETUP([test ]nnn)
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"
968 export MY_VAR
969 dnl Also populate enough of atlocal to do what atconfig normally does.
970 at_testdir=.
971 abs_builddir='`pwd`'
972 at_srcdir=.
973 abs_srcdir='`pwd`'
974 at_top_srcdir=.
975 abs_top_srcdir='`pwd`'
976 at_top_build_prefix=
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"],
1010          [0], [ignore], [])
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], [])
1026 # --recheck.
1027 AT_CHECK_AT_TEST([recheck],
1028   [AT_CHECK([:])
1029    AT_CLEANUP
1030    AT_SETUP([failing test])
1031    AT_CHECK([exit 1])
1032    AT_CLEANUP
1033    AT_SETUP([xpassing test])
1034    AT_XFAIL_IF([:])
1035    AT_CHECK([:])
1036    AT_CLEANUP
1037    AT_SETUP([xfailing test])
1038    AT_XFAIL_IF([:])
1039    AT_CHECK([exit 1])
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],
1066          [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])
1069 ], [1 4])
1072 ## -------- ##
1073 ## Banners. ##
1074 ## -------- ##
1075 AT_SETUP([Banners])
1077 AT_CHECK_AT_PREP([b],
1078 [[AT_INIT
1079 AT_SETUP(zero)# 1
1080 AT_CHECK(:)
1081 AT_CLEANUP
1083 AT_BANNER([first])
1084 AT_SETUP(one a)# 2
1085 AT_CHECK(:)
1086 AT_CLEANUP
1087 AT_SETUP(one b)# 3
1088 AT_CHECK(:)
1089 AT_CLEANUP
1091 AT_BANNER()
1092 AT_SETUP(two a)# 4
1093 AT_CHECK(:)
1094 AT_CLEANUP
1095 AT_SETUP(two b)# 5
1096 AT_CHECK(:)
1097 AT_CLEANUP
1099 AT_BANNER([second])
1100 AT_SETUP(three a)# 6
1101 AT_CHECK(:)
1102 AT_CLEANUP
1103 AT_SETUP(three b)# 7
1104 AT_CHECK(:)
1105 AT_CLEANUP
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
1123 dnl unnamed one.
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])
1136 AT_CLEANUP
1139 ## --------- ##
1140 ## Keywords. ##
1141 ## --------- ##
1142 AT_SETUP([Keywords and ranges])
1144 AT_CHECK_AT_PREP([k],
1145 [[AT_INIT
1146 AT_SETUP(none) # 01
1147 AT_CHECK(:)
1148 AT_CLEANUP
1149 AT_SETUP(first) # 02
1150 AT_KEYWORDS(key1)
1151 AT_CHECK(:)
1152 AT_CLEANUP
1153 AT_SETUP(second) # 03
1154 AT_KEYWORDS(key2)
1155 AT_CHECK(:)
1156 AT_CLEANUP
1157 AT_SETUP(both) # 04
1158 AT_KEYWORDS([key1 key2])
1159 AT_KEYWORDS([m4_echo([Key1])])
1160 AT_CHECK(:)
1161 AT_CLEANUP
1162 AT_SETUP(test5) # 05
1163 AT_CHECK(:)
1164 AT_CLEANUP
1165 AT_SETUP(test6) # 06
1166 AT_CHECK(:)
1167 AT_CLEANUP
1168 AT_SETUP(test7) # 07
1169 AT_CHECK(:)
1170 AT_CLEANUP
1171 AT_SETUP(test8) # 08
1172 AT_CHECK(:)
1173 AT_CLEANUP
1174 AT_SETUP(test9) # 09
1175 AT_CHECK(:)
1176 AT_CLEANUP
1177 AT_SETUP(test10) # 10
1178 AT_CHECK(:)
1179 AT_CLEANUP
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])
1239 AT_CLEANUP
1242 ## ----------------- ##
1243 ## Keyword wrapping. ##
1244 ## ----------------- ##
1245 AT_SETUP([Keyword wrapping])
1247 AT_CHECK_AT_PREP([k],
1248 [[AT_INIT
1249 AT_SETUP([test])
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])
1253 AT_CLEANUP
1254 AT_SETUP([test with long keywords])
1255 AT_KEYWORDS(
1256 [this-is-a-long-keyword-that-cannot-be-wrapped-so-we-exceed-the-length-limit-here])
1257 # surrounded by short ones
1258 AT_KEYWORDS([s])
1259 AT_KEYWORDS(
1260 [another-very-long-keyword-that-hits-the-line-length-limit-bla-bla-bla-bla])
1261 AT_KEYWORDS([t])
1262 AT_CLEANUP
1265 AT_CHECK_KEYS([-l], [.{80}], [1], [.{87}], [0])
1267 AT_CLEANUP
1270 ## ------------- ##
1271 ## AT_ARG_OPTION ##
1272 ## ------------- ##
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])],
1284               [echo ping])
1285 AT_SETUP([test argument handling])
1286 AT_CHECK([test "$frob" = "$FROB"])
1287 AT_CHECK([test "$at_arg_frob" = "$FROB_ARG"])
1288 AT_CLEANUP
1289 AT_SETUP([test hyphen normalization])
1290 AT_CHECK([test "$at_arg_opt_with_hyphen" = "$expected"])
1291 AT_CLEANUP
1293 [], [], [stdout], [], [],
1294 [# We already invoked --help.
1295 AT_CHECK([grep '  -f, --frob.*frobnicate' stdout], [], [ignore])
1296 for args in \
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])
1311 done
1312 AT_CHECK([$CONFIG_SHELL ./micro-suite 2 --ping --no-ping --ping expected=false],
1313          [], [stdout])
1314 AT_CHECK([grep -c ping stdout], [], [[3
1316 ], [--help])
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])],
1334                   [echo ping])
1335 AT_SETUP([test argument handling])
1336 AT_CHECK([test "$frob" = "$FROB"])
1337 AT_CHECK([test "$at_arg_frob" = "$FROB_ARG"])
1338 AT_CLEANUP
1339 AT_SETUP([test hyphen normalization])
1340 AT_CHECK([test "$at_arg_opt_with_hyphen" = "$expected"])
1341 AT_CLEANUP
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])
1350 for args in \
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' \
1360   '2 expected=' \
1361   '2 --opt-with-hyphen=baz expected=baz'
1363   AT_CHECK([$CONFIG_SHELL ./micro-suite -x $args], [], [ignore])
1364 done
1365 AT_CHECK([$CONFIG_SHELL ./micro-suite 2 --ping=1 --ping=2 expected=],
1366          [], [stdout])
1367 AT_CHECK([grep -c ping stdout], [], [[2
1369 ], [--help])
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'],
1381          [], [], [ignore])
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])
1436     AT_CHECK([sleep 1])
1437     AT_CLEANUP
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])
1466 mkdir serial
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])
1478 AT_CLEANUP
1480 AT_CHECK_AT_TEST([parallel truth],
1481   [AT_CHECK([:], 0, [], [])],
1482   [], [], [], [], [AT_SKIP_PARALLEL_TESTS],
1483   [], [-j])
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],
1496   [AT_CHECK([:])
1497    AT_CLEANUP
1498    AT_SETUP([syntax])
1499    AT_CHECK([if])
1500    AT_CLEANUP
1501    AT_SETUP([another test])
1502    AT_CHECK([:])],
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.
1506    echo 'if' > syntax
1507    AT_CHECK([${CONFIG_SHELL-$SHELL} -c 'case `. ./syntax; echo $?` in
1508                   0|"") exit 77;;
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])],
1512   [-j2 1 3])
1514 AT_CHECK_AT_TEST([parallel errexit],
1515   [AT_CHECK([false])
1516    AT_CLEANUP
1517    AT_SETUP([barrier test])
1518    AT_CHECK([sleep 4])
1519    AT_CLEANUP
1520    AT_SETUP([test that should not be run])
1521    AT_CHECK([:])],
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])],
1527   [-j2 --errexit])
1530 AT_SETUP([parallel autotest and signal handling])
1532 AT_SKIP_PARALLEL_TESTS
1534 # Goals:
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
1540 AT_DATA([atlocal],
1541 [[suite_pid=$$
1542 export suite_pid
1545 AT_CHECK_AT_PREP([micro-suite],
1546 [[AT_INIT([suite to test parallel execution])
1547 AT_SETUP([test number 1])
1548 AT_CHECK([sleep 2])
1549 AT_CLEANUP
1550 AT_SETUP([test number 2])
1551 AT_CHECK([sleep 1])
1552 AT_CLEANUP
1553 AT_SETUP([test number 3])
1554 AT_CHECK([sleep 1])
1555 AT_CLEANUP
1556 AT_SETUP([killer test])
1557 AT_CHECK([kill -$signal $suite_pid])
1558 AT_CLEANUP
1559 m4_for([count], [5], [7], [],
1560    [AT_SETUP([test number count])
1561     AT_CHECK([sleep 1])
1562     AT_CLEANUP
1566 AT_DATA([Makefile.in],
1567 [[@SET_MAKE@
1568 SHELL = @SHELL@
1569 TESTSUITE = ./micro-suite
1570 check:
1571         $(SHELL) '$(TESTSUITE)' $(TESTSUITEFLAGS)
1572 .PHONY: check
1575 AT_CHECK([$CONFIG_SHELL $abs_top_builddir/config.status --file=Makefile:Makefile.in],
1576          [], [ignore])
1578 # Test INT and TERM.
1579 for signal in 2 15; do
1580   export signal
1581   AS_VAR_ARITH([expected_status], [128 + $signal])
1583   # Sequential case.
1584   AT_CHECK([$CONFIG_SHELL ./micro-suite], [$expected_status],
1585            [ignore], [stderr])
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])
1592   # Parallel case.
1593   AT_CHECK([$CONFIG_SHELL ./micro-suite --jobs=3], [$expected_status],
1594            [ignore], [stderr])
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.
1602   : "${MAKE=make}"
1603   unset MAKEFLAGS
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])
1618 done
1621 # Test PIPE.
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
1628 # parallel barrier.
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],
1636          [], [ignore])
1637 AT_CHECK([if test -f micro-suite.dir/7/micro-suite.log; then ]dnl
1638          [  echo "shell ignores SIGPIPE" > sigpipe-stamp ]dnl
1639          [else :; fi])
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])
1645 AT_CLEANUP
1648 # Avoid running into a regression when mkfifo does not work.
1649 AT_CHECK_AT_TEST([parallel args but non-working mkfifo],
1650 [AT_CHECK([:])
1651 AT_CLEANUP
1652 AT_SETUP([second test])
1653 AT_CHECK([:])
1655 [], [], [stdout], [stderr],
1656 [AT_SKIP_PARALLEL_TESTS
1657 mkdir bin
1658 cat >bin/mkfifo <<\EOF
1659 #! /bin/sh
1660 exit 1
1662 chmod +x bin/mkfifo
1663 PATH=`pwd`/bin:$PATH
1664 export PATH
1666 [AT_CHECK([grep 'second test' stdout], [], [ignore])
1667 ], [--jobs])
1670 # --color
1671 AT_CHECK_AT_TEST([colored test results],
1672   [AT_CHECK([:])
1673    AT_CLEANUP
1674    AT_SETUP([fail])
1675    AT_CHECK([exit 1])
1676    AT_CLEANUP
1677    AT_SETUP([xpass])
1678    AT_XFAIL_IF([:])
1679    AT_CHECK([:])
1680    AT_CLEANUP
1681    AT_SETUP([xfail])
1682    AT_XFAIL_IF([:])
1683    AT_CHECK([exit 1])
1684    AT_CLEANUP
1685    AT_SETUP([skip])
1686    AT_CHECK([exit 77])
1687    AT_CLEANUP
1688    AT_SETUP([hardfail])
1689    AT_XFAIL_IF([:])
1690    AT_CHECK([exit 99])
1691 ], [], [], [], [], [], [
1693 TERM=ansi
1694 export TERM
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
1706             $std) :;;
1707             *) exit 77;;
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
1712   FGREP="grep -F"
1713 else
1714   FGREP=fgrep
1717 # No color.
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])
1721 done
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],
1736          [0], [stdout])
1737 AT_CHECK([cat stdout | grep 'test.*successful' | $FGREP "$grn"],
1738          [], [ignore])
1739 AT_CHECK([$CONFIG_SHELL ./micro-suite --color=always 1 -k xfail -k skip],
1740          [0], [stdout])
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.
1752 printf %s\\n "$std"
1753 ], [1])
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
1765 AT_DATA([pkg/a])
1766 AT_DATA([pkg/t/b])
1768 AT_DATA([pkg/configure.ac], [[AC_INIT
1769 AC_CONFIG_TESTDIR([t])
1770 AC_OUTPUT
1772 cp "$abs_top_srcdir/build-aux/install-sh" pkg
1774 cd pkg
1775 AT_CHECK_AUTOCONF
1776 cd ..
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])
1782 AT_CLEANUP
1783 ]], [], [], [], [pkg/t])
1785 rm -f pkg/t/atconfig
1787 # Build directory totally outside source directory.
1788 cd vpath-outside
1789 AT_CHECK([../pkg/configure $configure_options], [0], [ignore])
1790 cd t
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])
1794 cd ../..
1796 # Build directory totally outside source directory (absolute).
1797 my_srcdir=`pwd`/pkg
1798 cd vpath-abs
1799 AT_CHECK(["$my_srcdir"/configure $configure_options], [0], [ignore])
1800 cd t
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])
1804 cd ../..
1806 # Build directory as subdirectory of source directory.
1807 cd pkg/vpath-inside
1808 AT_CHECK([../configure $configure_options], [0], [ignore])
1809 cd t
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])
1813 cd ../../..
1815 # Build directory as parent of source directory.
1816 AT_CHECK([pkg/configure $configure_options], [0], [ignore])
1817 cd t
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])
1821 cd ..
1823 # Build directory as source directory.
1824 cd pkg
1825 AT_CHECK_CONFIGURE
1826 cd t
1827 AT_CHECK([./suite], [0], [ignore])
1828 AT_CHECK([./suite -v], [0], [stdout])
1829 AT_CHECK([grep '^\./suite.at' stdout], [0], [ignore])
1830 cd ../..
1832 AT_CLEANUP
1835 ## ------------------------------ ##
1836 ## whitespace in absolute testdir ##
1837 ## ------------------------------ ##
1839 AT_SETUP([whitespace in absolute testdir])
1841 dir='dir with  whitespace'
1842 mkdir "$dir"
1843 cd "$dir"
1844 wd=`pwd`
1846 AT_DATA([a])
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])
1851 AT_CLEANUP
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])
1856 AT_CLEANUP
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])
1869 AT_CLEANUP
1872 mkdir sub
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"])
1876 AT_CLEANUP
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])
1886 AT_CLEANUP
1889 ## --------------- ##
1890 ## C executables.  ##
1891 ## --------------- ##
1893 AT_SETUP([C unit tests])
1894 AT_KEYWORDS([AC_@&t@CONFIG_TESTDIR])
1895 AT_KEYWORDS([AT_@&t@TESTED])
1897 mkdir t
1898 AT_DATA([configure.ac], [[AC_INIT
1899 AC_PROG_CC
1900 AC_CONFIG_TESTDIR([t], [.])
1901 AC_CONFIG_FILES([Makefile])
1902 AC_OUTPUT
1905 # Test file
1906 AT_DATA([testprog.c],
1907 [[int main(int argc) { return argc == 2 ? 0 : 1; }
1910 # Testsuite
1911 AT_DATA([Makefile.in],
1912 [[CC=@CC@
1913 CFLAGS=@CFLAGS@
1915 testprog@EXEEXT@: testprog.o
1916 testprog.o: testprog.c
1917 .SUFFIXES: .c .o @EXEEXT@
1919 .c.o:
1920         $(CC) -c $<
1921 .o@EXEEXT@:
1922         $(CC) -o $@ $^
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])
1931 AT_CLEANUP
1932 ]], [], [], [], [t])
1934 rm t/atconfig
1935 AT_CHECK_AUTOCONF
1936 AT_CHECK_CONFIGURE
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])
1941 AT_CLEANUP
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])
1952 mkdir t
1953 AT_DATA([configure.ac], [[AC_INIT
1954 AC_PROG_CC
1955 case $ac_cv_exeext in
1956   '' | .exe) ;;
1957   *) exit 77 ;;
1958 esac
1959 ac_cv_exeext=.exe
1960 AC_SUBST([EXEEXT], [$ac_cv_exeext])
1961 AC_CONFIG_TESTDIR([t], [.])
1962 AC_CONFIG_FILES([Makefile])
1963 AC_OUTPUT
1966 # Test file
1967 AT_DATA([testprog.c],
1968 [[int main(int argc) { return argc == 2 ? 0 : 1; }
1971 # Testsuite
1972 AT_DATA([Makefile.in],
1973 [[CC=@CC@
1974 CFLAGS=@CFLAGS@
1976 testprog@EXEEXT@: testprog.o
1977 testprog.o: testprog.c
1978 .SUFFIXES: .c .o @EXEEXT@
1980 .c.o:
1981         $(CC) -c $<
1982 .o@EXEEXT@:
1983         $(CC) -o $@ $^
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])
1992 AT_CLEANUP
1993 ]], [], [], [], [t])
1995 rm t/atconfig
1996 AT_CHECK_AUTOCONF
1997 AT_CHECK_CONFIGURE
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])
2002 AT_CLEANUP
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])
2013 mkdir s t
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
2018   HAVE_ERLANG=no
2019   HAVE_EUNIT=no
2020 else
2021   HAVE_ERLANG=yes
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])
2030 AC_OUTPUT
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],
2041 [[-module(testme).
2042 -export([foo/1]).
2043 foo(1) -> one;
2044 foo(2) -> two;
2045 foo(_) -> other.
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"])
2067 AT_CLEANUP
2068 ]], [], [], [], [t])
2070 AT_CHECK_AUTOCONF
2071 AT_CHECK_CONFIGURE
2072 . ./erlang.conf
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])
2087 else
2088   AT_CHECK([grep 1.*skipped t/suite.log], [], [ignore])
2089   AT_CHECK([grep 0.*successful t/suite.log], [], [ignore])
2092 AT_CLEANUP