Fix yesterday's regression in m4_wrap([$1]).
[autoconf.git] / tests / m4sh.at
blob726a23e7bbc2409854ec4cda362cac135b9537d6
1 #                                                       -*- Autotest -*-
3 AT_BANNER([M4sh.])
5 # Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
6 # Free Software 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 3 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
21 ## ---------------- ##
22 ## LINENO support.  ##
23 ## ---------------- ##
25 AT_SETUP([LINENO])
27 # We cannot unset LINENO with Zsh, yet this test case relies on
28 # unsetting LINENO to compare its result when (i) LINENO is supported
29 # and when (ii) it is not.
30 # So just skip if the shell is ZSH.
31 AT_CHECK([test -n "${ZSH_VERSION+set}" && exit 77], ignore)
33 # AT_DATA_LINENO(FILE-NAME,
34 #                UNSET-LINENO = true | false, COUNTER, COUNTER-RE)
35 # ----------------------------------------------------------------
36 # Produce the FILE-NAME M4sh script which uses the COUNTER LINENO or
37 # _oline_, which we can recognized via COUNTER-RE.  Unset LINENO is
38 # UNSET-LINENO.
40 # Use COUNTER, COUNTER-RE = [__LINENO__], [LINENO]
41 #  or                     = [__OLINE__],  [_oline__]
43 # instead of the obvious $LINENO and __oline__, because they would
44 # be replaced in the test suite itself, even before creating these
45 # scripts.  For the same reason, grep for LINENO and _oline__ (sic).
47 # UNSET-LINENO is a shell condition to make sure the scripts have the
48 # same number of lines in the output, so that their outputs be identical.
49 m4_define([AT_DATA_LINENO],
50 [AT_DATA([$1.tas],
51 [[AS@&t@_INIT
52 if $2; then
53   AS@&t@_UNSET([LINENO])
55 _AS@&t@_PREPARE
56 echo "Line: $3"
57 grep 'Line: .*$4' "$[0]" >/dev/null ||
58   AS@&t@_ERROR([cannot find original script])
59 exit 0
60 ]])
61 # If occurrences of $LINENO or __oline__ were wanted, create them.
62 sed 's/__LINENO__/$''LINENO/g;s/__OLINE__/__''oline__/g' $1.tas >$1.as
63 AT_CHECK([autom4te -l m4sh $1.as -o $1])
64 ])# AT_DATA_LINENO
66 # `_oline_', once processed and ran, produces our reference.
67 # We check that we find ourselves by looking at a string which is
68 # available only in the original script: `_oline_'.
69 AT_DATA_LINENO([reference], [false], [__OLINE__], [_oline__])
70 AT_CHECK([./reference], 0, [stdout])
72 # The reference:
73 mv stdout expout
75 # Now using a maybe-functioning LINENO, with different call conventions.
76 # Be sure to be out of the PATH.
77 AT_CHECK([mkdir test || exit 77])
79 AT_DATA_LINENO([test/test-1], [false], [__LINENO__], [LINENO])
80 AT_CHECK([./test/test-1],                          0, [expout])
81 AT_CHECK([(PATH=test$PATH_SEPARATOR$PATH; export PATH; exec test-1)],
82                                                    0, [expout])
83 AT_CHECK([sh ./test/test-1],                       0, [expout])
85 # Now using a disabled LINENO, with different call conventions.
86 AT_DATA_LINENO([test/test-2], [true], [__LINENO__], [LINENO])
87 AT_CHECK([./test/test-2],                          0, [expout])
88 AT_CHECK([(PATH=test$PATH_SEPARATOR$PATH; export PATH; exec test-2)],
89                                                    0, [expout])
90 AT_CHECK([sh ./test/test-2],                       0, [expout])
92 AT_CLEANUP
96 ## ------------ ##
97 ## AS_DIRNAME.  ##
98 ## ------------ ##
100 # Build nested dirs.
101 AT_SETUP([AS@&t@_DIRNAME])
103 AT_DATA_M4SH([script.as],
104 [[AS_INIT
106 # The EXPR variant is allowed to fail if `expr' was considered as too
107 # weak for us, in which case `as_expr=false'.
108 m4_define([DIRNAME_TEST],
109 [dir=`AS_DIRNAME([$1])`
110 test "$dir" = "$2" || (test -n "$3" && test "$dir" = "$3") ||
111   echo "dirname($1) = $dir instead of $2" >&2
113 if test "$as_expr" != false; then
114   dir=`_AS_DIRNAME_EXPR([$1])`
115   test "$dir" = "$2" || (test -n "$3" && test "$dir" = "$3") ||
116     echo "dirname_expr($1) = $dir instead of $2" >&2
119 dir=`_AS_DIRNAME_SED([$1])`
120 test "$dir" = "$2" || (test -n "$3" && test "$dir" = "$3") ||
121   echo "dirname_sed($1) = $dir instead of $2" >&2])
123 DIRNAME_TEST([/],               [/])
124 DIRNAME_TEST([//],              [//],   [/])
125 DIRNAME_TEST([///],             [/])
126 DIRNAME_TEST([//1],             [//],   [/])
127 DIRNAME_TEST([/1],              [/])
128 DIRNAME_TEST([./1],             [.])
129 DIRNAME_TEST([../../2],         [../..])
130 DIRNAME_TEST([//1/],            [//],   [/])
131 DIRNAME_TEST([/1/],             [/])
132 DIRNAME_TEST([./1/],            [.])
133 DIRNAME_TEST([../../2],         [../..])
134 DIRNAME_TEST([//1/3],           [//1])
135 DIRNAME_TEST([/1/3],            [/1])
136 DIRNAME_TEST([./1/3],           [./1])
137 DIRNAME_TEST([../../2/3],       [../../2])
138 DIRNAME_TEST([//1/3///],        [//1])
139 DIRNAME_TEST([/1/3///],         [/1])
140 DIRNAME_TEST([./1/3///],        [./1])
141 DIRNAME_TEST([../../2/3///],    [../../2])
142 DIRNAME_TEST([//1//3/],         [//1])
143 DIRNAME_TEST([/1//3/],          [/1])
144 DIRNAME_TEST([./1//3/],         [./1])
145 DIRNAME_TEST([../../2//3/],     [../../2])
146 AS_EXIT(0)
149 AT_CHECK_M4SH
150 AT_CHECK([./script])
152 AT_CLEANUP
156 ## --------- ##
157 ## AS_ECHO.  ##
158 ## --------- ##
160 # Build nested dirs.
161 AT_SETUP([AS@&t@_ECHO and AS@&t@_ECHO_N])
163 AT_DATA_M4SH([script.as],
164 [[AS_INIT
166 m4_define([ECHO_TEST],
167 [echo=`AS_ECHO(['$1'])`
168 test "X$echo" = 'X$1' ||
169   echo "AS@&t@_ECHO('"'$1'"') outputs '$echo'" >&2
171 echo=`AS_ECHO_N(['$1'])`
172 test "X$echo" = 'X$1' ||
173   echo "AS@&t@_ECHO_N('"'$1'"') outputs '$echo'" >&2])
175 ECHO_TEST([-])
176 ECHO_TEST([--])
177 ECHO_TEST([---...---])
178 ECHO_TEST([      ])
179 ECHO_TEST([-e])
180 ECHO_TEST([-E])
181 ECHO_TEST([-n])
182 ECHO_TEST([-n -n])
183 ECHO_TEST([-e -n])
184 ECHO_TEST([ab\ncd])
185 ECHO_TEST([abcd\c])
186 ECHO_TEST([\a\b\c\f\n\r\t\v\"\])
187 ECHO_TEST([ab
190 ECHO_TEST([
191  ])
192 ECHO_TEST([
193 \c])
194 AS_EXIT(0)
197 AT_CHECK_M4SH
198 AT_CHECK([./script])
200 AT_CLEANUP
204 ## ------------- ##
205 ## AS_BASENAME.  ##
206 ## ------------- ##
208 # Build nested dirs.
209 AT_SETUP([AS@&t@_BASENAME])
211 AT_DATA_M4SH([script.as],
212 [[AS_INIT
214 m4_define([BASENAME_TEST],
215 [base=`AS_BASENAME([$1])`
216 test "$base" = "$2" ||
217   echo "basename($1) = $base instead of $2" >&2
219 base=`_AS_BASENAME_SED([$1])`
220 test "$base" = "$2" ||
221   echo "basename_sed($1) = $base instead of $2" >&2])
223 BASENAME_TEST([//1],             [1])
224 BASENAME_TEST([/1],              [1])
225 BASENAME_TEST([./1],             [1])
226 BASENAME_TEST([../../2],         [2])
227 BASENAME_TEST([//1/],            [1])
228 BASENAME_TEST([/1/],             [1])
229 BASENAME_TEST([./1/],            [1])
230 BASENAME_TEST([../../2],         [2])
231 BASENAME_TEST([//1/3],           [3])
232 BASENAME_TEST([/1/3],            [3])
233 BASENAME_TEST([./1/3],           [3])
234 BASENAME_TEST([../../2/3],       [3])
235 BASENAME_TEST([//1/3///],        [3])
236 BASENAME_TEST([/1/3///],         [3])
237 BASENAME_TEST([./1/3///],        [3])
238 BASENAME_TEST([../../2/3///],    [3])
239 BASENAME_TEST([//1//3/],         [3])
240 BASENAME_TEST([/1//3/],          [3])
241 BASENAME_TEST([./1//3/],         [3])
242 BASENAME_TEST([a.c],             [a.c])
243 BASENAME_TEST([a.c/],            [a.c])
244 BASENAME_TEST([/a.c/],           [a.c])
245 BASENAME_TEST([/1/a.c],          [a.c])
246 BASENAME_TEST([/1/a.c/],         [a.c])
247 BASENAME_TEST([/1/../a.c],       [a.c])
248 BASENAME_TEST([/1/../a.c/],      [a.c])
249 BASENAME_TEST([./1/a.c],         [a.c])
250 BASENAME_TEST([./1/a.c/],        [a.c])
251 AS_EXIT(0)
254 AT_CHECK_M4SH
255 AT_CHECK([./script])
257 AT_CLEANUP
261 ## ------------ ##
262 ## AS_MKDIR_P.  ##
263 ## ------------ ##
265 # Build nested dirs.
266 AT_SETUP([AS@&t@_MKDIR_P])
268 AT_DATA_M4SH([script.as],
269 [[AS_INIT
271 pwd=`pwd`
272 set -e
273 # Absolute
274 AS_MKDIR_P(["$pwd/1/2/3/4/5/6"])
275 test -d "$pwd/1/2/3/4/5/6" ||
276   AS_ERROR([$pwd/1/2/3/4/5/6 has not been properly created])
277 # Relative
278 AS_MKDIR_P(["a/b/c/d/e/f"])
279 test -d a/b/c/d/e/f ||
280   AS_ERROR([a/b/c/d/e/f has not been properly created])
281 AS_EXIT(0)
284 AT_CHECK_M4SH
285 AT_CHECK([./script])
287 AT_CLEANUP
292 ## -------------------- ##
293 ## AS_VERSION_COMPARE.  ##
294 ## -------------------- ##
296 # Build nested dirs.
297 AT_SETUP([AS@&t@_VERSION_COMPARE])
299 AT_DATA_M4SH([script.as],
300 [[AS_INIT
302 m4_define([VERSION_COMPARE_TEST],
303 [AS_VERSION_COMPARE([$1], [$3], [result='<'], [result='='], [result='>'])
304 test "X$result" = "X$2" ||
305   AS_ERROR([version $1 $result $3; should be $1 $2 $3])
306 m4_if([$1], <,
307 [AS_VERSION_COMPARE([$3], [$1], [result='<'], [result='='], [result='>'])
308 test "X$result" = "X>" ||
309   AS_ERROR([version $3 $result $1; should be $3 > $1])])])
311 VERSION_COMPARE_TEST([], =, [])
312 VERSION_COMPARE_TEST([1.0], =, [1.0])
313 VERSION_COMPARE_TEST([alpha-1.0], =, [alpha-1.0])
315 # These tests are taken from libc/string/tst-svc.expect.
316 tst_svc_expect='
317   000 001 00 00a 01 01a 0 0a 2.8 2.8-0.4 20 21 22 212 CP037 CP345 CP1257
318   foo foo-0.4 foo-0.4a foo-0.4b foo-0.5 foo-0.10.5 foo-3.01 foo-3.0
319   foo-3.0.0 foo-3.0.1 foo-3.2 foo-3.10 foo00 foo0
321 test1=''
322 for test2 in $tst_svc_expect; do
323   VERSION_COMPARE_TEST([$test1], <, [$test2])
324   test1=$test2
325 done
327 AS_EXIT(0)
330 AT_CHECK_M4SH
331 AT_CHECK([./script])
333 AT_CLEANUP
338 ## ----------------------------- ##
339 ## Negated classes in globbing.  ##
340 ## ----------------------------- ##
342 # It is known that `[^...]' is not universally supported, but it is
343 # unknown for `[!...]'.
345 AT_SETUP([Negated classes in globbing])
347 AT_DATA_M4SH([script.as],
348 [[AS_INIT
350 case 'with!two!bangs' in
351   *[[!a-z]]*) ;;
352            *) AS_ERROR([[`*[!a-z]*' didn't match `with!two!bangs']]);;
353 esac
355 case without in
356   *[[!a-z]]*) AS_ERROR([[`*[!a-z]*' matched `without']]);;
357 esac
360 AT_CHECK_M4SH
361 AT_CHECK([./script])
363 AT_CLEANUP
368 ## ------------------- ##
369 ## Functions Support.  ##
370 ## ------------------- ##
372 # Hypothesis: the shell we are running, after having checked for
373 # $LINENO support, supports functions.
375 AT_SETUP([Functions Support])
377 AT_DATA_M4SH([script.as],
378 [[AS_INIT
379 _AS_LINENO_PREPARE
381 func_return () {
382   (exit $1)
385 func_success () {
386   func_return 0
389 func_failure () {
390   func_return 1
393 if func_success; then
394   if func_failure; then
395     AS_ERROR([func_failure passed])
396   fi
397 else
398   AS_ERROR([func_success failed])
402 AT_CHECK_M4SH
403 AT_CHECK([./script])
405 AT_CLEANUP
410 ## ------------------------------ ##
411 ## Functions and return Support.  ##
412 ## ------------------------------ ##
414 # Hypothesis: the shell we are running, after having checked for
415 # $LINENO support, supports functions, and the `return' keyword.
417 AT_SETUP([Functions and return Support])
419 AT_DATA_M4SH([script.as],
420 [[AS_INIT
421 _AS_LINENO_PREPARE
423 func_success () {
424   return 0
427 func_failure () {
428   return 1
431 if func_success; then
432   if func_failure; then
433     AS_ERROR([func_failure passed])
434   fi
435 else
436   AS_ERROR([func_success failed])
440 AT_CHECK_M4SH
441 AT_CHECK([./script])
443 AT_CLEANUP
446 ## ------------------------------------ ##
447 ## AS_REQUIRE_SHELL_FN and m4_require.  ##
448 ## ------------------------------------ ##
450 # Hypothesis: M4sh expands the requirements of AS_REQUIRE_SHELL_FN
451 # in the main diversion, and not in M4SH-INIT.
453 AT_SETUP([AS@&t@_REQUIRE_SHELL_FN and m4@&t@_require])
455 AT_DATA_M4SH([script.as], [[dnl
456 AS_INIT
458 m4_defun([in_m4_sh_init], still_in_m4sh_init=yes)
459 m4_defun([not_in_m4_sh_init], still_in_m4sh_init=no)
461 m4_defun([error_if_emitted_in_m4sh_init], [
462   if test x$still_in_m4sh_init = xyes; then
463     AS_ERROR([requirement emitted in M4SH-INIT])
464   fi
467 m4_defun([TEST_FUNC_BODY], [
468 m4_require([error_if_emitted_in_m4sh_init])
469 : echo in shell function, with parameter = [$]1
473 m4_defun([test_init], [
474 AS_REQUIRE([in_m4_sh_init])
475 AS_REQUIRE_SHELL_FN([test_func], [TEST_FUNC_BODY])
476 AS_REQUIRE([not_in_m4_sh_init])
479 test_init
480 test_func parameter1
483 AT_CHECK_M4SH
484 AT_CHECK([./script])
486 AT_CLEANUP
489 ## -------------- ##
490 ## AS_HELP_STRING ##
491 ## -------------- ##
493 AT_SETUP([AS@&t@_HELP_STRING])
494 AT_KEYWORDS([m4@&t@_text_wrap m4@&t@_expand])
496 AT_DATA_M4SH([script.as],
497 [[AS_INIT
498 _AS_LINENO_PREPARE
500 echo "AS_HELP_STRING([--an-option],[some text])"
501 echo "AS_HELP_STRING([--another-much-longer-option],
502 [some other text which should wrap at our default of 80 characters.])"
503 echo "AS_HELP_STRING([--fooT=barT], [foo bar])"
504 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@], [foo bar])"
505 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@123456789], [foo bar])"
506 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@1234567890], [foo bar])"
507 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@12345678901], [foo bar])"
508 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@123456789012], [foo bar])"
509 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@1234567890123], [foo bar])"
510 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@],
511 [some other text which should wrap at our default of 80 characters.])"
512 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@123456789],
513 [some other text which should wrap at our default of 80 characters.])"
514 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@1234567890],
515 [some other text which should wrap at our default of 80 characters.])"
516 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@12345678901],
517 [some other text which should wrap at our default of 80 characters.])"
518 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@123456789012],
519 [some other text which should wrap at our default of 80 characters.])"
520 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@1234567890123],
521 [some other text which should wrap at our default of 80 characters.])"
522 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@],
523 [some other @<][:@ex@:][>@ which should wrap at our default of 80 characters.])"
524 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@123456789],
525 [some other @<][:@ex@:][>@ which should wrap at our default of 80 characters.])"
526 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@1234567890],
527 [some other @<][:@ex@:][>@ which should wrap at our default of 80 characters.])"
528 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@12345678901],
529 [some other @<][:@ex@:][>@ which should wrap at our default of 80 characters.])"
530 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@123456789012],
531 [some other @<][:@ex@:][>@ which should wrap at our default of 80 characters.])"
532 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@1234567890123],
533 [some other @<][:@ex@:][>@ which should wrap at our default of 80 characters.])"
534 echo "AS_HELP_STRING([[--foo[=bar]]],
535 [some other t[]t which should wrap at our default of 80 characters.])"
536 echo "AS_HELP_STRING([[--foo[=bar]123456789]],
537 [some other t[]t which should wrap at our default of 80 characters.])"
538 echo "AS_HELP_STRING([[--foo[=bar]1234567890]],
539 [some other t[]t which should wrap at our default of 80 characters.])"
540 echo "AS_HELP_STRING([[--foo[=bar]12345678901]],
541 [some other t[]t which should wrap at our default of 80 characters.])"
542 echo "AS_HELP_STRING([[--foo[=bar]123456789012]],
543 [some other t[]t which should wrap at our default of 80 characters.])"
544 echo "AS_HELP_STRING([[--foo[=bar]1234567890123]],
545 [some other t[]t which should wrap at our default of 80 characters.])"
546 m4_define([mac], [MACRO])dnl
547 echo "AS_HELP_STRING([--mac], [mac])"
548 echo "AS_HELP_STRING([--o1, --o2], [two
549 options,        one  description])"
550 echo "AS_HELP_STRING([[[--o3, --o4]]], [comma inside literal quoting])"
551 echo "AS_HELP_STRING([--tune1], [check out the tuned formatting],
552 [            ])"
553 echo "AS_HELP_STRING([--tune2], [check out the tuned formatting],
554 [12])"
555 echo "AS_HELP_STRING([--tune3], [check out the tuned formatting],
556 [], [40])"
557 echo "AS_HELP_STRING([--tune4], [check out the tuned formatting],
558 [12], [40])"
561 AT_CHECK_M4SH
562 AT_CHECK([./script], [0],
563 [[  --an-option             some text
564   --another-much-longer-option
565                           some other text which should wrap at our default of
566                           80 characters.
567   --fooT=barT             foo bar
568   --foo[=bar]             foo bar
569   --foo[=bar]123456789    foo bar
570   --foo[=bar]1234567890   foo bar
571   --foo[=bar]12345678901  foo bar
572   --foo[=bar]123456789012 foo bar
573   --foo[=bar]1234567890123
574                           foo bar
575   --foo[=bar]             some other text which should wrap at our default of
576                           80 characters.
577   --foo[=bar]123456789    some other text which should wrap at our default of
578                           80 characters.
579   --foo[=bar]1234567890   some other text which should wrap at our default of
580                           80 characters.
581   --foo[=bar]12345678901  some other text which should wrap at our default of
582                           80 characters.
583   --foo[=bar]123456789012 some other text which should wrap at our default of
584                           80 characters.
585   --foo[=bar]1234567890123
586                           some other text which should wrap at our default of
587                           80 characters.
588   --foo[=bar]             some other [ex] which should wrap at our default of
589                           80 characters.
590   --foo[=bar]123456789    some other [ex] which should wrap at our default of
591                           80 characters.
592   --foo[=bar]1234567890   some other [ex] which should wrap at our default of
593                           80 characters.
594   --foo[=bar]12345678901  some other [ex] which should wrap at our default of
595                           80 characters.
596   --foo[=bar]123456789012 some other [ex] which should wrap at our default of
597                           80 characters.
598   --foo[=bar]1234567890123
599                           some other [ex] which should wrap at our default of
600                           80 characters.
601   --foo[=bar]             some other t[]t which should wrap at our default of
602                           80 characters.
603   --foo[=bar]123456789    some other t[]t which should wrap at our default of
604                           80 characters.
605   --foo[=bar]1234567890   some other t[]t which should wrap at our default of
606                           80 characters.
607   --foo[=bar]12345678901  some other t[]t which should wrap at our default of
608                           80 characters.
609   --foo[=bar]123456789012 some other t[]t which should wrap at our default of
610                           80 characters.
611   --foo[=bar]1234567890123
612                           some other t[]t which should wrap at our default of
613                           80 characters.
614   --MACRO                 mac
615   --o1, --o2              two options, one description
616   [--o3, --o4]            comma inside literal quoting
617   --tune1   check out the tuned formatting
618   --tune2   check out the tuned formatting
619   --tune3                 check out the
620                           tuned
621                           formatting
622   --tune4   check out the tuned
623             formatting
626 AT_CLEANUP
629 ## ------------------- ##
630 ## AS_IF and AS_CASE.  ##
631 ## ------------------- ##
633 AT_SETUP([AS@&t@_IF and AS@&t@_CASE])
635 AT_DATA_M4SH([script.as], [[dnl
636 AS_INIT
637 # Syntax checks: cope with empty arguments.
638 AS_IF([:], [], [echo wrong])
639 AS_IF([:], [echo one], [echo wrong])
640 AS_IF([false], [echo wrong], [echo two])
641 AS_IF([false], [echo wrong])
642 # n-ary version
643 AS_IF([false], [echo wrong],
644       [:], [echo three])
645 AS_IF([false], [echo wrong],
646       [:], [echo four],
647       [echo wrong])
648 AS_IF([false], [echo wrong],
649       [false], [echo wrong])
650 AS_IF([false], [echo wrong],
651       [false], [echo wrong],
652       [echo five])
653 AS_IF([false], [echo wrong],
654       [false], [echo wrong],
655       [:], [echo six],
656       [echo wrong])
657 AS_CASE([foo])
658 AS_CASE([foo], [echo seven])
659 AS_CASE([foo],
660         [foo], [echo eight],
661         [echo wrong])
662 AS_CASE([foo],
663         [foo], [echo nine],
664         [*],   [echo wrong])
665 AS_CASE([foo],
666         [bar], [echo wrong],
667         [foo], [echo ten],
668         [*],   [echo wrong])
670 # check that require works correctly
671 m4_for([n], 1, 9, [],
672 [m4_defun([FOO]n, [foo]n[=]n)dnl
673 m4_defun([BAR]n,
674          [m4_require([FOO]]n[)dnl
675 bar]n[=]n)[]dnl
678 AS_IF([:], [BAR1])
679 echo "foo1=$foo1 bar1=$bar1"
680 AS_IF([:], [], [BAR2])
681 echo "foo2=$foo2 bar2=$bar2"
682 AS_IF([false], [BAR3])
683 echo "foo3=$foo3 bar3=$bar3"
684 AS_IF([false], [], [BAR4])
685 echo "foo4=$foo4 bar4=$bar4"
686 AS_CASE([x], [x], [BAR5])
687 echo "foo5=$foo5 bar5=$bar5"
688 AS_CASE([x], [y], [BAR6])
689 echo "foo6=$foo6 bar6=$bar6"
690 AS_CASE([x],
691         [x], [:],
692         [BAR7])
693 echo "foo7=$foo7 bar7=$bar7"
694 AS_CASE([x],
695         [y], [:],
696         [BAR8])
697 echo "foo8=$foo8 bar8=$bar8"
698 AS_CASE([x],
699         [y], [:],
700         [x], [BAR9])
701 echo "foo9=$foo9 bar9=$bar9"
704 AT_CHECK_M4SH
705 AT_CHECK([./script], [0], [[one
707 three
708 four
709 five
711 seven
712 eight
713 nine
715 foo1=1 bar1=1
716 foo2=2 bar2=
717 foo3=3 bar3=
718 foo4=4 bar4=4
719 foo5=5 bar5=5
720 foo6=6 bar6=
721 foo7=7 bar7=
722 foo8=8 bar8=8
723 foo9=9 bar9=9
726 AT_CLEANUP
729 ## --------------- ##
730 ## AS_LITERAL_IF.  ##
731 ## --------------- ##
733 AT_SETUP([AS@&t@_LITERAL_IF])
735 AT_DATA_M4SH([script.as], [[dnl
736 AS_INIT
737 echo AS_LITERAL_IF([lit], [ok], [ERR]) 1
738 echo AS_LITERAL_IF([l$it], [ERR], [ok]) 2
739 echo AS_LITERAL_IF([l``it], [ERR], [ok]) 3
740 m4_define([mac], [lit])
741 echo AS_LITERAL_IF([mac], [ok], [ERR]) 4
742 echo AS_LITERAL_IF([mac($, ``)], [ok], [ERR]) 5
743 m4_define([mac], [l$it])
744 echo AS_LITERAL_IF([mac], [ERR], [ok]) 6
745 m4_define([mac], [l`it])
746 echo AS_LITERAL_IF([mac], [ERR], [ok]) 7
749 AT_CHECK_M4SH
750 AT_CHECK([./script], [],
751 [[ok 1
752 ok 2
753 ok 3
754 ok 4
755 ok 5
756 ok 6
757 ok 7
760 AT_CLEANUP
763 ## ----------------- ##
764 ## AS_INIT cleanup.  ##
765 ## ----------------- ##
767 AT_SETUP([AS@&t@_INIT cleanup])
769 AT_KEYWORDS([m4@&t@_wrap m4@&t@_wrap_lifo])
771 AT_DATA_M4SH([script.as], [[dnl
772 dnl Registered before AS_INIT's cleanups
773 m4_wrap([echo cleanup 1
775 AS_INIT
776 dnl Registered after AS_INIT's cleanups, thus goes to KILL diversion
777 m4_wrap([echo cleanup 2
778 dnl However, nested wraps and diversions can still be used
779 dnl Also, test wrapping text that looks like parameter reference
780 m4_wrap([echo cleanup 3
781 m4_divert_text([M4SH-INIT], [m4_define([foo], [$1])dnl
782 echo prep foo([4])
783 ])])])
784 dnl Registered before AS_INIT's cleanups
785 m4_wrap_lifo([echo cleanup 5
787 echo body
790 AT_CHECK_M4SH
791 AT_CHECK([./script], [], [[prep 4
792 body
793 cleanup 5
794 cleanup 1
797 AT_CLEANUP