Avoid infinite aclocal loop.
[autoconf.git] / tests / m4sh.at
blobe01f769fa4263b6f1c25254e8b22d8e14adc784f
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 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.
23 ## ---------------- ##
24 ## LINENO support.  ##
25 ## ---------------- ##
27 AT_SETUP([LINENO])
29 # We cannot unset LINENO with Zsh, yet this test case relies on
30 # unsetting LINENO to compare its result when (i) LINENO is supported
31 # and when (ii) it is not.
32 # So just skip if the shell is ZSH.
33 AT_CHECK([test -n "${ZSH_VERSION+set}" && exit 77], ignore)
35 # AT_DATA_LINENO(FILE-NAME,
36 #                UNSET-LINENO = true | false, COUNTER, COUNTER-RE)
37 # ----------------------------------------------------------------
38 # Produce the FILE-NAME M4sh script which uses the COUNTER LINENO or
39 # _oline_, which we can recognized via COUNTER-RE.  Unset LINENO is
40 # UNSET-LINENO.
42 # Use COUNTER, COUNTER-RE = [__LINENO__], [LINENO]
43 #  or                     = [__OLINE__],  [_oline__]
45 # instead of the obvious $LINENO and __oline__, because they would
46 # be replaced in the test suite itself, even before creating these
47 # scripts.  For the same reason, grep for LINENO and _oline__ (sic).
49 # UNSET-LINENO is a shell condition to make sure the scripts have the
50 # same number of lines in the output, so that their outputs be identical.
51 m4_define([AT_DATA_LINENO],
52 [AT_DATA([$1.tas],
53 [[AS@&t@_INIT
54 if $2; then
55   AS@&t@_UNSET([LINENO])
57 _AS@&t@_PREPARE
58 echo "Line: $3"
59 grep 'Line: .*$4' "$[0]" >/dev/null ||
60   AS@&t@_ERROR([cannot find original script])
61 exit 0
62 ]])
63 # If occurrences of $LINENO or __oline__ were wanted, create them.
64 sed 's/__LINENO__/$''LINENO/g;s/__OLINE__/__''oline__/g' $1.tas >$1.as
65 AT_CHECK([autom4te -l m4sh $1.as -o $1])
66 ])# AT_DATA_LINENO
68 # `_oline_', once processed and ran, produces our reference.
69 # We check that we find ourselves by looking at a string which is
70 # available only in the original script: `_oline_'.
71 AT_DATA_LINENO([reference], [false], [__OLINE__], [_oline__])
72 AT_CHECK([./reference], 0, [stdout])
74 # The reference:
75 mv stdout expout
77 # Now using a maybe-functioning LINENO, with different call conventions.
78 # Be sure to be out of the PATH.
79 AT_CHECK([mkdir test || exit 77])
81 AT_DATA_LINENO([test/test-1], [false], [__LINENO__], [LINENO])
82 AT_CHECK([./test/test-1],                          0, [expout])
83 AT_CHECK([(PATH=test$PATH_SEPARATOR$PATH; export PATH; exec test-1)],
84                                                    0, [expout])
85 AT_CHECK([sh ./test/test-1],                       0, [expout])
87 # Now using a disabled LINENO, with different call conventions.
88 AT_DATA_LINENO([test/test-2], [true], [__LINENO__], [LINENO])
89 AT_CHECK([./test/test-2],                          0, [expout])
90 AT_CHECK([(PATH=test$PATH_SEPARATOR$PATH; export PATH; exec test-2)],
91                                                    0, [expout])
92 AT_CHECK([sh ./test/test-2],                       0, [expout])
94 AT_CLEANUP
98 ## ------------ ##
99 ## AS_DIRNAME.  ##
100 ## ------------ ##
102 # Build nested dirs.
103 AT_SETUP([AS@&t@_DIRNAME])
105 AT_DATA_M4SH([script.as],
106 [[AS_INIT
108 # The EXPR variant is allowed to fail if `expr' was considered as too
109 # weak for us, in which case `as_expr=false'.
110 m4_define([DIRNAME_TEST],
111 [dir=`AS_DIRNAME([$1])`
112 test "$dir" = "$2" || (test -n "$3" && test "$dir" = "$3") ||
113   echo "dirname($1) = $dir instead of $2" >&2
115 if test "$as_expr" != false; then
116   dir=`_AS_DIRNAME_EXPR([$1])`
117   test "$dir" = "$2" || (test -n "$3" && test "$dir" = "$3") ||
118     echo "dirname_expr($1) = $dir instead of $2" >&2
121 dir=`_AS_DIRNAME_SED([$1])`
122 test "$dir" = "$2" || (test -n "$3" && test "$dir" = "$3") ||
123   echo "dirname_sed($1) = $dir instead of $2" >&2])
125 DIRNAME_TEST([/],               [/])
126 DIRNAME_TEST([//],              [//],   [/])
127 DIRNAME_TEST([///],             [/])
128 DIRNAME_TEST([//1],             [//],   [/])
129 DIRNAME_TEST([/1],              [/])
130 DIRNAME_TEST([./1],             [.])
131 DIRNAME_TEST([../../2],         [../..])
132 DIRNAME_TEST([//1/],            [//],   [/])
133 DIRNAME_TEST([/1/],             [/])
134 DIRNAME_TEST([./1/],            [.])
135 DIRNAME_TEST([../../2],         [../..])
136 DIRNAME_TEST([//1/3],           [//1])
137 DIRNAME_TEST([/1/3],            [/1])
138 DIRNAME_TEST([./1/3],           [./1])
139 DIRNAME_TEST([../../2/3],       [../../2])
140 DIRNAME_TEST([//1/3///],        [//1])
141 DIRNAME_TEST([/1/3///],         [/1])
142 DIRNAME_TEST([./1/3///],        [./1])
143 DIRNAME_TEST([../../2/3///],    [../../2])
144 DIRNAME_TEST([//1//3/],         [//1])
145 DIRNAME_TEST([/1//3/],          [/1])
146 DIRNAME_TEST([./1//3/],         [./1])
147 DIRNAME_TEST([../../2//3/],     [../../2])
148 AS_EXIT(0)
151 AT_CHECK_M4SH
152 AT_CHECK([./script])
154 AT_CLEANUP
158 ## --------- ##
159 ## AS_ECHO.  ##
160 ## --------- ##
162 # Build nested dirs.
163 AT_SETUP([AS@&t@_ECHO and AS@&t@_ECHO_N])
165 AT_DATA_M4SH([script.as],
166 [[AS_INIT
168 m4_define([ECHO_TEST],
169 [echo=`AS_ECHO(['$1'])`
170 test "X$echo" = 'X$1' ||
171   echo "AS@&t@_ECHO('"'$1'"') outputs '$echo'" >&2
173 echo=`AS_ECHO_N(['$1'])`
174 test "X$echo" = 'X$1' ||
175   echo "AS@&t@_ECHO_N('"'$1'"') outputs '$echo'" >&2])
177 ECHO_TEST([-])
178 ECHO_TEST([--])
179 ECHO_TEST([---...---])
180 ECHO_TEST([      ])
181 ECHO_TEST([-e])
182 ECHO_TEST([-E])
183 ECHO_TEST([-n])
184 ECHO_TEST([-n -n])
185 ECHO_TEST([-e -n])
186 ECHO_TEST([ab\ncd])
187 ECHO_TEST([abcd\c])
188 ECHO_TEST([\a\b\c\f\n\r\t\v\"\])
189 ECHO_TEST([ab
192 ECHO_TEST([
193  ])
194 ECHO_TEST([
195 \c])
196 AS_EXIT(0)
199 AT_CHECK_M4SH
200 AT_CHECK([./script])
202 AT_CLEANUP
206 ## ------------- ##
207 ## AS_BASENAME.  ##
208 ## ------------- ##
210 # Build nested dirs.
211 AT_SETUP([AS@&t@_BASENAME])
213 AT_DATA_M4SH([script.as],
214 [[AS_INIT
216 m4_define([BASENAME_TEST],
217 [base=`AS_BASENAME([$1])`
218 test "$base" = "$2" ||
219   echo "basename($1) = $base instead of $2" >&2
221 base=`_AS_BASENAME_SED([$1])`
222 test "$base" = "$2" ||
223   echo "basename_sed($1) = $base instead of $2" >&2])
225 BASENAME_TEST([//1],             [1])
226 BASENAME_TEST([/1],              [1])
227 BASENAME_TEST([./1],             [1])
228 BASENAME_TEST([../../2],         [2])
229 BASENAME_TEST([//1/],            [1])
230 BASENAME_TEST([/1/],             [1])
231 BASENAME_TEST([./1/],            [1])
232 BASENAME_TEST([../../2],         [2])
233 BASENAME_TEST([//1/3],           [3])
234 BASENAME_TEST([/1/3],            [3])
235 BASENAME_TEST([./1/3],           [3])
236 BASENAME_TEST([../../2/3],       [3])
237 BASENAME_TEST([//1/3///],        [3])
238 BASENAME_TEST([/1/3///],         [3])
239 BASENAME_TEST([./1/3///],        [3])
240 BASENAME_TEST([../../2/3///],    [3])
241 BASENAME_TEST([//1//3/],         [3])
242 BASENAME_TEST([/1//3/],          [3])
243 BASENAME_TEST([./1//3/],         [3])
244 BASENAME_TEST([a.c],             [a.c])
245 BASENAME_TEST([a.c/],            [a.c])
246 BASENAME_TEST([/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 BASENAME_TEST([./1/a.c],         [a.c])
252 BASENAME_TEST([./1/a.c/],        [a.c])
253 AS_EXIT(0)
256 AT_CHECK_M4SH
257 AT_CHECK([./script])
259 AT_CLEANUP
263 ## ------------ ##
264 ## AS_MKDIR_P.  ##
265 ## ------------ ##
267 # Build nested dirs.
268 AT_SETUP([AS@&t@_MKDIR_P])
270 AT_DATA_M4SH([script.as],
271 [[AS_INIT
273 pwd=`pwd`
274 set -e
275 # Absolute
276 AS_MKDIR_P(["$pwd/1/2/3/4/5/6"])
277 test -d "$pwd/1/2/3/4/5/6" ||
278   AS_ERROR([$pwd/1/2/3/4/5/6 has not been properly created])
279 # Relative
280 AS_MKDIR_P(["a/b/c/d/e/f"])
281 test -d a/b/c/d/e/f ||
282   AS_ERROR([a/b/c/d/e/f has not been properly created])
283 AS_EXIT(0)
286 AT_CHECK_M4SH
287 AT_CHECK([./script])
289 AT_CLEANUP
294 ## -------------------- ##
295 ## AS_VERSION_COMPARE.  ##
296 ## -------------------- ##
298 # Build nested dirs.
299 AT_SETUP([AS@&t@_VERSION_COMPARE])
301 AT_DATA_M4SH([script.as],
302 [[AS_INIT
304 m4_define([VERSION_COMPARE_TEST],
305 [AS_VERSION_COMPARE([$1], [$3], [result='<'], [result='='], [result='>'])
306 test "X$result" = "X$2" ||
307   AS_ERROR([version $1 $result $3; should be $1 $2 $3])
308 m4_if([$1], <,
309 [AS_VERSION_COMPARE([$3], [$1], [result='<'], [result='='], [result='>'])
310 test "X$result" = "X>" ||
311   AS_ERROR([version $3 $result $1; should be $3 > $1])])])
313 VERSION_COMPARE_TEST([], =, [])
314 VERSION_COMPARE_TEST([1.0], =, [1.0])
315 VERSION_COMPARE_TEST([alpha-1.0], =, [alpha-1.0])
317 # These tests are taken from libc/string/tst-svc.expect.
318 tst_svc_expect='
319   000 001 00 00a 01 01a 0 0a 2.8 2.8-0.4 20 21 22 212 CP037 CP345 CP1257
320   foo foo-0.4 foo-0.4a foo-0.4b foo-0.5 foo-0.10.5 foo-3.01 foo-3.0
321   foo-3.0.0 foo-3.0.1 foo-3.2 foo-3.10 foo00 foo0
323 test1=''
324 for test2 in $tst_svc_expect; do
325   VERSION_COMPARE_TEST([$test1], <, [$test2])
326   test1=$test2
327 done
329 AS_EXIT(0)
332 AT_CHECK_M4SH
333 AT_CHECK([./script])
335 AT_CLEANUP
340 ## ----------------------------- ##
341 ## Negated classes in globbing.  ##
342 ## ----------------------------- ##
344 # It is known that `[^...]' is not universally supported, but it is
345 # unknown for `[!...]'.
347 AT_SETUP([Negated classes in globbing])
349 AT_DATA_M4SH([script.as],
350 [[AS_INIT
352 case 'with!two!bangs' in
353   *[[!a-z]]*) ;;
354            *) AS_ERROR([[`*[!a-z]*' didn't match `with!two!bangs']]);;
355 esac
357 case without in
358   *[[!a-z]]*) AS_ERROR([[`*[!a-z]*' matched `without']]);;
359 esac
362 AT_CHECK_M4SH
363 AT_CHECK([./script])
365 AT_CLEANUP
370 ## ------------------- ##
371 ## Functions Support.  ##
372 ## ------------------- ##
374 # Hypothesis: the shell we are running, after having checked for
375 # $LINENO support, supports functions.
377 AT_SETUP([Functions Support])
379 AT_DATA_M4SH([script.as],
380 [[AS_INIT
381 _AS_LINENO_PREPARE
383 func_return () {
384   (exit $1)
387 func_success () {
388   func_return 0
391 func_failure () {
392   func_return 1
395 if func_success; then
396   if func_failure; then
397     AS_ERROR([func_failure passed])
398   fi
399 else
400   AS_ERROR([func_success failed])
404 AT_CHECK_M4SH
405 AT_CHECK([./script])
407 AT_CLEANUP
412 ## ------------------------------ ##
413 ## Functions and return Support.  ##
414 ## ------------------------------ ##
416 # Hypothesis: the shell we are running, after having checked for
417 # $LINENO support, supports functions, and the `return' keyword.
419 AT_SETUP([Functions and return Support])
421 AT_DATA_M4SH([script.as],
422 [[AS_INIT
423 _AS_LINENO_PREPARE
425 func_success () {
426   return 0
429 func_failure () {
430   return 1
433 if func_success; then
434   if func_failure; then
435     AS_ERROR([func_failure passed])
436   fi
437 else
438   AS_ERROR([func_success failed])
442 AT_CHECK_M4SH
443 AT_CHECK([./script])
445 AT_CLEANUP
448 ## ------------------------------------ ##
449 ## AS_REQUIRE_SHELL_FN and m4_require.  ##
450 ## ------------------------------------ ##
452 # Hypothesis: M4sh expands the requirements of AS_REQUIRE_SHELL_FN
453 # in the main diversion, and not in M4SH-INIT.
455 AT_SETUP([AS@&t@_REQUIRE_SHELL_FN and m4@&t@_require])
457 AT_DATA_M4SH([script.as], [[dnl
458 AS_INIT
460 m4_defun([in_m4_sh_init], still_in_m4sh_init=yes)
461 m4_defun([not_in_m4_sh_init], still_in_m4sh_init=no)
463 m4_defun([error_if_emitted_in_m4sh_init], [
464   if test x$still_in_m4sh_init = xyes; then
465     AS_ERROR([requirement emitted in M4SH-INIT])
466   fi
469 m4_defun([TEST_FUNC_BODY], [
470 m4_require([error_if_emitted_in_m4sh_init])
471 : echo in shell function, with parameter = [$]1
475 m4_defun([test_init], [
476 AS_REQUIRE([in_m4_sh_init])
477 AS_REQUIRE_SHELL_FN([test_func], [TEST_FUNC_BODY])
478 AS_REQUIRE([not_in_m4_sh_init])
481 test_init
482 test_func parameter1
485 AT_CHECK_M4SH
486 AT_CHECK([./script])
488 AT_CLEANUP
491 ## -------------- ##
492 ## AS_HELP_STRING ##
493 ## -------------- ##
495 AT_SETUP([AS@&t@_HELP_STRING])
496 AT_KEYWORDS([m4@&t@_text_wrap m4@&t@_expand])
498 AT_DATA_M4SH([script.as],
499 [[AS_INIT
500 _AS_LINENO_PREPARE
502 echo "AS_HELP_STRING([--an-option],[some text])"
503 echo "AS_HELP_STRING([--another-much-longer-option],
504 [some other text which should wrap at our default of 80 characters.])"
505 echo "AS_HELP_STRING([--fooT=barT], [foo bar])"
506 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@], [foo bar])"
507 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@123456789], [foo bar])"
508 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@1234567890], [foo bar])"
509 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@12345678901], [foo bar])"
510 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@123456789012], [foo bar])"
511 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@1234567890123], [foo bar])"
512 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@],
513 [some other text which should wrap at our default of 80 characters.])"
514 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@123456789],
515 [some other text which should wrap at our default of 80 characters.])"
516 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@1234567890],
517 [some other text which should wrap at our default of 80 characters.])"
518 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@12345678901],
519 [some other text which should wrap at our default of 80 characters.])"
520 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@123456789012],
521 [some other text which should wrap at our default of 80 characters.])"
522 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@1234567890123],
523 [some other text which should wrap at our default of 80 characters.])"
524 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@],
525 [some other @<][:@ex@:][>@ which should wrap at our default of 80 characters.])"
526 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@123456789],
527 [some other @<][:@ex@:][>@ which should wrap at our default of 80 characters.])"
528 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@1234567890],
529 [some other @<][:@ex@:][>@ which should wrap at our default of 80 characters.])"
530 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@12345678901],
531 [some other @<][:@ex@:][>@ which should wrap at our default of 80 characters.])"
532 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@123456789012],
533 [some other @<][:@ex@:][>@ which should wrap at our default of 80 characters.])"
534 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@1234567890123],
535 [some other @<][:@ex@:][>@ which should wrap at our default of 80 characters.])"
536 echo "AS_HELP_STRING([[--foo[=bar]]],
537 [some other t[]t which should wrap at our default of 80 characters.])"
538 echo "AS_HELP_STRING([[--foo[=bar]123456789]],
539 [some other t[]t which should wrap at our default of 80 characters.])"
540 echo "AS_HELP_STRING([[--foo[=bar]1234567890]],
541 [some other t[]t which should wrap at our default of 80 characters.])"
542 echo "AS_HELP_STRING([[--foo[=bar]12345678901]],
543 [some other t[]t which should wrap at our default of 80 characters.])"
544 echo "AS_HELP_STRING([[--foo[=bar]123456789012]],
545 [some other t[]t which should wrap at our default of 80 characters.])"
546 echo "AS_HELP_STRING([[--foo[=bar]1234567890123]],
547 [some other t[]t which should wrap at our default of 80 characters.])"
548 m4_define([mac], [MACRO])dnl
549 echo "AS_HELP_STRING([--mac], [mac])"
550 echo "AS_HELP_STRING([--o1, --o2], [two
551 options,        one  description])"
552 echo "AS_HELP_STRING([[[--o3, --o4]]], [comma inside literal quoting])"
553 echo "AS_HELP_STRING([--tune1], [check out the tuned formatting],
554 [            ])"
555 echo "AS_HELP_STRING([--tune2], [check out the tuned formatting],
556 [12])"
557 echo "AS_HELP_STRING([--tune3], [check out the tuned formatting],
558 [], [40])"
559 echo "AS_HELP_STRING([--tune4], [check out the tuned formatting],
560 [12], [40])"
563 AT_CHECK_M4SH
564 AT_CHECK([./script], [0],
565 [[  --an-option             some text
566   --another-much-longer-option
567                           some other text which should wrap at our default of
568                           80 characters.
569   --fooT=barT             foo bar
570   --foo[=bar]             foo bar
571   --foo[=bar]123456789    foo bar
572   --foo[=bar]1234567890   foo bar
573   --foo[=bar]12345678901  foo bar
574   --foo[=bar]123456789012 foo bar
575   --foo[=bar]1234567890123
576                           foo bar
577   --foo[=bar]             some other text which should wrap at our default of
578                           80 characters.
579   --foo[=bar]123456789    some other text which should wrap at our default of
580                           80 characters.
581   --foo[=bar]1234567890   some other text which should wrap at our default of
582                           80 characters.
583   --foo[=bar]12345678901  some other text which should wrap at our default of
584                           80 characters.
585   --foo[=bar]123456789012 some other text which should wrap at our default of
586                           80 characters.
587   --foo[=bar]1234567890123
588                           some other text which should wrap at our default of
589                           80 characters.
590   --foo[=bar]             some other [ex] which should wrap at our default of
591                           80 characters.
592   --foo[=bar]123456789    some other [ex] which should wrap at our default of
593                           80 characters.
594   --foo[=bar]1234567890   some other [ex] which should wrap at our default of
595                           80 characters.
596   --foo[=bar]12345678901  some other [ex] which should wrap at our default of
597                           80 characters.
598   --foo[=bar]123456789012 some other [ex] which should wrap at our default of
599                           80 characters.
600   --foo[=bar]1234567890123
601                           some other [ex] which should wrap at our default of
602                           80 characters.
603   --foo[=bar]             some other t[]t which should wrap at our default of
604                           80 characters.
605   --foo[=bar]123456789    some other t[]t which should wrap at our default of
606                           80 characters.
607   --foo[=bar]1234567890   some other t[]t which should wrap at our default of
608                           80 characters.
609   --foo[=bar]12345678901  some other t[]t which should wrap at our default of
610                           80 characters.
611   --foo[=bar]123456789012 some other t[]t which should wrap at our default of
612                           80 characters.
613   --foo[=bar]1234567890123
614                           some other t[]t which should wrap at our default of
615                           80 characters.
616   --MACRO                 mac
617   --o1, --o2              two options, one description
618   [--o3, --o4]            comma inside literal quoting
619   --tune1   check out the tuned formatting
620   --tune2   check out the tuned formatting
621   --tune3                 check out the
622                           tuned
623                           formatting
624   --tune4   check out the tuned
625             formatting
628 AT_CLEANUP
631 ## ------------------- ##
632 ## AS_IF and AS_CASE.  ##
633 ## ------------------- ##
635 AT_SETUP([AS@&t@_IF and AS@&t@_CASE])
637 AT_DATA_M4SH([script.as], [[dnl
638 AS_INIT
639 # Syntax checks: cope with empty arguments.
640 AS_IF([:], [], [echo wrong])
641 AS_IF([:], [echo one], [echo wrong])
642 AS_IF([false], [echo wrong], [echo two])
643 AS_IF([false], [echo wrong])
644 # n-ary version
645 AS_IF([false], [echo wrong],
646       [:], [echo three])
647 AS_IF([false], [echo wrong],
648       [:], [echo four],
649       [echo wrong])
650 AS_IF([false], [echo wrong],
651       [false], [echo wrong])
652 AS_IF([false], [echo wrong],
653       [false], [echo wrong],
654       [echo five])
655 AS_IF([false], [echo wrong],
656       [false], [echo wrong],
657       [:], [echo six],
658       [echo wrong])
659 AS_CASE([foo])
660 AS_CASE([foo], [echo seven])
661 AS_CASE([foo],
662         [foo], [echo eight],
663         [echo wrong])
664 AS_CASE([foo],
665         [foo], [echo nine],
666         [*],   [echo wrong])
667 AS_CASE([foo],
668         [bar], [echo wrong],
669         [foo], [echo ten],
670         [*],   [echo wrong])
672 # check that require works correctly
673 m4_for([n], 1, 9, [],
674 [m4_defun([FOO]n, [foo]n[=]n)dnl
675 m4_defun([BAR]n,
676          [m4_require([FOO]]n[)dnl
677 bar]n[=]n)[]dnl
680 AS_IF([:], [BAR1])
681 echo "foo1=$foo1 bar1=$bar1"
682 AS_IF([:], [], [BAR2])
683 echo "foo2=$foo2 bar2=$bar2"
684 AS_IF([false], [BAR3])
685 echo "foo3=$foo3 bar3=$bar3"
686 AS_IF([false], [], [BAR4])
687 echo "foo4=$foo4 bar4=$bar4"
688 AS_CASE([x], [x], [BAR5])
689 echo "foo5=$foo5 bar5=$bar5"
690 AS_CASE([x], [y], [BAR6])
691 echo "foo6=$foo6 bar6=$bar6"
692 AS_CASE([x],
693         [x], [:],
694         [BAR7])
695 echo "foo7=$foo7 bar7=$bar7"
696 AS_CASE([x],
697         [y], [:],
698         [BAR8])
699 echo "foo8=$foo8 bar8=$bar8"
700 AS_CASE([x],
701         [y], [:],
702         [x], [BAR9])
703 echo "foo9=$foo9 bar9=$bar9"
706 AT_CHECK_M4SH
707 AT_CHECK([./script], [0], [[one
709 three
710 four
711 five
713 seven
714 eight
715 nine
717 foo1=1 bar1=1
718 foo2=2 bar2=
719 foo3=3 bar3=
720 foo4=4 bar4=4
721 foo5=5 bar5=5
722 foo6=6 bar6=
723 foo7=7 bar7=
724 foo8=8 bar8=8
725 foo9=9 bar9=9
728 AT_CLEANUP
731 ## --------------- ##
732 ## AS_LITERAL_IF.  ##
733 ## --------------- ##
735 AT_SETUP([AS@&t@_LITERAL_IF])
737 AT_DATA_M4SH([script.as], [[dnl
738 AS_INIT
739 echo AS_LITERAL_IF([lit], [ok], [ERR]) 1
740 echo AS_LITERAL_IF([l$it], [ERR], [ok]) 2
741 echo AS_LITERAL_IF([l``it], [ERR], [ok]) 3
742 m4_define([mac], [lit])
743 echo AS_LITERAL_IF([mac], [ok], [ERR]) 4
744 echo AS_LITERAL_IF([mac($, ``)], [ok], [ERR]) 5
745 m4_define([mac], [l$it])
746 echo AS_LITERAL_IF([mac], [ERR], [ok]) 6
747 m4_define([mac], [l`it])
748 echo AS_LITERAL_IF([mac], [ERR], [ok]) 7
751 AT_CHECK_M4SH
752 AT_CHECK([./script], [],
753 [[ok 1
754 ok 2
755 ok 3
756 ok 4
757 ok 5
758 ok 6
759 ok 7
762 AT_CLEANUP
765 ## ----------------- ##
766 ## AS_INIT cleanup.  ##
767 ## ----------------- ##
769 AT_SETUP([AS@&t@_INIT cleanup])
771 AT_KEYWORDS([m4@&t@_wrap m4@&t@_wrap_lifo])
773 AT_DATA_M4SH([script.as], [[dnl
774 dnl Registered before AS_INIT's cleanups
775 m4_wrap([echo cleanup 1
777 AS_INIT
778 dnl Registered after AS_INIT's cleanups, thus goes to KILL diversion
779 m4_wrap([echo cleanup 2
780 dnl However, nested wraps and diversions can still be used
781 dnl Also, test wrapping text that looks like parameter reference
782 m4_wrap([echo cleanup 3
783 m4_divert_text([M4SH-INIT], [m4_define([foo], [$1])dnl
784 echo prep foo([4])
785 ])])])
786 dnl Registered before AS_INIT's cleanups
787 m4_wrap_lifo([echo cleanup 5
789 echo body
792 AT_CHECK_M4SH
793 AT_CHECK([./script], [], [[prep 4
794 body
795 cleanup 5
796 cleanup 1
799 AT_CLEANUP