Fix quoting of m4 macros in AT_CHECK.
[autoconf.git] / tests / autotest.at
blobd86088c6f09ed68f1a0398dc9eb26af231811e5d
1 #                                                       -*- Autotest -*-
3 AT_BANNER([Autotest.])
5 # Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Free Software
6 # Foundation, Inc.
8 # This program is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2, or (at your option)
11 # any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write to the Free Software
20 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 # 02110-1301, USA.
24 # AT_DATA_AUTOTEST(FILE-NAME, CONTENTS)
25 # -------------------------------------
26 # Escape the invalid tokens with @&t@.
27 m4_define([AT_DATA_AUTOTEST],
28 [AT_DATA([$1],
29 [m4_bpatsubst([$2], [\(@.\)\(.@\)\|\(m4\|AS\|AT\)\(_\)\|\(d\)\(nl\)],
30               [\1\3\5@&t@\2\4\6])])])
33 # AT_CHECK_AT_PREP(NAME, SUITE-CODE, [STATUS = 0], [STDOUT], [STDERR],
34 #                  [DIR = .])
35 # --------------------------------------------------------------------
36 # Create a new testsuite named NAME that runs a minimal Autotest test suite,
37 # SUITE-CODE.  Do not use `testsuite' for NAME, or the log file it generates
38 # will overwrite the log that the Autoconf test produces when managing
39 # this test case.  STATUS, STDOUT, and STDERR pass directly to the AT_CHECK
40 # that compiles the testsuite.  DIR can specify a particular subdirectory
41 # where the testsuite should live.
42 m4_define([AT_CHECK_AT_PREP],
43 [AT_KEYWORDS([autotest])dnl
44 dnl overquote AT_dir, to make it easier to use
45 m4_pushdef([AT_dir], m4_ifval([$6], [[[$6]]], [.]))dnl
46 dnl
47 AT_CAPTURE_FILE([$1.log])dnl
48 dnl
49 AT_DATA_AUTOTEST(AT_dir[/package.m4],
50 [[m4_define([AT_PACKAGE_NAME],      [GNU Nonsense])
51 m4_define([AT_PACKAGE_TARNAME],   [nonsense])
52 m4_define([AT_PACKAGE_VERSION],   [1.0])
53 m4_define([AT_PACKAGE_STRING],    [GNU Nonsense 1.0])
54 m4_define([AT_PACKAGE_BUGREPORT], [bug-autoconf@gnu.org])
55 ]])
56 dnl
57 AT_DATA_AUTOTEST(AT_dir[/$1.at], [$2])
58 m4_ifval([$6], [(cd AT_dir])
59 AT_CHECK_AUTOM4TE([--language=autotest -o $1 $1.at], [$3], [$4], [$5])
60 m4_ifval([$6], [)])
61 m4_popdef([AT_dir])dnl
62 ]) # AT_CHECK_AT_PREP
64 # AT_CHECK_AT(TITLE, SUITE-CODE, [XFAIL-CONDITION], [STATUS = 0],
65 #             [STDOUT = ignore], STDERR, [PRE-TEST-CODE],
66 #             [POST-TEST-CODE], [SUITE-ARGS])
67 # ---------------------------------------------------------------
68 # Create a new test named TITLE that runs a minimal Autotest test suite,
69 # SUITE-CODE with additional SUITE-ARGS, once without and once with
70 # '-v -x' added.  Call AT_XFAIL_IF with XFAIL-CONDITION.  Pass STDERR
71 # directly to the AT_CHECK that calls the minimal test suite, STDOUT to
72 # the AT_CHECK without '-v -x'; ignore stdout for the latter.
73 # Run PRE-TEST-CODE at the top level after the micro-suite is created, but
74 # before it is run, and POST-TEST-CODE after the micro-suite has been run.
75 m4_define([AT_CHECK_AT],
76 [AT_SETUP([$1])
77 AT_XFAIL_IF([$3])
78 AT_CHECK_AT_PREP([micro-suite], [$2])
80 AT_CHECK([$CONFIG_SHELL ./micro-suite $9],       m4_default([$4], 0),
81          m4_default([$5], [ignore]), [$6])
82 AT_CHECK([$CONFIG_SHELL ./micro-suite -v -x $9], m4_default([$4], 0),
83          [ignore], [$6])
85 AT_CLEANUP
86 ])# AT_CHECK_AT
88 # AT_CHECK_AT_TEST(TITLE, SUITE-SNIPPET, ...)
89 # -----------------------------------------------------------------------
90 # Wrapper for AT_CHECK_AT that surrounds SUITE-SNIPPET with a boilerplate
91 # AT_INIT, AT_SETUP, and AT_CLEANUP and passes other arguments verbatim.
92 m4_define([AT_CHECK_AT_TEST],
93 [AT_CHECK_AT([$1],
95 AT_INIT([artificial test suite])
96 AT_SETUP([my only test])
98 AT_CLEANUP
99 ]], m4_shift2($@))]) # AT_CHECK_AT_TEST
101 # AT_CHECK_AT_SYNTAX(TITLE, SUITE, MESSAGE)
102 # -----------------------------------------
103 # Create a test named TITLE that tries compiling SUITE with syntax
104 # errors with autotest.  Expect a failed compilation, and grep for
105 # MESSAGE occuring within the error output.
106 m4_define([AT_CHECK_AT_SYNTAX],
107 [AT_SETUP([$1])
108 AT_CHECK_AT_PREP([micro-suite], [$2], [1], [], [stderr])
109 AT_CHECK([grep '$3' stderr], [0], [ignore])
110 AT_CLEANUP
111 ])# AT_CHECK_AT_SYNTAX
114 # AT_NO_CMDSUBST
115 # --------------
116 m4_define([AT_NO_CMDSUBST],
117 [if (eval 'foo=$(echo bar) && test "$foo" = bar') >/dev/null 2>&1; then ]dnl
118 [false; else :; fi])
120 # AT_CHECK_EGREP(PATTERN, STATUS, COUNT)
121 # --------------------------------------
122 # Run grep -E, counting how many times PATTERN occurs in the file 'stdout',
123 # and expecting exit STATUS and output COUNT.
124 m4_define([AT_CHECK_EGREP],
125 [AT_CHECK([$EGREP -c '$1' stdout], [$2], [$3
126 ], [ignore])
130 ## ------------------ ##
131 ## Empty test suite.  ##
132 ## ------------------ ##
134 # This is not a sensible thing to do, but the user should not get an unhelpful
135 # error message.
136 AT_CHECK_AT([Empty test suite],
137 [[AT_INIT([empty test suite])
140 AT_CHECK_AT([Banner-only test suite],
141 [[AT_INIT([empty test suite])
142 AT_BANNER([banner])
145 # Next level of emptiness.
146 AT_CHECK_AT_TEST([Empty test], [])
148 # And finally, an empty check should not cause a syntax error.
149 AT_CHECK_AT_TEST([Empty check], [AT_CHECK])
151 # Check for sensible error messages for common bugs.
152 AT_CHECK_AT_SYNTAX([AT@&t@_SETUP without AT@&t@_INIT],
153 [[AT_SETUP([only test])
154 AT_CHECK([:])
155 AT_CLEANUP
156 ]], [AT@&t@_SETUP: missing AT@&t@_INIT detected])
158 AT_CHECK_AT_SYNTAX([AT@&t@_BANNER without AT@&t@_INIT],
159 [[AT_BANNER([just a banner])
160 ]], [AT@&t@_BANNER: missing AT@&t@_INIT detected])
162 AT_CHECK_AT_SYNTAX([AT@&t@_CLEANUP without AT@&t@_INIT],
163 [[AT_CLEANUP
164 ]], [AT@&t@_CLEANUP: missing AT@&t@_INIT detected])
166 AT_CHECK_AT_SYNTAX([Missing AT@&t@_CLEANUP],
167 [[AT_INIT([incomplete test suite])
168 AT_SETUP([only test])
169 AT_CHECK([:])
170 ]], [missing AT@&t@_CLEANUP detected])
172 AT_CHECK_AT_SYNTAX([AT@&t@_CHECK without AT@&t@_SETUP],
173 [[AT_INIT([incomplete test suite])
174 AT_CHECK([:])
175 ]], [AT@&t@_CHECK: missing AT@&t@_SETUP detected])
177 AT_CHECK_AT_SYNTAX([AT@&t@_DATA without AT@&t@_SETUP],
178 [[AT_INIT([incomplete test suite])
179 AT_DATA([file])
180 ]], [AT@&t@_DATA: missing AT@&t@_SETUP detected])
182 AT_CHECK_AT_SYNTAX([AT@&t@_XFAIL_IF without AT@&t@_SETUP],
183 [[AT_INIT([incomplete test suite])
184 AT_XFAIL_IF([:])
185 ]], [AT@&t@_XFAIL_IF: missing AT@&t@_SETUP detected])
187 AT_CHECK_AT_SYNTAX([AT@&t@_KEYWORDS without AT@&t@_SETUP],
188 [[AT_INIT([incomplete test suite])
189 AT_KEYWORDS([keyword])
190 ]], [AT@&t@_KEYWORDS: missing AT@&t@_SETUP detected])
192 AT_CHECK_AT_SYNTAX([AT@&t@_CLEANUP without AT@&t@_SETUP],
193 [[AT_INIT([incomplete test suite])
194 AT_CLEANUP
195 ]], [AT@&t@_CLEANUP: missing AT@&t@_SETUP detected])
197 AT_CHECK_AT_SYNTAX([AT@&t@_BANNER inside AT@&t@_SETUP],
198 [[AT_INIT([incomplete test suite])
199 AT_SETUP([only test])
200 AT_BANNER([banner])
201 AT_CHECK([:])
202 AT_CLEANUP
203 ]], [AT@&t@_BANNER: nested AT@&t@_SETUP detected])
205 AT_CHECK_AT_SYNTAX([AT@&t@_SETUP inside AT@&t@_SETUP],
206 [[AT_INIT([incomplete test suite])
207 AT_SETUP([only test])
208  AT_SETUP([nested test])
209  AT_CHECK([:])
210  AT_CLEANUP
211 AT_CHECK([:])
212 AT_CLEANUP
213 ]], [AT@&t@_SETUP: nested AT@&t@_SETUP detected])
215 AT_CHECK_AT_SYNTAX([Multiple AT@&t@_INIT],
216 [[AT_INIT([[suite, take one]])
217 AT_INIT([repeat])
218 ]], [AT@&t@_INIT: invoked multiple times])
220 # Check for tested programs.  autoconf should only appear once.
221 AT_CHECK_AT([Tested programs],
222 [[AT_INIT([programs test suite])
223 AT_TESTED([autoconf autom4te])
224 AT_TESTED([autoconf])
225 ]], [], [], [], [], [],
226 [AT_CHECK([[sed -n 's|.*/\([^ /]* --version\)|\1|p' micro-suite.log]], [],
227 [[autoconf --version
228 autom4te --version
229 ]])])
231 AT_CHECK_AT([Startup error messages],
232 [[AT_INIT([[suite]])
233 AT_SETUP([only test])
234 AT_CHECK([:])
235 AT_CLEANUP
236 ]], [], [], [], [], [],
237 [AT_CHECK([sed -n '/exec AS_MESSAGE_LOG_FD/q; />&AS_MESSAGE_LOG_FD/p' < micro-suite])])
239 ## ----------------- ##
240 ## Status handling.  ##
241 ## ----------------- ##
243 AT_CHECK_AT_TEST([Truth],
244   [AT_CHECK([:], 0, [], [])])
246 AT_CHECK_AT_TEST([Fallacy],
247   [AT_CHECK([false], [], [], [])],
248   [], [1], [], [ignore], [],
249   [AT_CHECK([grep failed micro-suite.log], [], [ignore])])
251 AT_CHECK_AT_TEST([Skip],
252   [AT_CHECK([exit 77], 0, [], [])],
253   [], [], [], [], [],
254   [AT_CHECK([grep skipped micro-suite.log], [], [ignore])])
256 AT_CHECK_AT_TEST([Hard fail],
257   [AT_CHECK([exit 99])
258    AT_CLEANUP
259    AT_SETUP([another test])
260    AT_XFAIL_IF([:])
261    AT_CHECK([exit 99])],
262   [], [1], [], [ignore], [],
263   [AT_CHECK([grep '2 failed unexpectedly' micro-suite.log], [], [ignore])
264    AT_CHECK([grep ok micro-suite.log], [1])])
266 AT_CHECK_AT_TEST([Syntax error],
267   [AT_CHECK([:])
268    AT_CLEANUP
269    AT_SETUP([syntax])
270    AT_CHECK([if])
271    AT_CLEANUP
272    AT_SETUP([another test])
273    AT_CHECK([:])],
274   [], [1], [], [stderr], [],
275   [AT_CHECK([grep "unable to parse test group: 2" stderr], [0], [ignore])
276    AT_CHECK([$CONFIG_SHELL ./micro-suite 1 3], [0], [ignore])])
278 AT_CHECK_AT_TEST([errexit],
279   [AT_CHECK([false])
280    AT_CLEANUP
281    AT_SETUP([test that should not be run])
282    AT_CHECK([:])],
283   [], [1], [stdout], [stderr], [],
284   [AT_CHECK([test -f micro-suite.log], [1])
285    touch micro-suite.log # shut up AT_CAPTURE_FILE.
286    AT_CHECK([grep "should not be run" stdout], [1])
287    AT_CHECK([grep "1 .* inhibited subsequent" stderr], [], [ignore])],
288   [--errexit])
290 AT_CHECK_AT_TEST([unquoted output],
291   [m4_define([backtick], [`])
292    a=a
293    AT_CHECK_UNQUOTED([echo 'a"b  backtick`'], [],
294      [${a}"`echo 'b  '`\`\backtick]m4_newline)],
295   [], [], [], [], [AT_KEYWORDS([AT@&t@_CHECK_UNQUOTED])])
297 AT_CHECK_AT([Logging],
298   [[AT_INIT([artificial test suite])
299     dnl intentionally write failing tests, to see what gets logged
300     AT_SETUP([one])
301     AT_CHECK([echo magicstring01], [1], [ignore])
302     AT_CLEANUP
303     AT_SETUP([two])
304     AT_CHECK([echo magicstring02 >&2], [1], [], [ignore])
305     AT_CLEANUP
306     AT_SETUP([three])
307     AT_CHECK([echo magicstring03], [1], [ignore-nolog])
308     AT_CLEANUP
309     AT_SETUP([four])
310     AT_CHECK([echo magicstring04 >&2], [1], [], [ignore-nolog])
311     AT_CLEANUP
312     AT_SETUP([five])
313     AT_CHECK([echo magicstring05], [1], [stdout])
314     AT_CLEANUP
315     AT_SETUP([six])
316     AT_CHECK([echo magicstring06 >&2], [1], [], [stderr])
317     AT_CLEANUP
318     AT_SETUP([seven])
319     AT_CHECK([echo magicstring07], [1], [stdout-nolog])
320     AT_CLEANUP
321     AT_SETUP([eight])
322     AT_CHECK([echo magicstring08 >&2], [1], [], [stderr-nolog])
323     AT_CLEANUP
324     AT_SETUP([nine])
325     echo magicstring09 > expout
326     AT_CHECK([echo magicstring09], [1], [expout])
327     AT_CLEANUP
328     AT_SETUP([ten])
329     echo magicstring10 > experr
330     AT_CHECK([echo magicstring10 >&2], [1], [], [experr])
331     AT_CLEANUP
332 ]], [], [1], [], [ignore], [],
333   [AT_CHECK([$CONFIG_SHELL ./micro-suite], [1], [ignore-nolog], [ignore-nolog])
334    AT_CHECK([grep '^magicstring' micro-suite.log], [],
335 [[magicstring01
336 magicstring02
337 magicstring05
338 magicstring06
339 ]])])
342 AT_CHECK_AT([Binary output],
343   [[AT_INIT([artificial test suite])
344     AT_SETUP([pass: no trailing newline])
345     AT_CHECK([printf short], [0], [stdout-nolog])
346     AT_CHECK([cat stdout], [0], [[short]])
347     AT_CLEANUP
348     AT_SETUP([pass: non-printing characters])
349     AT_CHECK([printf '\1\n' >&2], [0], [], [stderr-nolog])
350     printf '\1\n' > expout
351     AT_CHECK([cat stderr], [0], [expout])
352     AT_CLEANUP
353     AT_SETUP([pass: long lines])
354     # 5000 bytes in str
355     str=..........
356     str=$str$str$str$str$str$str$str$str$str$str
357     str=$str$str$str$str$str$str$str$str$str$str
358     str=$str$str$str$str$str
359     AT_CHECK_UNQUOTED([echo $str], [0], [[$str]m4_newline])
360     AT_CLEANUP
361     AT_SETUP([fail: no trailing newline])
362     AT_CHECK([printf short], [0], [stdout-nolog])
363     AT_CHECK([cat stdout], [0], [[long]])
364     AT_CLEANUP
365     AT_SETUP([fail: non-printing characters])
366     AT_CHECK([printf '\1\n' >&2], [0], [], [stderr-nolog])
367     printf '\2\n' > expout
368     AT_CHECK([cat stderr], [0], [expout])
369     AT_CLEANUP
370     AT_SETUP([fail: long lines])
371     # 5000 bytes in str
372     str=..........
373     str=$str$str$str$str$str$str$str$str$str$str
374     str=$str$str$str$str$str$str$str$str$str$str
375     str=$str$str$str$str$str
376     AT_CHECK_UNQUOTED([echo x$str], [0], [[${str}x]m4_newline])
377     AT_CLEANUP
378 ]], [], [0], [], [], [],
379   [AT_CHECK([$CONFIG_SHELL ./micro-suite 4], [1], [ignore], [ignore])
380    AT_CHECK([$CONFIG_SHELL ./micro-suite 5], [1], [ignore], [ignore])
381    AT_CHECK([$CONFIG_SHELL ./micro-suite 6], [1], [ignore], [ignore])], [1-3])
384 AT_CHECK_AT_TEST([Cleanup],
385   [AT_CHECK([test ! -f cleanup.success && test ! -f cleanup.failure])
386    AT_CHECK_UNQUOTED([exit $value], [ignore], [$output],
387      [], [touch cleanup.failure], [touch cleanup.success])],
388   [], [], [], [],
389   [AT_KEYWORDS([AT@&t@_CHECK_UNQUOTED])
390     output=; export output],
391   [AT_CHECK([test -d micro-suite.dir/1])
392    AT_CHECK([test -f micro-suite.dir/1/cleanup.success])
393    AT_CHECK([test ! -f micro-suite.dir/1/cleanup.failure])
395    AT_CHECK([$CONFIG_SHELL ./micro-suite -d value=1], [], [ignore])
396    AT_CHECK([test -f micro-suite.dir/1/cleanup.success])
397    AT_CHECK([test ! -f micro-suite.dir/1/cleanup.failure])
399    AT_CHECK([$CONFIG_SHELL ./micro-suite -d value=1 output=mismatch],
400      [1], [ignore], [ignore])
401    AT_CHECK([test ! -f micro-suite.dir/1/cleanup.success])
402    AT_CHECK([test -f micro-suite.dir/1/cleanup.failure])
404    AT_CHECK([$CONFIG_SHELL ./micro-suite -d value=77], [], [ignore])
405    AT_CHECK([test ! -f micro-suite.dir/1/cleanup.success])
406    AT_CHECK([test ! -f micro-suite.dir/1/cleanup.failure])
408    AT_CHECK([$CONFIG_SHELL ./micro-suite -d value=99], [1], [ignore], [ignore])
409    AT_CHECK([test ! -f micro-suite.dir/1/cleanup.success])
410    AT_CHECK([test ! -f micro-suite.dir/1/cleanup.failure])
411   ], [-d value=0])
413 ## ----------------------------------------------------- ##
414 ## Newlines and command substitutions in test commands.  ##
415 ## ----------------------------------------------------- ##
417 AT_CHECK_AT_TEST([Literal multiline command],
418   [AT_CHECK([echo Auto'
419 'conf], 0, [Auto
420 conf
421 ], [])])
423 AT_CHECK_AT_TEST([Multiline parameter expansion],
424   [FOO='one
425 two'
426    AT_CHECK([echo "$FOO"], 0, [one
428 ], [])])
430 AT_CHECK_AT_TEST([Backquote command substitution],
431   [AT_CHECK([echo `echo hi`], 0, [hi
432 ], [])])
435 AT_CHECK_AT_TEST([Multiline backquote command substitution],
436   [AT_DATA([myfile],[foo
439    AT_CHECK([echo "`cat myfile`"], 0, [foo
441 ], [])])
443 AT_CHECK_AT_TEST([Parenthetical command substitution],
444   [AT_CHECK([echo $(echo hi)], 0, [hi
445 ], [])],
446   [AT_NO_CMDSUBST])
448 AT_CHECK_AT_TEST([Multiline parenthetical command substitution],
449   [AT_DATA([myfile],[foo
452    AT_CHECK([echo "$(cat myfile)"], 0, [foo
454 ], [])],
455   [AT_NO_CMDSUBST])
458 AT_CHECK_AT_TEST([Shell comment in command],
459   [my_echo=echo
460    AT_CHECK([$my_echo one [#] two], [], [one
461 ])])
464 ## ------------------------- ##
465 ## ${...} in test commands.  ##
466 ## ------------------------- ##
468 # If this invalid parameter expansion capsizes the test suite, the entire
469 # AT_SETUP ... AT_CLEANUP subshell will exit, and the commands it runs will
470 # appear to have succeeded.  Therefore, we verify a failing test case.
472 AT_CHECK_AT_TEST([Invalid brace-enclosed parameter expansion],
473   [AT_CHECK([echo '${=invalid}'], 0, [wrong])], [false], 1, ignore, ignore)
476 ## ---------------------------- ##
477 ## M4 macros in test commands.  ##
478 ## ---------------------------- ##
480 AT_CHECK_AT_TEST([Multiline command from M4 expansion],
481   [m4_define([GNU], ['foo
482 bar'])
483    AT_CHECK([echo GNU], 0, [foo
485 ], [])])
487 AT_CHECK_AT_TEST([Double-M4-quoted command],
488   [m4_define([GNU], ['foo
489 bar'])
490    AT_CHECK([[echo GNU]], 0, [[GNU
491 ]], [])])
494 AT_CHECK_AT_TEST([Metacharacters in command from M4 expansion],
495   [m4_define([GNU], [\"`])
496    AT_CHECK([echo '\"`' [GNU] 'GNU'], 0, [GNU [G][NU] [\"`
497 ]], [])])
500 ## -------------------------------------- ##
501 ## Backslash-<newline> in test commands.  ##
502 ## -------------------------------------- ##
504 AT_CHECK_AT_TEST([BS-newline in command],
505   [AT_CHECK([echo Auto"\
506 "conf], 0, [Autoconf
507 ], [])])
509 AT_CHECK_AT_TEST([^BS-newline in command],
510   [AT_CHECK([\
511 echo GNU], 0, [GNU
512 ], [])])
514 AT_CHECK_AT_TEST([BSx641-newline in command],
515   [AT_CHECK([printf '%s\n' Auto"\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
516 "conf], 0, [Auto\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\conf
517 ], [])])
519 AT_CHECK_AT_TEST([BS-BS-newline in command],
520   [AT_CHECK([printf '%s\n' Auto"\\
521 "conf], 0, [Auto\
522 conf
523 ], [])])
525 # A `^BS-BS-newline in command' test will run a command named `\'.  No, thanks.
527 AT_CHECK_AT_TEST([BSx640-newline in command],
528   [AT_CHECK([printf '%s\n' Auto"\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
529 "conf], 0, [Auto\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
530 conf
531 ], [])])
533 # This command has both escaped and unescaped newlines.
534 AT_CHECK_AT_TEST([Newline-CODE-BS-newline in command],
535   [AT_CHECK([printf '%s\n' Auto'
536 'co\
537 nf], 0, [Auto
538 conf
539 ], [])])
541 AT_CHECK_AT_TEST([Single-quote-BS-newline in command],
542   [AT_CHECK([printf '%s\n' Auto'\
543 'conf], 0, [Auto\
544 conf
545 ], [])])
547 AT_CHECK_AT_TEST([Single-quote-newline-BS-newline in command],
548   [AT_CHECK([printf '%s\n' Auto'
550 'conf], 0, [Auto
552 conf
553 ], [])])
556 ## ----------------- ##
557 ## Input from stdin. ##
558 ## ----------------- ##
560 AT_SETUP([Input from stdin])
562 AT_CHECK_AT_PREP([micro-suite],
563 [[AT_INIT
564 AT_SETUP([please enter hello<RETURN><EOF>])
565 AT_CHECK([cat], [], [hello
567 AT_CLEANUP
570 AT_CHECK([echo hello | $CONFIG_SHELL ./micro-suite], [], [ignore])
571 AT_CHECK([$CONFIG_SHELL ./micro-suite </dev/null], [1], [ignore], [ignore])
573 AT_CLEANUP
576 ## ------------------------------- ##
577 ## Funny characters in test names. ##
578 ## ------------------------------- ##
580 # AT_CHECK_AT_TITLE(TITLE, TITLE-TO-TEST, EXPANDED-TITLE-TO-TEST
581 #                   [XFAIL-CONDITION], [COLUMN = 53])
582 # ---------------------------------------------------------------
583 # Create a new test named TITLE that runs an Autotest test suite
584 # comprised of a trivial test named TITLE-TO-TEST, which expands
585 # to EXPANDED-TITLE-TO-TEST.  XFAIL-CONDITION passes verbatim to
586 # AT_CHECK_AT.  Verify that `ok' prints at COLUMN.
587 m4_define([AT_CHECK_AT_TITLE],
588 [AT_CHECK_AT([$1],
590 m4_define([macro_name],         [[macro_expanded]])
591 m4_define([macro_expanded],     [[macro_overexpanded]])
592 m4_define([macro_backquote],    [`])
593 m4_define([macro_single_quote], ['])
594 m4_define([macro_double_quote], ["])
595 ]]dnl restore font-lock: "
596 [[m4_define([macro_backslash],  [\])
597 m4_define([macro_echo],         [$][1])
598 AT_INIT([artificial test suite])
599 AT_SETUP([$2])
600 AT_CHECK([:])
601 AT_CLEANUP
602 ]], [$4], [], [], [], [],
603 dnl This sed script checks for two things - that the output is properly
604 dnl expanded, and that the 'ok' starts on the right column.
605 [AT_KEYWORDS([m4@&t@_expand])
606 AT_CHECK([[$CONFIG_SHELL ./micro-suite |
607             sed -n '/^  1:/{
609 s/[^:]*: \(.*[^  ]\)[    ]*ok.*/\1/p
611 s/^.\{]]]m4_default($5, 53)[[[\}ok.*/ok/p
612 }']],,
613 [[$3
616 AT_CHECK([[$CONFIG_SHELL ./micro-suite -l |
617            sed -n 's/.*[0-9]: [^         ][^     ]*[     ][      ]*\(.*[^        ]\)[    ]*/\1/p']],,
618 [[$3
620 AT_CHECK([[sed -n 's/[^.]*\. \(.*\) ([^)]*): ok.*/\1/p' micro-suite.log]],,
621 [[$3
623 ])])
625 m4_define([AT_CHECK_AT_TITLE_CHAR],
626 [AT_CHECK_AT_TITLE([$1 in a test title], [A $2 in my name],
627                    [A ]m4_ifval([$3], [[$3]], [[$2]])[ in my name], $4, $5)])
629 AT_CHECK_AT_TITLE_CHAR([Backquote],     [`])
630 AT_CHECK_AT_TITLE_CHAR([Single-quote],  ['])
631 AT_CHECK_AT_TITLE_CHAR([Double-quote],  ["])
632 dnl restore font-lock: "
633 AT_CHECK_AT_TITLE_CHAR([Backslash],     [\])
634 AT_CHECK_AT_TITLE_CHAR([Brackets],   [[[]]], [[]])
635 AT_CHECK_AT_TITLE_CHAR([Left bracket],  [@<:@], [@<:@])
636 AT_CHECK_AT_TITLE_CHAR([Right bracket], [@:>@], [@:>@])
637 AT_CHECK_AT_TITLE_CHAR([Quoted pound],  [[#]], [#])
638 AT_CHECK_AT_TITLE_CHAR([Pound],         [#])
639 AT_CHECK_AT_TITLE_CHAR([Quoted comma],  [[,]], [,])
640 AT_CHECK_AT_TITLE_CHAR([Comma],         [,])
641 dnl this test also hits quadrigraphs for ()
642 AT_CHECK_AT_TITLE_CHAR([Parentheses],   [(@{:@)@:}@], [(())])
643 AT_CHECK_AT_TITLE_CHAR([Left paren],    [[(]], [(])
644 AT_CHECK_AT_TITLE_CHAR([Right paren],   [[)]], [)])
646 AT_CHECK_AT_TITLE_CHAR([Quoted Macro], [[macro_name]], [macro_name])
647 AT_CHECK_AT_TITLE_CHAR([Macro],        [macro_name],   [macro_expanded])
648 AT_CHECK_AT_TITLE_CHAR([Macro with backquote],       [macro_backquote], [`])
649 AT_CHECK_AT_TITLE_CHAR([Macro with single-quote], [macro_single_quote], ['])
650 AT_CHECK_AT_TITLE_CHAR([Macro with double-quote], [macro_double_quote], ["])
651 dnl restore font-lock: "
652 AT_CHECK_AT_TITLE_CHAR([Macro with backslash],       [macro_backslash], [\])
653 AT_CHECK_AT_TITLE_CHAR([Macro echoing macro], [macro_echo([macro_name])],
654                        [macro_expanded])
655 AT_CHECK_AT_TITLE_CHAR([Macro echoing single-quote], [macro_echo(['])], ['])
656 AT_CHECK_AT_TITLE_CHAR([Long test title], [0123456789012345678901234567890123])
657 AT_CHECK_AT_TITLE_CHAR([Longer test title],
658                        [01234567890123456789012345678901234], [], [], [54])
661 ## ----------------------- ##
662 ## Long test source lines. ##
663 ## ----------------------- ##
665 # Create a test file that has more than 99 words in a line, for Solaris awk.
666 # While at that, try out the limit of 2000 bytes in a text file line.
668 AT_CHECK_AT_TEST([Long test source lines],
669 [m4_for([nnn], [1], [999], [], [: ])
670 AT_CHECK([:])
671 ], [], [], [], [ignore], [],
672 [AT_CHECK([$CONFIG_SHELL ./micro-suite -k skipalltests], [], [ignore], [ignore])
676 ## ----------------- ##
677 ## Debugging a test. ##
678 ## ----------------- ##
680 AT_CHECK_AT_TEST([Debugging a successful test],
681   [AT_CHECK([:])], [], [], [], [ignore], [],
682 [# Without options, when all tests pass, no test directory should exist.
683 AT_CHECK([test -d micro-suite.dir/1 && exit 42
684           $CONFIG_SHELL ./micro-suite -d 1], [], [ignore], [ignore])
685 # Running with -d should leave a reproducible test group.
686 # Also, running the test script from the test group locks the
687 # directory from removal on some platforms; the script should still be
688 # able to run even if rmdir fails.
689 AT_CHECK([(cd micro-suite.dir/1 && ./run)], [], [ignore], [ignore])
690 # Running a debugging script implies -d.
691 AT_CHECK([(cd micro-suite.dir/1 && ./run)], [], [ignore], [ignore])
694 AT_CHECK_AT_TEST([Debugging script and environment],
695   [AT_CHECK([test "$MY_VAR" = pass || exit 42])],
696   [], [1], [], [ignore], [], [
697 # Changing environment outside of debugging script is not preserved.
698 AT_CHECK([(cd micro-suite.dir/1 && MY_VAR=pass ./run)],
699          [0], [ignore], [ignore])
700 AT_CHECK([(cd micro-suite.dir/1 && ./run)],
701          [1], [ignore], [ignore])
702 # Changing environment as argument to debugging script is preserved.
703 AT_CHECK([(cd micro-suite.dir/1; ./run MY_VAR=pass)],
704          [0], [ignore], [ignore])
705 AT_CHECK([(cd micro-suite.dir/1; ./run)],
706          [0], [ignore], [ignore])
709 # The run script must still be valid when shell metacharacters are passed
710 # in via an environment option.
711 AT_CHECK_AT_TEST([Debugging a failed test],
712   [AT_CHECK([test "$MY_VAR" = "one space" || exit 42])],
713   [], [1], [], [ignore], [], [
714 AT_CHECK([(cd micro-suite.dir/1 && ./run MY_VAR='two  spaces')],
715          [1], [ignore], [ignore])
716 AT_CHECK([(cd micro-suite.dir/1 && ./run MY_VAR='one space')],
717          [0], [ignore], [ignore])
721 # Setting default variable values via atlocal.
722 AT_CHECK_AT_TEST([Using atlocal],
723   [AT_CHECK([test "x$MY_VAR" = "xodd;  'string" || exit 42])],
724   [], [1], [ignore], [ignore], [], [
725 dnl check that command line can set variable
726 AT_CHECK([$CONFIG_SHELL ./micro-suite MY_VAR="odd;  'string"], [0], [ignore])
727 dnl check that command line overrides environment
728 AT_CHECK([MY_VAR="odd;  'string" $CONFIG_SHELL ./micro-suite MY_VAR=unset],
729          [1], [ignore], [ignore])
730 dnl check that atlocal can give it a default
731 AT_CHECK([cat <<EOF >atlocal
732 MY_VAR="odd;  'string"
733 export MY_VAR
734 dnl Also populate enough of atlocal to do what atconfig normally does.
735 at_testdir=.
736 abs_builddir='`pwd`'
737 at_srcdir=.
738 abs_srcdir='`pwd`'
739 at_top_srcdir=.
740 abs_top_srcdir='`pwd`'
741 at_top_build_prefix=
742 abs_top_builddir='`pwd`'
745 AT_CHECK([$CONFIG_SHELL ./micro-suite], [0], [ignore])
746 dnl check that atlocal overrides environment
747 AT_CHECK([MY_VAR=unset $CONFIG_SHELL ./micro-suite], [0], [ignore])
748 dnl check that command line overrides atlocal
749 AT_CHECK([$CONFIG_SHELL ./micro-suite MY_VAR=], [1], [ignore], [ignore])
750 dnl check that syntax error is detected
751 AT_CHECK([$CONFIG_SHELL ./micro-suite =], [1], [], [ignore], [ignore])
752 AT_CHECK([$CONFIG_SHELL ./micro-suite 1=2], [1], [], [ignore], [ignore])
756 # Controlling where the testsuite is run.
757 AT_CHECK_AT_TEST([Choosing where testsuite is run],
758   [AT_CHECK([:])], [], [], [], [], [], [
759 dnl AT_CHECK_AT_TEST tests the default of running in `.'.
760 AT_CHECK([$CONFIG_SHELL ./micro-suite --clean])
761 AT_CHECK([test -f micro-suite.log], [1])
762 AT_CHECK([test -d micro-suite.dir], [1])
763 AT_CHECK([mkdir sub1 sub2])
764 dnl check specifying a different relative path to run in.
765 AT_CHECK([$CONFIG_SHELL ./micro-suite -C sub1], [0], [ignore], [])
766 AT_CHECK([test -f micro-suite.log], [1])
767 AT_CHECK([test -f sub1/micro-suite.log], [0])
768 AT_CHECK([test -d micro-suite.dir], [1])
769 AT_CHECK([test -d sub1/micro-suite.dir], [0])
770 AT_CHECK([$CONFIG_SHELL ./micro-suite -C sub1 --clean])
771 AT_CHECK([test -f sub1/micro-suite.log], [1])
772 AT_CHECK([test -d sub1/micro-suite.dir], [1])
773 dnl check specifying an absolute path to run in.
774 AT_CHECK([$CONFIG_SHELL ./micro-suite --directory="`pwd`/sub2"],
775          [0], [ignore], [])
776 AT_CHECK([test -f micro-suite.log], [1])
777 AT_CHECK([test -f sub2/micro-suite.log], [0])
778 AT_CHECK([$CONFIG_SHELL ./micro-suite --clean --directory="`pwd`/sub2"])
779 AT_CHECK([test -f sub2/micro-suite.log], [1])
780 AT_CHECK([test -f sub2/micro-suite.dir], [1])
781 dnl check for failure detection with bad, missing, or empty directory.
782 AT_CHECK([$CONFIG_SHELL ./micro-suite -C nonesuch || exit 1], [1], [ignore], [ignore])
783 AT_CHECK([$CONFIG_SHELL ./micro-suite -C ''], [1], [ignore], [ignore])
784 AT_CHECK([$CONFIG_SHELL ./micro-suite -C - || exit 1], [1], [ignore], [ignore])
785 AT_CHECK([$CONFIG_SHELL ./micro-suite -C], [1], [ignore], [ignore])
786 dnl check that --help overrides bad directory selection.
787 AT_CHECK([$CONFIG_SHELL ./micro-suite -C nonesuch --help], [0], [ignore], [])
791 ## -------- ##
792 ## Banners. ##
793 ## -------- ##
794 AT_SETUP([Banners])
796 AT_CHECK_AT_PREP([b],
797 [[AT_INIT
798 AT_SETUP(zero)# 1
799 AT_CHECK(:)
800 AT_CLEANUP
802 AT_BANNER([first])
803 AT_SETUP(one a)# 2
804 AT_CHECK(:)
805 AT_CLEANUP
806 AT_SETUP(one b)# 3
807 AT_CHECK(:)
808 AT_CLEANUP
810 AT_BANNER()
811 AT_SETUP(two)# 4
812 AT_CHECK(:)
813 AT_CLEANUP
815 AT_BANNER([second])
816 AT_SETUP(three a)# 5
817 AT_CHECK(:)
818 AT_CLEANUP
819 AT_SETUP(three b)# 6
820 AT_CHECK(:)
821 AT_CLEANUP
824 # AT_CHECK_BANNERS(TESTSUITE-OPTIONS, PATTERN1, COUNT1, PATTERN2, COUNT2)
825 m4_define([AT_CHECK_BANNERS],
826 [AT_CHECK([$CONFIG_SHELL ./b $1], [], [stdout])
827 AT_CHECK_EGREP([$2], m4_if([$3], [0], [1], [0]), [$3])
828 AT_CHECK_EGREP([$4], m4_if([$5], [0], [1], [0]), [$5])
831 AT_CHECK_BANNERS([],            [first], [1], [second], [1])
832 AT_CHECK_BANNERS([-k zero],     [first], [0], [second], [0])
833 AT_CHECK_BANNERS([1],           [first], [0], [second], [0])
834 AT_CHECK_BANNERS([-2],          [first], [1], [second], [0])
835 AT_CHECK_BANNERS([-3],          [first], [1], [second], [0])
836 AT_CHECK_BANNERS([-k one],      [first], [1], [second], [0])
837 AT_CHECK_BANNERS([3-4],         [first], [1], [second], [0])
838 AT_CHECK_BANNERS([3-5],         [first], [1], [second], [1])
839 AT_CHECK_BANNERS([4-5],         [first], [0], [second], [1])
840 AT_CHECK_BANNERS([3-],          [first], [1], [second], [1])
841 AT_CHECK_BANNERS([-k a],        [first], [1], [second], [1])
842 AT_CHECK_BANNERS([4],           [first], [0], [second], [0])
843 AT_CHECK_BANNERS([4-],          [first], [0], [second], [1])
844 AT_CHECK_BANNERS([-k two],      [first], [0], [second], [0])
845 AT_CHECK_BANNERS([1 4],         [first], [0], [second], [0])
846 AT_CHECK_BANNERS([-k three],    [first], [0], [second], [1])
847 AT_CHECK_BANNERS([5],           [first], [0], [second], [0])
848 AT_CHECK_BANNERS([5-],          [first], [0], [second], [1])
849 AT_CLEANUP
852 ## --------- ##
853 ## Keywords. ##
854 ## --------- ##
855 AT_SETUP([Keywords and ranges])
857 AT_CHECK_AT_PREP([k],
858 [[AT_INIT
859 AT_SETUP(none) # 01
860 AT_CHECK(:)
861 AT_CLEANUP
862 AT_SETUP(first) # 02
863 AT_KEYWORDS(key1)
864 AT_CHECK(:)
865 AT_CLEANUP
866 AT_SETUP(second) # 03
867 AT_KEYWORDS(key2)
868 AT_CHECK(:)
869 AT_CLEANUP
870 AT_SETUP(both) # 04
871 AT_KEYWORDS([key1 key2])
872 AT_KEYWORDS([m4_echo([Key1])])
873 AT_CHECK(:)
874 AT_CLEANUP
875 AT_SETUP(test5) # 05
876 AT_CHECK(:)
877 AT_CLEANUP
878 AT_SETUP(test6) # 06
879 AT_CHECK(:)
880 AT_CLEANUP
881 AT_SETUP(test7) # 07
882 AT_CHECK(:)
883 AT_CLEANUP
884 AT_SETUP(test8) # 08
885 AT_CHECK(:)
886 AT_CLEANUP
887 AT_SETUP(test9) # 09
888 AT_CHECK(:)
889 AT_CLEANUP
890 AT_SETUP(test10) # 10
891 AT_CHECK(:)
892 AT_CLEANUP
894 dnl check that AT_KEYWORDS does not duplicate words
895 AT_CHECK([grep -i 'key1.*key1' k], [1])
896 dnl check that -k requires an argument
897 AT_CHECK([$CONFIG_SHELL ./k -k], [1], [], [ignore])
899 # AT_CHECK_KEYS(TESTSUITE-OPTIONS, PATTERN1, COUNT1, PATTERN2, COUNT2)
900 m4_define([AT_CHECK_KEYS],
901 [AT_CHECK([$CONFIG_SHELL ./k $1], 0, [stdout])
902 AT_CHECK_EGREP([$2], 0, [$3])
903 AT_CHECK_EGREP([$4], 1, [$5])
906 AT_CHECK_KEYS([-k key1], [first|both], [2], [none|second], [0])
907 AT_CHECK_KEYS([-k key2], [second|both], [2], [none|first], [0])
908 AT_CHECK_KEYS([-k key1,key2], [both], [1], [none|first|second], [0])
909 AT_CHECK_KEYS([-k key1 -k key2], [first|second|both], [3], [none], [0])
910 AT_CHECK_KEYS([-k '!key1'], [none|second], [2], [first|both], [0])
911 AT_CHECK_KEYS([-k '!key2'], [none|first], [2], [second|both], [0])
912 AT_CHECK_KEYS([-k '!key1,key2'], [second], [1], [none|first|both], [0])
913 AT_CHECK_KEYS([-k 'key1,!key2'], [first], [1], [none|second|both], [0])
914 AT_CHECK_KEYS([-k '!key1,!key2'], [none], [1], [first|second|both], [0])
915 AT_CHECK_KEYS([-k '!key1' -k KEY2], [none|second|both], [3], [first], [0])
916 AT_CHECK_KEYS([-k key1 -k '!key2'], [none|first|both], [3], [second], [0])
917 AT_CHECK_KEYS([-k '!KEY1' -k '!key2'], [none|first|second], [3], [both], [0])
919 AT_CHECK_KEYS([-k none], [none], [1], [first|second|both], [0])
920 AT_CHECK_KEYS([-k key1,both], [both], [1], [none|first|second], [0])
921 AT_CHECK_KEYS([-k key1 -k both], [first|both], [2], [none|second], [0])
922 AT_CHECK_KEYS([-k none,first], [successful], [1], [none|first|second|both], [0])
923 AT_CHECK_KEYS([-k none,first,second,both], [successful], [1], [none|first|second|both], [0])
924 AT_CHECK_KEYS([-k !none,first], [first], [1], [none|second|both], [0])
926 AT_CHECK_KEYS([-k '.*eco.*'], [second], [1], [none|first|both], [0])
927 AT_CHECK_KEYS([-k 'ECO'], [successful], [1], [none|first|second|both], [0])
928 AT_CHECK_KEYS([-k '.*eco'], [successful], [1], [none|first|second|both], [0])
929 AT_CHECK_KEYS([-k 'eco.*'], [successful], [1], [none|first|second|both], [0])
930 AT_CHECK_KEYS([-k 'fir.*'], [first], [1], [none|second|both], [0])
932 AT_CHECK_KEYS([1-2], [none|first], [2], [second|both], [0])
933 AT_CHECK_KEYS([01-002 08], [none|first], [2], [second|both], [0])
934 AT_CHECK_KEYS([1-3 2-1], [none|first|second], [3], [both], [0])
935 AT_CHECK_KEYS([-3], [none|first|second], [3], [both], [0])
936 AT_CHECK_KEYS([4-], [both], [1], [none|first|second], [0])
937 AT_CHECK_KEYS([010], [test10], [1], [none|first|second|both], [0])
938 AT_CHECK_KEYS([-k second 4-], [second|both], [2], [none|first], [0])
940 AT_CHECK([$CONFIG_SHELL ./k 0], [1], [ignore], [ignore])
941 AT_CHECK([$CONFIG_SHELL ./k 0-], [1], [ignore], [ignore])
942 AT_CHECK([$CONFIG_SHELL ./k -0], [1], [ignore], [ignore])
943 AT_CHECK([$CONFIG_SHELL ./k 11], [1], [ignore], [ignore])
944 AT_CHECK([$CONFIG_SHELL ./k 11-], [1], [ignore], [ignore])
945 AT_CHECK([$CONFIG_SHELL ./k 1-011], [1], [ignore], [ignore])
946 AT_CHECK([$CONFIG_SHELL ./k -k nonexistent], [0], [ignore])
948 AT_CHECK_KEYS([--list -k nonexistent], [KEYWORDS], [1], [first|second|both], [0])
949 AT_CHECK_KEYS([--list 1], [none], [1], [first|second|both], [0])
950 AT_CHECK_KEYS([--list 01], [none], [1], [first|second|both], [0])
951 AT_CHECK_KEYS([--list -k none -k first], [none|first], [2], [second|both], [0])
952 AT_CLEANUP
955 ## ----------------- ##
956 ## Keyword wrapping. ##
957 ## ----------------- ##
958 AT_SETUP([Keyword wrapping])
960 AT_CHECK_AT_PREP([k],
961 [[AT_INIT
962 AT_SETUP([test])
963 AT_KEYWORDS([a1 b1 c1 d1 e1 f1 g1 h1 i1 j1 k1 l1 m1 n1 o1 p1 q1 r1 s1 t1])
964 AT_KEYWORDS([u1 v1 w1 x1 y1 z1])
965 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])
966 AT_CLEANUP
967 AT_SETUP([test with long keywords])
968 AT_KEYWORDS(
969 [this-is-a-long-keyword-that-cannot-be-wrapped-so-we-exceed-the-length-limit-here])
970 # surrounded by short ones
971 AT_KEYWORDS([s])
972 AT_KEYWORDS(
973 [another-very-long-keyword-that-hits-the-line-length-limit-bla-bla-bla-bla])
974 AT_KEYWORDS([t])
975 AT_CLEANUP
978 AT_CHECK_KEYS([-l], [.{80}], [1], [.{87}], [0])
980 AT_CLEANUP
982 m4_define([AT_SKIP_PARALLEL_TESTS],
983 [# Per BUGS, we have not yet figured out how to run parallel tests cleanly
984 # under dash and some ksh variants.  For now, only run this test under
985 # limited conditions; help is appreciated in widening this test base.
986 AT_CHECK([test -n "${BASH_VERSION+set}${ZSH_VERSION+set}]]dnl
987 [[${TEST_PARALLEL_AUTOTEST+set}" || exit 77])
991 ## ----------------------- ##
992 ## parallel test execution ##
993 ## ----------------------- ##
995 AT_SETUP([parallel test execution])
997 AT_SKIP_PARALLEL_TESTS
999 # This test tries to ensure that -j runs tests in parallel.
1000 # Such a test is inherently racy, because there are no real-time
1001 # guarantees about scheduling delays.  So we try to minimize
1002 # the chance to lose the race.
1004 # The time needed for a micro-suite consisting of NTESTS tests each
1005 # sleeping for a second is estimated by
1006 #   startup + ntests * (serial_overhead + 1 / njobs)
1008 # in absence of major scheduling delays.  This leads to side conditions:
1009 # - NTESTS should be high, so the STARTUP time is small compared to the
1010 #   test run time, and scheduling delays can even out; it should not be
1011 #   too high, to not slow down the testsuite unnecessarily,
1012 # - the number of concurrent jobs NJOBS should not be too low, so the
1013 #   race is not lost so easily; it should not be too high, to avoid fork
1014 #   failures on tightly limited systems.  4 seems a good compromise
1015 #   here, considering that Autotest spawns several other processes.
1016 # - STARTUP is assumed to be the same for parallel and serial runs, so
1017 #   the latter can estimate the former.
1018 # - To avoid unportable output from time measurement commands, spawn
1019 #   both a parallel and a serial testsuite run; check that the former
1020 #   completes before the latter has completed a fraction SERIAL_NTESTS
1021 #   of the tests (the serial run is executed in a subdirectory), plus
1022 #   some additional time to allow for compensation of SERIAL_OVERHEAD.
1023 # - when adding this time to the serial test execution, an initial delay
1024 #   SERIAL_DELAY of the serial test helps to avoid unreliable scheduling
1025 #   due to the startup burst of the suites.
1027 dnl total number of tests.
1028 m4_define([AT_PARALLEL_NTESTS], [16])
1029 dnl number of jobs to run in parallel.
1030 m4_define([AT_PARALLEL_NJOBS], [4])
1031 dnl number of tests to run serially, as comparison.
1032 m4_define([AT_PARALLEL_SERIAL_NTESTS],
1033   m4_eval(AT_PARALLEL_NTESTS / AT_PARALLEL_NJOBS))
1034 dnl initial delay of serial run, to compensate for SERIAL_OVERHEAD.
1035 dnl This corresponds to 0.67 s of overhead per test.
1036 m4_define([AT_PARALLEL_SERIAL_DELAY],
1037   m4_eval((AT_PARALLEL_NTESTS - AT_PARALLEL_SERIAL_NTESTS + 1) * 2 / 3))
1040 AT_CHECK_AT_PREP([micro-suite],
1041 [[AT_INIT([suite to test parallel execution])
1042 m4_for([count], [1], ]]AT_PARALLEL_NTESTS[[, [],
1043    [AT_SETUP([test number count])
1044     AT_CHECK([sleep 1])
1045     AT_CLEANUP
1049 AT_CHECK([$CONFIG_SHELL ./micro-suite --help | grep " --jobs"], [0], [ignore])
1050 AT_CHECK([$CONFIG_SHELL ./micro-suite -j2foo], [1], [], [stderr])
1051 AT_CHECK([grep 'non-numeric argument' stderr], [], [ignore])
1052 AT_CHECK([$CONFIG_SHELL ./micro-suite --jobs=foo], [1], [], [stderr])
1053 AT_CHECK([grep 'non-numeric argument' stderr], [], [ignore])
1054 AT_CHECK([$CONFIG_SHELL ./micro-suite -j[]AT_PARALLEL_NJOBS], [], [stdout])
1055 # Ensure that all tests run, and lines are not split.
1056 AT_CHECK([grep -c '^.\{53\}ok' stdout], [], [AT_PARALLEL_NTESTS
1058 # Running one test with -j should produce correctly formatted output:
1059 AT_CHECK([$CONFIG_SHELL ./micro-suite -j 3], [], [stdout])
1060 AT_CHECK([grep -c '^.\{53\}ok' stdout], [], [1
1062 # Specifying more jobs than tests should not hang:
1063 AT_CHECK([$CONFIG_SHELL ./micro-suite -j3 3], [], [stdout])
1064 AT_CHECK([grep -c '^.\{53\}ok' stdout], [], [1
1066 # Not even with zero tests:
1067 AT_CHECK([$CONFIG_SHELL ./micro-suite -j -k nomatch], [], [ignore])
1068 AT_CHECK([$CONFIG_SHELL ./micro-suite -j3 -k nomatch], [], [ignore])
1070 # The parallel scheduler requires mkfifo to work.
1071 AT_CHECK([mkfifo fifo || exit 77])
1072 mkdir serial
1074 # Unfortunately, the return value of wait is unreliable,
1075 # so we check that kill fails.
1076 AT_CHECK([$CONFIG_SHELL ./micro-suite --jobs=[]AT_PARALLEL_NJOBS & ]dnl
1077          [sleep AT_PARALLEL_SERIAL_DELAY && ]dnl
1078          [cd serial && $CONFIG_SHELL ../micro-suite -AT_PARALLEL_SERIAL_NTESTS >/dev/null && ]dnl
1079          [{ kill $! && exit 1; :; }], [], [stdout], [ignore])
1080 AT_CHECK([grep -c '^.\{53\}ok' stdout], [], [AT_PARALLEL_NTESTS
1082 AT_CHECK([grep 'AT_PARALLEL_NTESTS tests' stdout], [], [ignore])
1084 AT_CLEANUP
1086 AT_CHECK_AT_TEST([parallel truth],
1087   [AT_CHECK([:], 0, [], [])],
1088   [], [], [], [], [AT_SKIP_PARALLEL_TESTS],
1089   [], [-j])
1091 AT_CHECK_AT_TEST([parallel fallacy],
1092   [AT_CHECK([false], [], [], [])],
1093   [], [1], [], [ignore], [AT_SKIP_PARALLEL_TESTS],
1094   [AT_CHECK([grep failed micro-suite.log], [], [ignore])], [-j])
1096 AT_CHECK_AT_TEST([parallel skip],
1097   [AT_CHECK([exit 77], 0, [], [])],
1098   [], [], [], [], [AT_SKIP_PARALLEL_TESTS],
1099   [AT_CHECK([grep skipped micro-suite.log], [], [ignore])], [-j])
1101 AT_CHECK_AT_TEST([parallel syntax error],
1102   [AT_CHECK([:])
1103    AT_CLEANUP
1104    AT_SETUP([syntax])
1105    AT_CHECK([if])
1106    AT_CLEANUP
1107    AT_SETUP([another test])
1108    AT_CHECK([:])],
1109   [], [1], [], [stderr], [AT_SKIP_PARALLEL_TESTS],
1110   [AT_CHECK([grep "unable to parse test group: 2" stderr], [0], [ignore])
1111    AT_CHECK([$CONFIG_SHELL ./micro-suite -j 3], [0], [ignore])], [-j])
1113 AT_CHECK_AT_TEST([parallel errexit],
1114   [AT_CHECK([false])
1115    AT_CLEANUP
1116    AT_SETUP([barrier test])
1117    AT_CHECK([sleep 4])
1118    AT_CLEANUP
1119    AT_SETUP([test that should not be run])
1120    AT_CHECK([:])],
1121   [], [1], [stdout], [stderr], [AT_SKIP_PARALLEL_TESTS],
1122   [AT_CHECK([test -f micro-suite.log], [1])
1123    touch micro-suite.log # shut up AT_CAPTURE_FILE.
1124    AT_CHECK([grep "should not be run" stdout], [1])
1125    AT_CHECK([grep "[[12]] .* inhibited subsequent" stderr], [], [ignore])],
1126   [-j2 --errexit])
1129 AT_SETUP([parallel autotest and signal handling])
1131 AT_SKIP_PARALLEL_TESTS
1133 # Goals:
1134 # (1) interrupt `./testsuite -jN'
1135 # (2) interrupt `make check TESTSUITEFLAGS=-jN'
1136 # (3) no trailing verbose/trace output
1137 # (4) exit status should be 128+signal
1139 AT_DATA([atlocal],
1140 [[suite_pid=$$
1141 export suite_pid
1144 AT_CHECK_AT_PREP([micro-suite],
1145 [[AT_INIT([suite to test parallel execution])
1146 AT_SETUP([test number 1])
1147 AT_CHECK([sleep 2])
1148 AT_CLEANUP
1149 AT_SETUP([test number 2])
1150 AT_CHECK([sleep 1])
1151 AT_CLEANUP
1152 AT_SETUP([test number 3])
1153 AT_CHECK([sleep 1])
1154 AT_CLEANUP
1155 AT_SETUP([killer test])
1156 AT_CHECK([kill -$signal $suite_pid])
1157 AT_CLEANUP
1158 m4_for([count], [5], [7], [],
1159    [AT_SETUP([test number count])
1160     AT_CHECK([sleep 1])
1161     AT_CLEANUP
1165 AT_DATA([Makefile.in],
1166 [[@SET_MAKE@
1167 SHELL = @SHELL@
1168 TESTSUITE = ./micro-suite
1169 check:
1170         $(SHELL) '$(TESTSUITE)' $(TESTSUITEFLAGS)
1171 .PHONY: check
1174 AT_CHECK([$CONFIG_SHELL $abs_top_builddir/config.status --file=Makefile:Makefile.in],
1175          [], [ignore])
1177 # Test INT and TERM.
1178 for signal in 2 15; do
1179   export signal
1180   AS_VAR_ARITH([expected_status], [128 + $signal])
1182   # Sequential case.
1183   AT_CHECK([$CONFIG_SHELL ./micro-suite], [$expected_status],
1184            [ignore], [stderr])
1185   # Both stderr and the log should contain the notification about the signal.
1186   AT_CHECK([grep 'bailing out' stderr], [], [ignore])
1187   AT_CHECK([grep 'bailing out' micro-suite.log], [], [ignore])
1188   # There should be no junk job status output.
1189   AT_CHECK([[grep '[iI]nterrupt[         ]' stderr]], [1])
1191   # Parallel case.
1192   AT_CHECK([$CONFIG_SHELL ./micro-suite --jobs=3], [$expected_status],
1193            [ignore], [stderr])
1194   AT_CHECK([grep 'bailing out' stderr], [], [ignore])
1195   AT_CHECK([grep 'bailing out' micro-suite.log], [], [ignore])
1196   # We'd like to check this here, too, but some shells do not allow to
1197   # turn off job control.
1198   # AT_CHECK([[grep '[iI]nterrupt[       ]' stderr]], [1])
1200   # Ditto with `make' in the loop.
1201   : ${MAKE=make}
1202   unset MAKEFLAGS
1203   # Need to eliminate outer TESTSUITEFLAGS here.
1204   # Need to normalize exit status here: some make implementations
1205   # exit 1 (BSD make), some exit 2 (GNU make).
1206   AT_CHECK([$MAKE check TESTSUITEFLAGS=; ]dnl
1207            [case $? in 1|2) exit 1;; *) exit $?;; esac],
1208            [1], [ignore], [stderr])
1209   AT_CHECK([grep 'bailing out' stderr], [], [ignore])
1210   AT_CHECK([grep 'bailing out' micro-suite.log], [], [ignore])
1211   # Ditto, parallel case.
1212   AT_CHECK([$MAKE check TESTSUITEFLAGS=--jobs=3; ]dnl
1213            [case $? in 1|2) exit 1;; *) exit $?;; esac],
1214            [1], [ignore], [stderr])
1215   AT_CHECK([grep 'bailing out' stderr], [], [ignore])
1216   AT_CHECK([grep 'bailing out' micro-suite.log], [], [ignore])
1217 done
1220 # Test PIPE.
1221 # The most important part here is that things should not hang, nor
1222 # get out of hand.  OTOH, if the shell sets the default handler to
1223 # ignore PIPE (pdksh, dash), there is little we can do about having the
1224 # test run; it's only the output that won't be there.  So all we check
1225 # for is that, if test 7 didn't run serially, then it shouldn't be
1226 # run in the parallel case either; the intermediate tests serve as
1227 # parallel barrier.
1228 # Note that stderr may contain "Broken pipe" errors.
1229 AT_CHECK([($CONFIG_SHELL ./micro-suite -d -3 5-; echo $? >status) | sed 5q],
1230          [], [stdout], [stderr])
1231 AT_CHECK([grep '5.*ok' stdout], [1])
1232 # Apparently some shells don't get around to creating 'status' any more.
1233 # And ksh93 on FreeBSD uses 256 + 13 instead of 128 + 13
1234 AT_CHECK([test ! -s status || grep 141 status || grep 269 status],
1235          [], [ignore])
1236 AT_CHECK([if test -f micro-suite.dir/7/micro-suite.log; then ]dnl
1237          [  echo "shell ignores SIGPIPE" > sigpipe-stamp ]dnl
1238          [else :; fi])
1240 AT_CHECK([$CONFIG_SHELL ./micro-suite -d -3 5- --jobs=2 | sed 5q], [], [stdout], [ignore])
1241 AT_CHECK([grep '5.*ok' stdout], [1])
1242 AT_CHECK([test -s sigpipe-stamp || test ! -f micro-suite.dir/7/micro-suite.log], [0])
1244 AT_CLEANUP
1246 ## ------------------- ##
1247 ## srcdir propagation. ##
1248 ## ------------------- ##
1250 AT_SETUP([srcdir propagation])
1252 mkdir pkg vpath-outside vpath-abs
1253 mkdir pkg/t pkg/vpath-inside
1254 AT_DATA([pkg/a])
1255 AT_DATA([pkg/t/b])
1257 AT_DATA([pkg/configure.ac], [[AC_INIT
1258 AC_CONFIG_TESTDIR([t])
1259 AC_OUTPUT
1261 cp "$abs_top_srcdir/build-aux/install-sh" pkg
1263 cd pkg
1264 AT_CHECK_AUTOCONF
1265 cd ..
1267 AT_CHECK_AT_PREP([suite],
1268 [[AT_INIT([suite to check srcdir])
1269 AT_SETUP([my only test])
1270 AT_CHECK([test -f "$top_srcdir"/a && test -f "$srcdir"/b])
1271 AT_CLEANUP
1272 ]], [], [], [], [pkg/t])
1274 # Build directory totally outside source directory.
1275 cd vpath-outside
1276 AT_CHECK([../pkg/configure], [0], [ignore])
1277 cd t
1278 AT_CHECK([../../pkg/t/suite], [0], [ignore])
1279 cd ../..
1281 # Build directory totally outside source directory (absolute).
1282 my_srcdir=`pwd`/pkg
1283 cd vpath-abs
1284 AT_CHECK(["$my_srcdir"/configure], [0], [ignore])
1285 cd t
1286 AT_CHECK(["$my_srcdir"/t/suite], [0], [ignore])
1287 cd ../..
1289 # Build directory as subdirectory of source directory.
1290 cd pkg/vpath-inside
1291 AT_CHECK([../configure], [0], [ignore])
1292 cd t
1293 AT_CHECK([../../t/suite], [0], [ignore])
1294 cd ../../..
1296 # Build directory as parent of source directory.
1297 AT_CHECK([pkg/configure], [0], [ignore])
1298 cd t
1299 AT_CHECK([../pkg/t/suite], [0], [ignore])
1300 cd ..
1302 # Build directory as source directory.
1303 cd pkg
1304 AT_CHECK_CONFIGURE
1305 cd t
1306 AT_CHECK([./suite], [0], [ignore])
1307 cd ../..
1309 AT_CLEANUP
1312 ## ------------------------------ ##
1313 ## whitespace in absolute testdir ##
1314 ## ------------------------------ ##
1316 AT_SETUP([whitespace in absolute testdir])
1318 dir='dir with  whitespace'
1319 mkdir "$dir"
1320 cd "$dir"
1321 wd=`pwd`
1323 AT_DATA([a])
1324 AT_CHECK_AT_PREP([suite],
1325 [[AT_INIT([suite to check srcdir])
1326 AT_SETUP([my only test])
1327 AT_CHECK([test -f "$top_srcdir"/a])
1328 AT_CLEANUP
1330 AT_CHECK([top_srcdir=$wd ./suite], [0], [ignore])
1331 AT_CHECK([top_srcdir=$wd ./suite -d], [0], [ignore])
1332 AT_CHECK([cd suite.dir/1 && ./run top_srcdir="$wd"], [0], [ignore], [ignore])
1333 AT_CLEANUP
1336 ## ------------------ ##
1337 ## unusual file names ##
1338 ## ------------------ ##
1340 AT_SETUP([unusual file names])
1342 AT_DATA_AUTOTEST([d@&t@nl.at],
1343 [[AT_SETUP([test one])
1344 m4_pattern_allow([^dnl$])
1345 AT_CHECK([test "]m4_dquote(AT_LINE)[" = dn[]l.at:3])
1346 AT_CLEANUP
1349 mkdir sub
1350 AT_DATA_AUTOTEST([sub/"two  spaces".at],
1351 [[AT_SETUP([test two])
1352 AT_CHECK([test "]m4_dquote(AT_LINE)[" = "two  spaces.at:2"])
1353 AT_CLEANUP
1356 AT_CHECK_AT_PREP([suite],
1357 [[AT_INIT([suite to check included file names])
1358 m4_include([d][nl.at])
1359 m4_include([sub/two  spaces.at])
1361 AT_CHECK([$CONFIG_SHELL ./suite], [0], [stdout])
1362 AT_CHECK([grep 'two spaces' suite.log], [1])
1363 AT_CLEANUP