maint: update copyright year
[autoconf.git] / tests / m4sh.at
bloba5ef905b638ff89c851e500286f77c8081fef59d
1 #                                                       -*- Autotest -*-
3 AT_BANNER([M4sh.])
5 # Copyright (C) 2000-2011 Free Software Foundation, Inc.
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
20 ## ------------------- ##
21 ## AS_WARN, AS_ERROR.  ##
22 ## ------------------- ##
24 AT_SETUP([AS@&t@_WARN and AS@&t@_ERROR])
25 AT_KEYWORDS([m4sh])
27 dnl without logging
28 AT_DATA_M4SH([script.as],
29 [[AS_INIT
30 AS_WARN([*watch out*])dnl
32 if test x"$die" != x; then
33   AS_ERROR([you're dead])dnl
35   AS_ERROR([really])dnl
38 echo got here
39 ]])
41 AT_CHECK_M4SH
42 AT_CHECK([$CONFIG_SHELL ./script], [],
43 [[got here
44 ]], [[script: WARNING: *watch out*
45 ]])
46 AT_CHECK([die=: $CONFIG_SHELL ./script], [1],
47 [], [[script: WARNING: *watch out*
48 script: error: you're dead
49 ]])
51 dnl with logging
52 rm script
53 AT_DATA_M4SH([script.as],
54 [[AS_INIT
55 m4_define([gone], [AS_ERROR([really])])
56 m4_define([AS_MESSAGE_LOG_FD], [5])
57 exec AS_MESSAGE_LOG_FD>log.txt
58 AS_WARN([*watch out*])dnl
60 if test x"$die" != x; then
61   AS_ERROR([you're dead])dnl
63   AS_ERROR([really])dnl
66 echo got here
67 exec AS_MESSAGE_LOG_FD>&-
68 ]])
70 AT_CHECK_M4SH
71 AT_CHECK([$CONFIG_SHELL ./script], [],
72 [[got here
73 ]], [[script: WARNING: *watch out*
74 ]])
75 AT_CHECK([[grep 'script:[0-9]*: WARNING: \*watch out\*' log.txt]], [], [ignore])
76 AT_CHECK([die=: $CONFIG_SHELL ./script], [1],
77 [], [[script: WARNING: *watch out*
78 script: error: you're dead
79 ]])
80 AT_CHECK([[grep 'script:[0-9]*: WARNING: \*watch out\*' log.txt]], [], [ignore])
81 AT_CHECK([[grep 'script:[0-9]*: error: you'\''re dead' log.txt]], [], [ignore])
83 AT_CLEANUP
85 ## ---------------- ##
86 ## LINENO support.  ##
87 ## ---------------- ##
89 AT_SETUP([LINENO])
90 AT_KEYWORDS([m4sh])
92 # We cannot unset LINENO with Zsh, yet this test case relies on
93 # unsetting LINENO to compare its result when (i) LINENO is supported
94 # and when (ii) it is not.
95 # So just skip if the shell is ZSH.
96 AT_CHECK([test -n "${ZSH_VERSION+set}" && exit 77], ignore)
98 # AT_DATA_LINENO(FILE-NAME,
99 #                UNSET-LINENO = true | false, COUNTER, COUNTER-RE)
100 # ----------------------------------------------------------------
101 # Produce the FILE-NAME M4sh script which uses the COUNTER LINENO or
102 # _oline_, which we can recognized via COUNTER-RE.  Unset LINENO is
103 # UNSET-LINENO.
105 # Use COUNTER, COUNTER-RE = [__LINENO__], [LINENO]
106 #  or                     = [__OLINE__],  [_oline__]
108 # instead of the obvious $LINENO and __oline__, because they would
109 # be replaced in the test suite itself, even before creating these
110 # scripts.  For the same reason, grep for LINENO and _oline__ (sic).
112 # UNSET-LINENO is a shell condition to make sure the scripts have the
113 # same number of lines in the output, so that their outputs be identical.
114 m4_define([AT_DATA_LINENO],
115 [AT_DATA([$1.tas],
116 [[AS@&t@_INIT
117 m4@&t@_divert_text([], [
118 if $2; then
119   AS@&t@_UNSET([LINENO])
122 AS@&t@_LINENO_PREPARE
123 echo "Line: $3"
124 grep 'Line: .*$4' "$[0]" >/dev/null ||
125   AS@&t@_ERROR([cannot find original script])
126 exit 0
128 # If occurrences of $LINENO or __@&t@oline__ were wanted, create them.
129 sed 's/__LINENO__/$''LINENO/g;s/__OLINE__/__''oline__/g' $1.tas >$1.as
130 AT_CHECK([autom4te -l m4sh $1.as -o $1])
131 ])# AT_DATA_LINENO
133 # `_oline_', once processed and ran, produces our reference.
134 # We check that we find ourselves by looking at a string which is
135 # available only in the original script: `_oline_'.
136 AT_DATA_LINENO([reference], [false], [__OLINE__], [_oline__])
137 AT_CHECK([./reference], 0, [stdout])
139 # The reference:
140 mv stdout expout
142 # Now using a maybe-functioning LINENO, with different call conventions.
143 # Be sure to be out of the PATH.
144 AT_CHECK([mkdir test || exit 77])
146 AT_DATA_LINENO([test/test-1], [false], [__LINENO__], [LINENO])
147 AT_CHECK([./test/test-1],                          0, [expout])
148 AT_CHECK([(PATH=test$PATH_SEPARATOR$PATH; export PATH; exec test-1)],
149                                                    0, [expout])
150 AT_CHECK([sh ./test/test-1],                       0, [expout])
152 # Now using a disabled LINENO, with different call conventions.
153 AT_DATA_LINENO([test/test-2], [true], [__LINENO__], [LINENO])
154 AT_CHECK([./test/test-2],                          0, [expout])
155 AT_CHECK([(PATH=test$PATH_SEPARATOR$PATH; export PATH; exec test-2)],
156                                                    0, [expout])
157 AT_CHECK([sh ./test/test-2],                       0, [expout])
159 AT_CLEANUP
162 ## ---------------------- ##
163 ## LINENO stack support.  ##
164 ## ---------------------- ##
166 AT_SETUP([LINENO stack])
167 AT_KEYWORDS([m4sh])
169 AT_DATA_M4SH([script.as],
170 [[AS_INIT
172 AS_LINENO_PUSH([9999])
173 test $as_lineno = 9999 || AS_ERROR([bad as_lineno at depth 1])
174 AS_LINENO_PUSH([8888])
175 test $as_lineno = 9999 || AS_ERROR([bad as_lineno at depth 2])
176 AS_LINENO_POP
177 test $as_lineno = 9999 || AS_ERROR([bad as_lineno at depth 1])
178 AS_LINENO_POP
179 test x${as_lineno+set} = xset && AS_ERROR([as_lineno set at depth 0])
181 AS_EXIT([0])
184 AT_CHECK_M4SH
185 AT_CHECK([$CONFIG_SHELL ./script])
187 AT_CLEANUP
190 ## -------- ##
191 ## AS_BOX.  ##
192 ## -------- ##
194 # Output a framed one-line message.
195 AT_SETUP([AS@&t@_BOX])
196 AT_KEYWORDS([m4sh])
198 AT_DATA_M4SH([script.as],
199 [[AS_INIT
200 echo
201 AS_BOX([Send a simple message, to foobar@example.com])
202 AS_BOX([Send a simple message, to foobar@example.com], [$])
203 m4_define([msg], [$complex])
204 complex='Not quite as simple |$[1]'
205 AS_BOX([msg])
206 AS_BOX([msg], [,])
207 AS_EXIT(0)
210 AT_CHECK_M4SH
211 AT_CHECK([sed -n '/ -\{44\} /,/ -\{44\} /p' script ]dnl
212 [| sed '1 s/.*## -/## -/; 3 s/- ##.*/- ##/'], [],
213 [[## -------------------------------------------- ##
214 ## Send a simple message, to foobar@example.com ##
215 ## -------------------------------------------- ##
218 AT_CHECK([$CONFIG_SHELL ./script], [], [[
219 ## -------------------------------------------- ##
220 ## Send a simple message, to foobar@example.com ##
221 ## -------------------------------------------- ##
222 ## $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ ##
223 ## Send a simple message, to foobar@example.com ##
224 ## $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ ##
225 ## ----------------------- ##
226 ## Not quite as simple |$1 ##
227 ## ----------------------- ##
228 ## ,,,,,,,,,,,,,,,,,,,,,,, ##
229 ## Not quite as simple |$1 ##
230 ## ,,,,,,,,,,,,,,,,,,,,,,, ##
233 AT_CLEANUP
236 # Strip path from file.
237 AT_SETUP([AS@&t@_BASENAME])
238 AT_KEYWORDS([m4sh])
240 AT_DATA_M4SH([script.as],
241 [[AS_INIT
243 m4_define([BASENAME_TEST],
244 [base=`AS_BASENAME([$1])`
245 test "$base" = "$2" ||
246   echo "basename($1) = $base instead of $2" >&2
248 base=`_AS_BASENAME_SED([$1])`
249 test "$base" = "$2" ||
250   echo "basename_sed($1) = $base instead of $2" >&2])
252 BASENAME_TEST([//1],             [1])
253 BASENAME_TEST([/1],              [1])
254 BASENAME_TEST([./1],             [1])
255 BASENAME_TEST([../../2],         [2])
256 BASENAME_TEST([//1/],            [1])
257 BASENAME_TEST([/1/],             [1])
258 BASENAME_TEST([./1/],            [1])
259 BASENAME_TEST([../../2],         [2])
260 BASENAME_TEST([//1/3],           [3])
261 BASENAME_TEST([/1/3],            [3])
262 BASENAME_TEST([./1/3],           [3])
263 BASENAME_TEST([../../2/3],       [3])
264 BASENAME_TEST([//1/3///],        [3])
265 BASENAME_TEST([/1/3///],         [3])
266 BASENAME_TEST([./1/3///],        [3])
267 BASENAME_TEST([../../2/3///],    [3])
268 BASENAME_TEST([//1//3/],         [3])
269 BASENAME_TEST([/1//3/],          [3])
270 BASENAME_TEST([./1//3/],         [3])
271 BASENAME_TEST([a.c],             [a.c])
272 BASENAME_TEST([a.c/],            [a.c])
273 BASENAME_TEST([/a.c/],           [a.c])
274 BASENAME_TEST([/1/a.c],          [a.c])
275 BASENAME_TEST([/1/a.c/],         [a.c])
276 BASENAME_TEST([/1/../a.c],       [a.c])
277 BASENAME_TEST([/1/../a.c/],      [a.c])
278 BASENAME_TEST([./1/a.c],         [a.c])
279 BASENAME_TEST([./1/a.c/],        [a.c])
280 AS_EXIT(0)
283 AT_CHECK_M4SH
284 AT_CHECK([$CONFIG_SHELL ./script])
286 AT_CLEANUP
289 ## ------------ ##
290 ## AS_DIRNAME.  ##
291 ## ------------ ##
293 # Strip filename component.
294 AT_SETUP([AS@&t@_DIRNAME])
295 AT_KEYWORDS([m4sh])
297 AT_DATA_M4SH([script.as],
298 [[AS_INIT
300 # The EXPR variant is allowed to fail if `expr' was considered as too
301 # weak for us, in which case `as_expr=false'.
302 m4_define([DIRNAME_TEST],
303 [dir=`AS_DIRNAME([$1])`
304 test "$dir" = "$2" || (test -n "$3" && test "$dir" = "$3") ||
305   echo "dirname($1) = $dir instead of $2" >&2
307 if test "$as_expr" != false; then
308   dir=`_AS_DIRNAME_EXPR([$1])`
309   test "$dir" = "$2" || (test -n "$3" && test "$dir" = "$3") ||
310     echo "dirname_expr($1) = $dir instead of $2" >&2
313 dir=`_AS_DIRNAME_SED([$1])`
314 test "$dir" = "$2" || (test -n "$3" && test "$dir" = "$3") ||
315   echo "dirname_sed($1) = $dir instead of $2" >&2])
317 DIRNAME_TEST([/],               [/])
318 DIRNAME_TEST([//],              [//],   [/])
319 DIRNAME_TEST([///],             [/])
320 DIRNAME_TEST([//1],             [//],   [/])
321 DIRNAME_TEST([/1],              [/])
322 DIRNAME_TEST([./1],             [.])
323 DIRNAME_TEST([../../2],         [../..])
324 DIRNAME_TEST([//1/],            [//],   [/])
325 DIRNAME_TEST([/1/],             [/])
326 DIRNAME_TEST([./1/],            [.])
327 DIRNAME_TEST([../../2],         [../..])
328 DIRNAME_TEST([//1/3],           [//1])
329 DIRNAME_TEST([/1/3],            [/1])
330 DIRNAME_TEST([./1/3],           [./1])
331 DIRNAME_TEST([../../2/3],       [../../2])
332 DIRNAME_TEST([//1/3///],        [//1])
333 DIRNAME_TEST([/1/3///],         [/1])
334 DIRNAME_TEST([./1/3///],        [./1])
335 DIRNAME_TEST([../../2/3///],    [../../2])
336 DIRNAME_TEST([//1//3/],         [//1])
337 DIRNAME_TEST([/1//3/],          [/1])
338 DIRNAME_TEST([./1//3/],         [./1])
339 DIRNAME_TEST([../../2//3/],     [../../2])
340 AS_EXIT(0)
343 AT_CHECK_M4SH
344 AT_CHECK([$CONFIG_SHELL ./script])
346 AT_CLEANUP
349 ## ---------------- ##
350 ## AS_SET_CATFILE.  ##
351 ## ---------------- ##
353 AT_SETUP([AS@&t@_SET_CATFILE])
354 AT_KEYWORDS([m4sh])
356 AT_DATA_M4SH([script.as],
357 [[AS_INIT
359 # CATFILE_TEST(DIR, FILE, EXPECTED)
360 m4_define([CATFILE_TEST],
361 [# AS_SET_CATFILE works and can be used in a compound list.
362 if AS_SET_CATFILE([var], [$1], [$2]) \
363    && test "$var" = $3; then :; else
364   echo "catfile($1, $2) = $var != $3" >&2
366 # AS_SET_CATFILE can use non-literals in its arguments.
367 varname=var2
368 dirpart=$1
369 filepart=$2
370 if AS_SET_CATFILE([$varname], [$dirpart], [$filepart]) \
371    && test "$var2" = $3; then :; else
372   echo "catfile($dirpart, $filepart) = $var2 != $3" >&2
376 CATFILE_TEST([dir], [file], [dir/file])
377 CATFILE_TEST([.], [file], [file])
378 CATFILE_TEST([dir], [.], [dir])
379 CATFILE_TEST([dir], [/abs/file], [/abs/file])
380 CATFILE_TEST([dir], [C:/abs/file], [C:/abs/file])
381 CATFILE_TEST(["dir  name"], ['file  name'], ['dir  name/file  name'])
383 AS_EXIT(0)
386 AT_CHECK_M4SH
387 AT_CHECK([$CONFIG_SHELL ./script])
389 AT_CLEANUP
392 ## --------- ##
393 ## AS_ECHO.  ##
394 ## --------- ##
396 # Print literal strings, with/without newline.
397 AT_SETUP([AS@&t@_ECHO and AS@&t@_ECHO_N])
398 AT_KEYWORDS([m4sh])
400 AT_DATA_M4SH([script.as],
401 [[AS_INIT
403 m4_define([ECHO_TEST],
404 [echo=`AS_ECHO(['$1'])`
405 test "X$echo" = 'X$1' ||
406   echo "AS@&t@_ECHO('"'$1'"') outputs '$echo'" >&2
408 echo=`AS_ECHO_N(['$1'])`
409 test "X$echo" = 'X$1' ||
410   echo "AS@&t@_ECHO_N('"'$1'"') outputs '$echo'" >&2])
412 ECHO_TEST([-])
413 ECHO_TEST([--])
414 ECHO_TEST([---...---])
415 ECHO_TEST([      ])
416 ECHO_TEST([-e])
417 ECHO_TEST([-E])
418 ECHO_TEST([-n])
419 ECHO_TEST([-n -n])
420 ECHO_TEST([-e -n])
421 ECHO_TEST([ab\ncd])
422 ECHO_TEST([abcd\c])
423 ECHO_TEST([\a\b\c\f\n\r\t\v\"\])
424 ECHO_TEST([ab
427 ECHO_TEST([
428  ])
429 ECHO_TEST([
430 \c])
431 AS_EXIT(0)
434 AT_CHECK_M4SH
435 AT_CHECK([$CONFIG_SHELL ./script])
437 AT_CLEANUP
441 ## --------- ##
442 ## AS_EXIT.  ##
443 ## --------- ##
445 # Exit scripts with given status.
446 AT_SETUP([AS@&t@_EXIT])
447 AT_KEYWORDS([m4sh AS@&t@_SET_STATUS])
449 AT_DATA_M4SH([script.as],
450 [[AS_INIT
451 test x${1} = xa && AS_EXIT
452 test x${1} = xb && AS_EXIT([${2}])
453 test x${1} = xc && { AS_SET_STATUS([${2}]); AS_EXIT; }
454 test x${1} = xd && trap 's=$?; echo $s; AS_EXIT([$s])' 0
455 test x${2} = xe && set -e
456 test $[#] -gt 0 || AS_EXIT
457 AS_SET_STATUS([3])
458 dnl Solaris /bin/sh 'set -e' doesn't react to failed function calls
459 test x${2} = xe \
460   && { echo 'skipping rest of test: set -e support is lousy'; exit 77; }
461 AS_SET_STATUS([4])
464 AT_CHECK_M4SH
465 AT_CHECK([$CONFIG_SHELL ./script], [1])
466 AT_CHECK([$CONFIG_SHELL ./script ''], [4])
467 AT_CHECK([$CONFIG_SHELL ./script a], [0])
468 AT_CHECK([$CONFIG_SHELL ./script b], [0])
469 AT_CHECK([$CONFIG_SHELL ./script b 0], [0])
470 AT_CHECK([$CONFIG_SHELL ./script b 2], [2])
471 AT_CHECK([$CONFIG_SHELL ./script c 0], [0])
472 AT_CHECK([$CONFIG_SHELL ./script c 2], [2])
473 AT_CHECK([$CONFIG_SHELL ./script d], [4], [[4
475 dnl If we got to this point without a FAIL, then AS_EXIT at least works.
476 dnl The rest of this test relies on semi-decent 'set -e' support, even
477 dnl though m4sh in general should not try to rely on it because of
478 dnl portability nightmares on what constructs are considered errors across
479 dnl various shells; therefore, an overall SKIP result is desirable on
480 dnl broken shells like Solaris /bin/sh.
481 AT_CHECK([$CONFIG_SHELL ./script '' e], [3])
482 AT_CHECK([$CONFIG_SHELL ./script d e], [3], [stdout])
483 dnl NetBSD sh fails to output on stderr here.
484 AT_CHECK([grep 3 stdout || exit 77], [], [ignore])
486 AT_CLEANUP
490 ## ------------ ##
491 ## AS_MKDIR_P.  ##
492 ## ------------ ##
494 # Build nested dirs.
495 AT_SETUP([AS@&t@_MKDIR_P])
496 AT_KEYWORDS([m4sh])
498 AT_DATA_M4SH([script.as],
499 [[AS_INIT
501 pwd=`pwd`
502 set -e
503 # Absolute
504 AS_MKDIR_P(["$pwd/1/2/3/4/5/6"])
505 test -d "$pwd/1/2/3/4/5/6" ||
506   AS_ERROR([$pwd/1/2/3/4/5/6 has not been properly created])
507 # Relative
508 AS_MKDIR_P(["a/b/c/d/e/f"])
509 test -d a/b/c/d/e/f ||
510   AS_ERROR([a/b/c/d/e/f has not been properly created])
511 AS_EXIT(0)
514 AT_CHECK_M4SH
515 AT_CHECK([$CONFIG_SHELL ./script])
517 AT_CLEANUP
522 ## -------------------- ##
523 ## AS_VERSION_COMPARE.  ##
524 ## -------------------- ##
526 # Three-way version comparison.
527 AT_SETUP([AS@&t@_VERSION_COMPARE])
528 AT_KEYWORDS([m4sh])
530 AT_DATA_M4SH([script.as],
531 [[AS_INIT
533 m4_define([VERSION_COMPARE_TEST],
534 [AS_VERSION_COMPARE([$1], [$3], [result='<'], [result='='], [result='>'])
535 test "X$result" = "X$2" ||
536   AS_ERROR([version $1 $result $3; should be $1 $2 $3])
537 m4_if([$1], <,
538 [AS_VERSION_COMPARE([$3], [$1], [result='<'], [result='='], [result='>'])
539 test "X$result" = "X>" ||
540   AS_ERROR([version $3 $result $1; should be $3 > $1])])])
542 VERSION_COMPARE_TEST([], =, [])
543 VERSION_COMPARE_TEST([1.0], =, [1.0])
544 VERSION_COMPARE_TEST([alpha-1.0], =, [alpha-1.0])
546 # These tests are taken from libc/string/tst-svc.expect.
547 tst_svc_expect='
548   000 001 00 00a 01 01a 0 0a 2.8 2.8-0.4 20 21 22 212 CP037 CP345 CP1257
549   foo foo-0.4 foo-0.4a foo-0.4b foo-0.5 foo-0.10.5 foo-3.01 foo-3.0
550   foo-3.0.0 foo-3.0.1 foo-3.2 foo-3.10 foo00 foo0
552 test1=''
553 for test2 in $tst_svc_expect; do
554   VERSION_COMPARE_TEST([$test1], <, [$test2])
555   test1=$test2
556 done
558 AS_EXIT(0)
561 AT_CHECK_M4SH
562 AT_CHECK([$CONFIG_SHELL ./script])
564 AT_CLEANUP
569 ## ------- ##
570 ## as_me.  ##
571 ## ------- ##
573 AT_SETUP([as_me])
574 AT_KEYWORDS([m4sh])
576 AT_DATA_M4SH([script.as],
577 [[AS_INIT
578 AS_ME_PREPARE
579 test "$as_me" = script || AS_ECHO([["incorrect value of \$as_me: $as_me"]])
582 AT_CHECK_M4SH
583 AT_CHECK([$CONFIG_SHELL ./script])
585 AT_CLEANUP
590 ## ----------------------------- ##
591 ## Negated classes in globbing.  ##
592 ## ----------------------------- ##
594 # According to http://www.in-ulm.de/~mascheck/bourne/, all shells with
595 # functions also support `[!...]'.  But `[^...]' is not universally supported.
597 AT_SETUP([Negated classes in globbing])
598 AT_KEYWORDS([m4sh])
600 AT_DATA_M4SH([script.as],
601 [[AS_INIT
603 case 'with!two!bangs' in
604   *[[!a-z]]*) ;;
605            *) AS_ERROR([[`*[!a-z]*' didn't match `with!two!bangs']]);;
606 esac
608 case without in
609   *[[!a-z]]*) AS_ERROR([[`*[!a-z]*' matched `without']]);;
610 esac
613 AT_CHECK_M4SH
614 AT_CHECK([$CONFIG_SHELL ./script])
616 AT_CLEANUP
618 ## ---------------------------- ##
619 ## Null variable substitution.  ##
620 ## ---------------------------- ##
622 # According to http://www.in-ulm.de/~mascheck/bourne/, all shells with
623 # functions also support `${a:-b}'.
625 AT_SETUP([Null variable substitution])
626 AT_KEYWORDS([m4sh])
628 AT_DATA_M4SH([script.as],
629 [[AS_INIT
631 AS_UNSET([a])
634 case ${a:-x}${b:-y}${c:-z} in
635   xy.) ;;
636   *) exit 1 ;;
637 esac
638 case ${a-x}${b-y}${c-z} in
639   x.) ;;
640   *) exit 2 ;;
641 esac
643 case ${a+x}${b+y}${c+z} in
644   yz) ;;
645   *) exit 3 ;;
646 esac
647 case ${a:+x}${b:+y}${c:+z} in
648   z) ;;
649   *) exit 4 ;;
650 esac
652 case ${a=x}${b=y}${c=z} in
653   x.) ;;
654   *) exit 5 ;;
655 esac
656 AS_UNSET([a])
657 case ${a:=x}${b:=y}${c:=z} in
658   xy.) ;;
659   *) exit 6 ;;
660 esac
661 case $a$b$c in
662   xy.) ;;
663   *) exit 7 ;;
664 esac
665 AS_UNSET([a])
668 (: ${a?oops}; echo fail) 2>err && exit 8
669 grep oops err >/dev/null || exit 9
670 test "${b?oops}" = '' || exit 10
671 test "${c?oops}" = . || exit 11
672 (: ${a:?oops}; echo fail) 2>err && exit 12
673 grep oops err >/dev/null || exit 13
674 (: ${b:?oops}; echo fail) 2>err && exit 14
675 grep oops err >/dev/null || exit 15
676 test "${c:?oops}" = . || exit 16
679 AT_CHECK_M4SH
680 AT_CHECK([$CONFIG_SHELL ./script])
682 AT_CLEANUP
685 ## ------------------- ##
686 ## Functions Support.  ##
687 ## ------------------- ##
689 # All m4sh scripts require function support.
691 AT_SETUP([Functions Support])
692 AT_KEYWORDS([m4sh])
694 AT_DATA_M4SH([script.as],
695 [[AS_INIT
696 AS_LINENO_PREPARE
698 func_return () {
699   (exit $1)
702 func_success () {
703   func_return 0
706 func_failure () {
707   func_return 1
710 if func_success; then
711   if func_failure; then
712     AS_ERROR([func_failure passed])
713   fi
714 else
715   AS_ERROR([func_success failed])
719 AT_CHECK_M4SH
720 AT_CHECK([$CONFIG_SHELL ./script])
722 AT_CLEANUP
727 ## ------------------------------ ##
728 ## Functions and return Support.  ##
729 ## ------------------------------ ##
731 # All m4sh scripts require working return within functions.
733 AT_SETUP([Functions and return Support])
734 AT_KEYWORDS([m4sh])
736 AT_DATA_M4SH([script.as],
737 [[AS_INIT
738 AS_LINENO_PREPARE
740 func_success () {
741   return 0
744 func_failure () {
745   return 1
748 if func_success; then
749   if func_failure; then
750     AS_ERROR([func_failure passed])
751   fi
752 else
753   AS_ERROR([func_success failed])
757 AT_CHECK_M4SH
758 AT_CHECK([$CONFIG_SHELL ./script])
760 AT_CLEANUP
763 ## --------------------------- ##
764 ## Nested AS_REQUIRE_SHELL_FN. ##
765 ## --------------------------- ##
767 # Hypothesis: M4sh expands nested AS_REQUIRE_SHELL_FN
768 # separately.
770 AT_SETUP([Nested AS@&t@_REQUIRE_SHELL_FN])
771 AT_KEYWORDS([m4sh])
773 AT_DATA_M4SH([script.as], [[dnl
774 m4_define([INIT], [oops])dnl
775 AS_INIT
777 m4_defun([TEST_FUNC2_BODY], [
781 m4_defun([TEST_FUNC1_BODY], [
782 AS_REQUIRE_SHELL_FN([test_func2], [], [TEST_FUNC2_BODY])
786 AS_REQUIRE_SHELL_FN([test_func1], [], [TEST_FUNC1_BODY])
787 test_func2
790 AT_CHECK_M4SH
791 AT_CHECK([$CONFIG_SHELL ./script])
793 AT_CLEANUP
796 ## ------------------- ##
797 ## Nested AS_REQUIRE.  ##
798 ## ------------------- ##
800 # Hypothesis: M4sh expands the requirements of AS_REQUIRE in the
801 # requested diversion, even if other AS_REQUIREs are interleaved.
803 AT_SETUP([Nested AS@&t@_REQUIRE])
804 AT_KEYWORDS([m4sh])
806 AT_DATA_M4SH([script.as], [[dnl
807 AS_INIT
809 m4_defun([in_fn_diversion], still_in_m4sh_init_fn=yes)
810 m4_defun([not_in_fn_diversion], still_in_m4sh_init_fn=no)
812 m4_defun([NESTED], [nested_require_in_fn_diversion=$still_in_m4sh_init_fn])
814 m4_defun([OUTER], [AS_REQUIRE([NESTED])dnl
815 outer_require_in_fn_diversion=$still_in_m4sh_init_fn])
817 m4_defun([test_init], [
818 AS_REQUIRE([in_fn_diversion], , [M4SH-INIT-FN])
819 AS_REQUIRE([OUTER], , [M4SH-INIT-FN])
820 AS_REQUIRE([not_in_fn_diversion], , [M4SH-INIT-FN])
823 test_init
824 if test $outer_require_in_fn_diversion != yes; then AS_EXIT([1]); fi
825 if test $nested_require_in_fn_diversion != no; then AS_EXIT([1]); fi
828 AT_CHECK_M4SH
829 AT_CHECK([$CONFIG_SHELL ./script])
831 AT_CLEANUP
834 ## ------------------------------------ ##
835 ## AS_REQUIRE_SHELL_FN and m4_require.  ##
836 ## ------------------------------------ ##
838 # Hypothesis: M4sh expands the requirements of AS_REQUIRE_SHELL_FN
839 # in M4SH-INIT-FN.  This changed after Autoconf 2.63.
841 AT_SETUP([AS@&t@_REQUIRE_SHELL_FN and m4@&t@_require])
842 AT_KEYWORDS([m4sh])
844 AT_DATA_M4SH([script.as], [[dnl
845 AS_INIT
847 m4_defun([in_m4_sh_init], still_in_m4sh_init=yes)
848 m4_defun([not_in_m4_sh_init], still_in_m4sh_init=no)
850 m4_defun([error_if_emitted_in_m4sh_init], [
851   if test x$still_in_m4sh_init = xyes; then
852     AS_ERROR([requirement emitted in M4SH-INIT])
853   fi
856 m4_defun([TEST_FUNC_BODY], [
857 m4_require([error_if_emitted_in_m4sh_init])
858 : echo in shell function, with parameter = [$]1
862 m4_defun([test_init], [
863 AS_REQUIRE([in_m4_sh_init], , [M4SH-INIT-FN])
864 AS_REQUIRE_SHELL_FN([test_func], [], [TEST_FUNC_BODY])
865 AS_REQUIRE([not_in_m4_sh_init])
868 test_init
869 test_func parameter1
872 AT_CHECK_M4SH
873 AT_CHECK([$CONFIG_SHELL ./script])
875 AT_CLEANUP
878 ## -------------- ##
879 ## AS_HELP_STRING ##
880 ## -------------- ##
882 AT_SETUP([AS@&t@_HELP_STRING])
883 AT_KEYWORDS([m4sh m4@&t@_text_wrap m4@&t@_expand])
885 AT_DATA_M4SH([script.as],
886 [[AS_INIT
888 echo "AS_HELP_STRING([--an-option],[some text])"
889 echo "AS_HELP_STRING([--another-much-longer-option],
890 [some other text which should wrap at our default of 80 characters.])"
891 echo "AS_HELP_STRING([--fooT=barT], [foo bar])"
892 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@], [foo bar])"
893 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@123456789], [foo bar])"
894 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@1234567890], [foo bar])"
895 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@12345678901], [foo bar])"
896 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@123456789012], [foo bar])"
897 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@1234567890123], [foo bar])"
898 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@],
899 [some other text which should wrap at our default of 80 characters.])"
900 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@123456789],
901 [some other text which should wrap at our default of 80 characters.])"
902 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@1234567890],
903 [some other text which should wrap at our default of 80 characters.])"
904 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@12345678901],
905 [some other text which should wrap at our default of 80 characters.])"
906 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@123456789012],
907 [some other text which should wrap at our default of 80 characters.])"
908 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@1234567890123],
909 [some other text which should wrap at our default of 80 characters.])"
910 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@],
911 [some other @<][:@ex@:][>@ which should wrap at our default of 80 characters.])"
912 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@123456789],
913 [some other @<][:@ex@:][>@ which should wrap at our default of 80 characters.])"
914 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@1234567890],
915 [some other @<][:@ex@:][>@ which should wrap at our default of 80 characters.])"
916 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@12345678901],
917 [some other @<][:@ex@:][>@ which should wrap at our default of 80 characters.])"
918 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@123456789012],
919 [some other @<][:@ex@:][>@ which should wrap at our default of 80 characters.])"
920 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@1234567890123],
921 [some other @<][:@ex@:][>@ which should wrap at our default of 80 characters.])"
922 echo "AS_HELP_STRING([[--foo[=bar]]],
923 [some other t[]t which should wrap at our default of 80 characters.])"
924 echo "AS_HELP_STRING([[--foo[=bar]123456789]],
925 [some other t[]t which should wrap at our default of 80 characters.])"
926 echo "AS_HELP_STRING([[--foo[=bar]1234567890]],
927 [some other t[]t which should wrap at our default of 80 characters.])"
928 echo "AS_HELP_STRING([[--foo[=bar]12345678901]],
929 [some other t[]t which should wrap at our default of 80 characters.])"
930 echo "AS_HELP_STRING([[--foo[=bar]123456789012]],
931 [some other t[]t which should wrap at our default of 80 characters.])"
932 echo "AS_HELP_STRING([[--foo[=bar]1234567890123]],
933 [some other t[]t which should wrap at our default of 80 characters.])"
934 m4_define([mac], [MACRO])dnl
935 echo "AS_HELP_STRING([--mac], [mac])"
936 echo "AS_HELP_STRING([--o1, --o2], [two
937 options,        one  description])"
938 echo "AS_HELP_STRING([[[--o3, --o4]]], [comma inside literal quoting])"
939 echo "AS_HELP_STRING([--tune1], [check out the tuned formatting],
940 [            ])"
941 echo "AS_HELP_STRING([--tune2], [check out the tuned formatting],
942 [12])"
943 echo "AS_HELP_STRING([--tune3], [check out the tuned formatting],
944 [], [40])"
945 echo "AS_HELP_STRING([--tune4], [check out the tuned formatting],
946 [12], [40])"
949 AT_CHECK_M4SH
950 AT_CHECK([$CONFIG_SHELL ./script], [0],
951 [[  --an-option             some text
952   --another-much-longer-option
953                           some other text which should wrap at our default of
954                           80 characters.
955   --fooT=barT             foo bar
956   --foo[=bar]             foo bar
957   --foo[=bar]123456789    foo bar
958   --foo[=bar]1234567890   foo bar
959   --foo[=bar]12345678901  foo bar
960   --foo[=bar]123456789012 foo bar
961   --foo[=bar]1234567890123
962                           foo bar
963   --foo[=bar]             some other text which should wrap at our default of
964                           80 characters.
965   --foo[=bar]123456789    some other text which should wrap at our default of
966                           80 characters.
967   --foo[=bar]1234567890   some other text which should wrap at our default of
968                           80 characters.
969   --foo[=bar]12345678901  some other text which should wrap at our default of
970                           80 characters.
971   --foo[=bar]123456789012 some other text which should wrap at our default of
972                           80 characters.
973   --foo[=bar]1234567890123
974                           some other text which should wrap at our default of
975                           80 characters.
976   --foo[=bar]             some other [ex] which should wrap at our default of
977                           80 characters.
978   --foo[=bar]123456789    some other [ex] which should wrap at our default of
979                           80 characters.
980   --foo[=bar]1234567890   some other [ex] which should wrap at our default of
981                           80 characters.
982   --foo[=bar]12345678901  some other [ex] which should wrap at our default of
983                           80 characters.
984   --foo[=bar]123456789012 some other [ex] which should wrap at our default of
985                           80 characters.
986   --foo[=bar]1234567890123
987                           some other [ex] which should wrap at our default of
988                           80 characters.
989   --foo[=bar]             some other t[]t which should wrap at our default of
990                           80 characters.
991   --foo[=bar]123456789    some other t[]t which should wrap at our default of
992                           80 characters.
993   --foo[=bar]1234567890   some other t[]t which should wrap at our default of
994                           80 characters.
995   --foo[=bar]12345678901  some other t[]t which should wrap at our default of
996                           80 characters.
997   --foo[=bar]123456789012 some other t[]t which should wrap at our default of
998                           80 characters.
999   --foo[=bar]1234567890123
1000                           some other t[]t which should wrap at our default of
1001                           80 characters.
1002   --MACRO                 mac
1003   --o1, --o2              two options, one description
1004   [--o3, --o4]            comma inside literal quoting
1005   --tune1   check out the tuned formatting
1006   --tune2   check out the tuned formatting
1007   --tune3                 check out the
1008                           tuned
1009                           formatting
1010   --tune4   check out the tuned
1011             formatting
1014 AT_CLEANUP
1017 ## ------------------- ##
1018 ## AS_IF and AS_CASE.  ##
1019 ## ------------------- ##
1021 AT_SETUP([AS@&t@_IF and AS@&t@_CASE])
1022 AT_KEYWORDS([m4sh m4@&t@_map_args_pair])
1024 AT_DATA_M4SH([script.as], [[dnl
1025 AS_INIT
1026 # Syntax checks: cope with empty arguments.
1027 AS_IF([:], [], [echo wrong])
1028 AS_IF([:], [echo one], [echo wrong])
1029 AS_IF([false], [echo wrong], [echo two])
1030 AS_IF([false], [echo wrong])
1031 # n-ary version
1032 AS_IF([false], [echo wrong],
1033       [:], [echo three])
1034 AS_IF([false], [echo wrong],
1035       [:], [echo four],
1036       [echo wrong])
1037 AS_IF([false], [echo wrong],
1038       [false], [echo wrong])
1039 AS_IF([false], [echo wrong],
1040       [false], [echo wrong],
1041       [echo five])
1042 AS_IF([false], [echo wrong],
1043       [false], [echo wrong],
1044       [:], [echo six],
1045       [echo wrong])
1046 AS_CASE([foo])
1047 AS_CASE([foo], [echo seven])
1048 AS_CASE([foo],
1049         [foo], [echo eight],
1050         [echo wrong])
1051 AS_CASE([foo],
1052         [foo], [echo nine],
1053         [*],   [echo wrong])
1054 AS_CASE([foo],
1055         [bar], [echo wrong],
1056         [foo], [echo ten],
1057         [*],   [echo wrong])
1059 # check for nesting, lists, and side effects, and quoting robustness
1060 empty=
1061 AS_IF([AS_IF([$empty], [echo eleven])]) && AS_CASE([foo]) && echo twelve
1062 rm -f file
1063 AS_IF([touch file; false]) && echo thirteen
1064 test -f file && echo fourteen
1065 rm -f file
1066 AS_CASE([`touch file; false`]) && test -f file && echo fifteen
1067 dnl The next line is badly underquoted; don't intentionally copy this style.
1068 AS_CASE([foo], [foo], m4_do(AS_CASE([bar], [bar], [echo sixteen])))
1069 dnl Handle blank arguments.
1070 AS_IF([false], [:], [ ]) && AS_CASE([foo], [foo], []
1071 ) && echo seventeen
1072 m4_define([empty])AS_IF([:], [empty]
1073 ) && AS_CASE([foo], [foo], [empty]) && echo eighteen
1074 dnl We can't handle AS_IF([false], [:], [empty]) unless m4_expand is
1075 dnl taught how to handle m4_require.  The user is responsible for
1076 dnl avoiding the syntax error in that case.
1078 # check that require works correctly
1079 m4_for([n], 1, 9, [],
1080 [m4_defun([FOO]n, [foo]n[=]n)dnl
1081 m4_defun([BAR]n,
1082          [m4_require([FOO]]n[)dnl
1083 bar]n[=]n)[]dnl
1086 AS_IF([:], [BAR1])
1087 echo "foo1=$foo1 bar1=$bar1"
1088 AS_IF([:], [], [BAR2])
1089 echo "foo2=$foo2 bar2=$bar2"
1090 AS_IF([false], [BAR3])
1091 echo "foo3=$foo3 bar3=$bar3"
1092 AS_IF([false], [], [BAR4])
1093 echo "foo4=$foo4 bar4=$bar4"
1094 AS_CASE([x], [x], [BAR5])
1095 echo "foo5=$foo5 bar5=$bar5"
1096 AS_CASE([x], [y], [BAR6])
1097 echo "foo6=$foo6 bar6=$bar6"
1098 AS_CASE([x],
1099         [x], [:],
1100         [BAR7])
1101 echo "foo7=$foo7 bar7=$bar7"
1102 AS_CASE([x],
1103         [y], [:],
1104         [BAR8])
1105 echo "foo8=$foo8 bar8=$bar8"
1106 AS_CASE([x],
1107         [y], [:],
1108         [x], [BAR9])
1109 echo "foo9=$foo9 bar9=$bar9"
1112 AT_CHECK_M4SH
1113 AT_CHECK([$CONFIG_SHELL ./script], [0], [[one
1115 three
1116 four
1117 five
1119 seven
1120 eight
1121 nine
1123 eleven
1124 twelve
1125 thirteen
1126 fourteen
1127 fifteen
1128 sixteen
1129 seventeen
1130 eighteen
1131 foo1=1 bar1=1
1132 foo2=2 bar2=
1133 foo3=3 bar3=
1134 foo4=4 bar4=4
1135 foo5=5 bar5=5
1136 foo6=6 bar6=
1137 foo7=7 bar7=
1138 foo8=8 bar8=8
1139 foo9=9 bar9=9
1142 dnl stress test for large number of conditionals
1143 dnl too large, and we start tickling shell bugs
1144 m4_pushdef([limit], [1000])dnl
1145 AT_DATA_M4SH([script.as], [[dnl
1146 AS_INIT
1147 AS_IF(m4_shift(m4_for([i], [1], ]limit[, [], [, test $[1] = i, echo i])))
1148 AS_IF(m4_shift(m4_for([i], [1], ]limit[, [], [, test $[1] = i, echo i])),
1149       [echo default])
1150 AS_CASE([$[1]]m4_for([i], [1], ]limit[, [], [, i, echo i]))
1151 AS_CASE([$[1]]m4_for([i], [1], ]limit[, [], [, i, echo i]), [echo default])
1154 dnl Add --force so autom4te doesn't think `script' is still up to date.
1155 AT_CHECK_M4SH([--force])
1156 AT_CHECK([$CONFIG_SHELL ./script 1], [0], [[1
1161 AT_CHECK([$CONFIG_SHELL ./script limit], [0], [limit
1162 limit
1163 limit
1164 limit
1166 AT_CHECK([$CONFIG_SHELL ./script default], [0], [[default
1167 default
1169 m4_popdef([limit])
1171 AT_CLEANUP
1174 ## -------- ##
1175 ## AS_FOR.  ##
1176 ## -------- ##
1178 AT_SETUP([AS@&t@_FOR])
1179 AT_KEYWORDS([m4sh])
1181 AT_DATA_M4SH([script.as], [[dnl
1182 AS_INIT
1184 # Simple checks.
1185 AS_FOR([m4var], [shvar], [a],
1186 [echo "m4var $shvar"])
1187 AS_FOR([m4var], [shvar], [b c],
1188 [echo "m4var $shvar"])
1189 list='d e'
1190 AS_FOR([m4var], [shvar], [$list],
1191 [echo "m4var $shvar"])
1192 AS_FOR([m4var], [shvar], ["$list"],
1193 [echo "m4var $shvar"])
1194 AS_FOR([m4var], [shvar], ['$list'],
1195 [echo "m4var $shvar"])
1196 AS_FOR([m4var], [shvar], [\'],
1197 [echo "m4var $shvar"])
1199 # Syntax checks: cope with empty/blank arguments.
1200 set f g
1201 AS_FOR([], [shvar], [],
1202 [echo "m4_defn([]) $shvar"])
1203 rm -f file
1204 AS_FOR([], [shvar], [`touch file`])
1205 test -f file || exit 1
1206 AS_FOR([], [shvar], [], [ ])
1207 m4_define([empty])AS_FOR([], [shvar], [], [empty])
1209 # Check that break works.
1210 while :
1212   AS_FOR([m4var], [shvar], [h i],
1213     [echo "m4var"; break 2])
1214   exit 1
1215 done
1216 while :
1218   AS_FOR([m4var], [shvar], [j],
1219     [echo "m4var"; break 2])
1220   exit 1
1221 done
1224 AT_CHECK_M4SH
1225 AT_CHECK([$CONFIG_SHELL ./script], [0], [[a a
1226 b b
1227 c c
1228 d d
1229 e e
1230 d e d e
1231 $list $list
1232 ' '
1233 f f
1234 g g
1239 AT_CLEANUP
1242 ## --------------- ##
1243 ## AS_LITERAL_IF.  ##
1244 ## --------------- ##
1246 AT_SETUP([AS@&t@_LITERAL_IF])
1247 AT_KEYWORDS([m4sh AS@&t@_LITERAL_WORD_IF AS@&t@_LITERAL_HEREDOC_IF])
1249 AT_DATA_M4SH([script.as], [[dnl
1250 AS_INIT
1251 echo AS_LITERAL_IF([lit], [ok], [ERR]) 1
1252 echo AS_LITERAL_IF([l-/.it], [ok], [ERR]) 2
1253 echo AS_LITERAL_IF([l''it], [ERR], [ok]) 3
1254 echo AS_LITERAL_IF([l$it], [ERR], [ok]) 4
1255 echo AS_LITERAL_IF([l$it], [ERR1], [ERR2], [ok]) 5
1256 echo AS_LITERAL_IF([l${it}], [ERR1], [ERR2], [ok]) 6
1257 echo AS_LITERAL_IF([l`case a in b) ;; esac`it], [ERR], [ok]) 7
1258 echo AS_LITERAL_IF([l`case a in b) ;; esac`it], [ERR1], [ok], [ERR2]) 8
1259 m4_define([mac], [l-/.it])
1260 echo AS_LITERAL_IF([mac], [ok], [ERR]) 9
1261 echo AS_LITERAL_IF([mac($, ``)], [ok], [ERR]) 10
1262 m4_define([mac], [l$it])
1263 echo AS_LITERAL_IF([mac], [ERR], [ok]) 11
1264 echo AS_LITERAL_IF([mac], [ERR1], [ERR2], [ok]) 12
1265 m4_define([mac], [l``it])
1266 echo AS_LITERAL_IF([mac], [ERR], [ok]) 13
1267 echo AS_LITERAL_IF([mac], [ERR1], [ok], [ERR2]) 14
1268 echo AS_LITERAL_IF([    a ][
1269 b], [ok], [ERR]) 15
1270 echo AS_LITERAL_WORD_IF([       a ][
1271 b], [ERR], [ok]) 16
1272 echo AS_LITERAL_HEREDOC_IF([    a ][
1273 b], [ok], [ERR]) 17
1274 echo AS_LITERAL_IF([(a)], [ERR], [ok]) 18
1275 echo AS_LITERAL_WORD_IF([(a)], [ERR], [ok]) 19
1276 echo AS_LITERAL_HEREDOC_IF([(a)], [ok], [ERR]) 20
1277 echo AS_LITERAL_IF([@S|@a], [ERR], [ok]) 21
1278 echo AS_LITERAL_WORD_IF([@S|@a], [ERR], [ok]) 22
1279 echo AS_LITERAL_HEREDOC_IF([@S|@a], [ERR], [ok]) 23
1280 echo AS_LITERAL_IF([${a+b}], [ERR1], [ok], [ERR2]) 24
1281 echo AS_LITERAL_IF([${a=b}], [ERR1], [ok], [ERR2]) 25
1282 echo AS_LITERAL_IF([a+b], [ok], [ERR1], [ERR2]) 26
1283 echo AS_LITERAL_IF([a=b], [ok], [ERR1], [ERR2]) 27
1286 AT_CHECK_M4SH
1287 AT_CHECK([$CONFIG_SHELL ./script], [],
1288 [[ok 1
1289 ok 2
1290 ok 3
1291 ok 4
1292 ok 5
1293 ok 6
1294 ok 7
1295 ok 8
1296 ok 9
1297 ok 10
1298 ok 11
1299 ok 12
1300 ok 13
1301 ok 14
1302 ok 15
1303 ok 16
1304 ok 17
1305 ok 18
1306 ok 19
1307 ok 20
1308 ok 21
1309 ok 22
1310 ok 23
1311 ok 24
1312 ok 25
1313 ok 26
1314 ok 27
1317 AT_CLEANUP
1320 ## --------------------- ##
1321 ## AS_TR_SH, AS_TR_CPP.  ##
1322 ## --------------------- ##
1324 AT_SETUP([AS@&t@_TR_SH and AS@&t@_TR_CPP])
1326 AT_DATA_M4SH([script.as], [[dnl
1327 AS_INIT
1328 m4_define([abc], [hI])m4_define([ABC], [Hi])
1329 m4_define([hi], [oops])m4_define([HI], [OOPS])
1330 echo AS_TR_SH(abc) AS_TR_SH(aBc) AS_TR_SH(ABC)
1331 echo AS_TR_SH([abc]) AS_TR_SH([aBc]) AS_TR_SH([ABC])
1332 echo AS_TR_SH([[abc]]) AS_TR_SH([[aBc]]) AS_TR_SH([[ABC]])
1333 echo AS_TR_CPP(abc) AS_TR_CPP(aBc) AS_TR_CPP(ABC)
1334 echo AS_TR_CPP([abc]) AS_TR_CPP([aBc]) AS_TR_CPP([ABC])
1335 echo AS_TR_CPP([[abc]]) AS_TR_CPP([[aBc]]) AS_TR_CPP([[ABC]])
1336 echo ===
1337 [var=abc vAr=aBc VAR=ABC]
1338 echo AS_TR_SH($var) AS_TR_SH($vAr) AS_TR_SH($VAR)
1339 echo AS_TR_SH([$var]) AS_TR_SH([$vAr]) AS_TR_SH([$VAR])
1340 echo AS_TR_SH([[$var]]) AS_TR_SH([[$vAr]]) AS_TR_SH([[$VAR]])
1341 echo AS_TR_CPP($var) AS_TR_CPP($vAr) AS_TR_CPP($VAR)
1342 echo AS_TR_CPP([$var]) AS_TR_CPP([$vAr]) AS_TR_CPP([$VAR])
1343 echo AS_TR_CPP([[$var]]) AS_TR_CPP([[$vAr]]) AS_TR_CPP([[$VAR]])
1344 echo ===
1345 echo AS_TR_SH(`echo abc`) AS_TR_SH(`echo aBc`) AS_TR_SH(`echo ABC`)
1346 echo AS_TR_SH([`echo abc`]) AS_TR_SH([`echo aBc`]) AS_TR_SH([`echo ABC`])
1347 echo AS_TR_SH([[`echo abc`]]) AS_TR_SH([[`echo aBc`]]) AS_TR_SH([[`echo ABC`]])
1348 echo AS_TR_CPP(`echo abc`) AS_TR_CPP(`echo aBc`) AS_TR_CPP(`echo ABC`)
1349 echo AS_TR_CPP([`echo abc`]) AS_TR_CPP([`echo aBc`]) AS_TR_CPP([`echo ABC`])
1350 echo AS_TR_CPP([[`echo abc`]]) AS_TR_CPP([[`echo aBc`]]) AS_TR_CPP([[`echo ABC`]])
1351 echo ===
1352 # start here
1353 echo AS_TR_SH([a.b/c+*-=])
1354 echo AS_TR_CPP([a.b/c+*-=])
1355 var=a.b/c+*-=
1356 echo AS_TR_SH([$var])
1357 echo AS_TR_CPP([$var])
1358 m4_define([macro], [a.b/c+*-=])
1359 echo AS_TR_SH([macro])
1360 echo AS_TR_CPP([macro])
1363 AT_CHECK_M4SH
1364 AT_CHECK([$CONFIG_SHELL ./script], [],
1365 [[hI aBc Hi
1366 hI aBc Hi
1367 abc aBc ABC
1368 HI ABC HI
1369 HI ABC HI
1370 ABC ABC ABC
1372 abc aBc ABC
1373 abc aBc ABC
1374 abc aBc ABC
1375 ABC ABC ABC
1376 ABC ABC ABC
1377 ABC ABC ABC
1379 hI aBc Hi
1380 hI aBc Hi
1381 abc aBc ABC
1382 HI ABC HI
1383 HI ABC HI
1384 ABC ABC ABC
1386 a_b_cpp__
1387 A_B_C_P__
1388 a_b_cpp__
1389 A_B_C_P__
1390 a_b_cpp__
1391 A_B_C_P__
1394 dnl Check that of the last 6 macros, only 2 needed command substitution.
1395 dnl This test abuses our knowledge of m4sh internals a bit; oh well.
1396 AT_CHECK([sed -n '/start here/,$ {
1397 /`.*`/p
1398 }' script | wc -l], [], [[2
1401 AT_CLEANUP
1404 ## ---------- ##
1405 ## AS_VAR_*.  ##
1406 ## ---------- ##
1408 AT_SETUP([AS@&t@_VAR basics])
1409 AT_KEYWORDS([m4sh AS@&t@_VAR_COPY AS@&t@_VAR_SET AS@&t@_VAR_GET])
1410 AT_KEYWORDS([AS@&t@_VAR_TEST_SET AS@&t@_VAR_SET_IF AS@&t@_VAR_IF])
1411 AT_KEYWORDS([AS@&t@_VAR_PUSHDEF AS@&t@_VAR_POPDEF])
1413 AT_DATA_M4SH([script.as], [[dnl
1414 AS_INIT
1415  m4_define([with], [WITH])
1416 # Literals.
1417 dnl AS_VAR_SET_IF also covers AS_VAR_TEST_SET
1418 AS_VAR_SET_IF([foo], [echo oops]) && echo ok
1419 AS_VAR_IF([foo], [], [echo ok], [echo oops])
1420 foo=
1421 AS_VAR_SET_IF([foo], [echo ok])
1422 AS_VAR_SET([foo], ['\a  "weird" `value` with; $fun '\''characters
1423 ']) # 'font-lock
1424 AS_VAR_COPY([bar], [foo])
1425 AS_ECHO(["$bar-"])
1426 AS_ECHO(["AS_VAR_GET([foo])-"])
1427 AS_VAR_SET_IF([foo], [echo ok], [echo oops])
1428 AS_VAR_IF([foo], [string], [echo oops]) && echo ok
1429 AS_VAR_PUSHDEF([tmp], [foo])
1430 AS_VAR_IF([tmp], ['\a  "weird" `value` with; $fun '\''characters
1431 '], [echo ok], [echo oops]) # 'font-lock
1432 AS_VAR_POPDEF([tmp])
1433 m4_ifdef([tmp], [echo oops])
1435 # Indirects via shell vars.
1436 echo '===='
1437 num=1
1438 AS_VAR_SET_IF([foo$num], [echo oops]) && echo ok
1439 AS_VAR_IF([foo$num], [], [echo ok], [echo oops])
1440 foo1=
1441 AS_VAR_SET_IF([foo$num], [echo ok])
1442 AS_VAR_SET([foo$num], ['\a  "weird" `value` with; $fun '\''characters
1443 ']) # 'font-lock
1444 AS_VAR_COPY([bar], [foo$num])
1445 num=2
1446 AS_VAR_COPY([foo$num], [bar])
1447 AS_ECHO(["$foo2-"])
1448 AS_ECHO(["AS_VAR_GET([foo$num])-"])
1449 AS_VAR_SET_IF([foo$num], [echo ok], [echo oops])
1450 AS_VAR_IF([foo$num], [string], [echo oops]) && echo ok
1451 AS_VAR_PUSHDEF([tmp], [foo$num])
1452 AS_VAR_IF([tmp], ['\a  "weird" `value` with; $fun '\''characters
1453 '], [echo ok], [echo oops]) # 'font-lock
1454 AS_VAR_POPDEF([tmp])
1455 m4_ifdef([tmp], [echo oops])
1457 # Indirects via command substitution.
1458 echo '===='
1459 AS_VAR_SET_IF([`echo foo3`], [echo oops]) && echo ok
1460 AS_VAR_IF([`echo foo3`], [], [echo ok], [echo oops])
1461 foo3=
1462 AS_VAR_SET_IF([`echo foo3`], [echo ok])
1463 AS_VAR_SET([`echo foo3`], ['\a  "weird" `value` with; $fun '\''characters
1464 ']) # 'font-lock
1465 AS_VAR_COPY([bar], [`echo foo3`])
1466 num=2
1467 AS_VAR_COPY([`echo foo4`], [bar])
1468 AS_ECHO(["$foo4-"])
1469 AS_ECHO(["AS_VAR_GET([`echo foo4`])-"])
1470 AS_VAR_SET_IF([`echo foo4`], [echo ok], [echo oops])
1471 AS_VAR_IF([`echo foo4`], [string], [echo oops]) && echo ok
1472 AS_VAR_PUSHDEF([tmp], [`echo foo4`])
1473 AS_VAR_IF([tmp], ['\a  "weird" `value` with; $fun '\''characters
1474 '], [echo ok], [echo oops]) # 'font-lock
1475 AS_VAR_POPDEF([tmp])
1476 m4_ifdef([tmp], [echo oops])
1480 AT_CHECK_M4SH
1481 AT_CHECK([$CONFIG_SHELL ./script], [], [[ok
1484 \a  "weird" `value` WITH; $fun 'characters
1486 \a  "weird" `value` WITH; $fun 'characters
1491 ====
1495 \a  "weird" `value` WITH; $fun 'characters
1497 \a  "weird" `value` WITH; $fun 'characters-
1501 ====
1505 \a  "weird" `value` WITH; $fun 'characters
1507 \a  "weird" `value` WITH; $fun 'characters-
1513 AT_CLEANUP
1516 ## --------------- ##
1517 ## AS_VAR_APPEND.  ##
1518 ## --------------- ##
1520 AT_SETUP([AS@&t@_VAR_APPEND])
1521 AT_KEYWORDS([m4sh AS@&t@_VAR])
1523 AT_DATA_M4SH([script.as], [[dnl
1524 AS_INIT
1525 # Literals.
1526 AS_VAR_APPEND([foo], ["hello,  "])
1527 AS_VAR_APPEND([foo], [world])
1528 echo "$foo"
1529 # Indirects via shell vars.
1530 num=1
1531 AS_VAR_APPEND([foo$num], ['hello,  '])
1532 AS_VAR_APPEND([foo$num], [`echo "world"`])
1533 echo "$foo1"
1534 # Indirects via command substitution.
1535 h=hello w=',  world'
1536 AS_VAR_APPEND([`echo foo2`], [${h}])
1537 AS_VAR_APPEND([`echo foo2`], ["$w"])
1538 echo "$foo2"
1541 AT_CHECK_M4SH
1542 AT_CHECK([$CONFIG_SHELL ./script], [],
1543 [[hello,  world
1544 hello,  world
1545 hello,  world
1548 AT_CLEANUP
1551 ## -------------- ##
1552 ## AS_VAR_ARITH.  ##
1553 ## -------------- ##
1555 AT_SETUP([AS@&t@_VAR_ARITH])
1556 AT_KEYWORDS([m4sh AS@&t@_VAR])
1558 AT_DATA_M4SH([script.as], [[dnl
1559 AS_INIT
1560 # Literals.
1561 AS_VAR_ARITH([foo], [1 + 1])
1562 echo "$foo"
1563 # Indirects via shell vars.
1564 num=1
1565 AS_VAR_ARITH([foo$num], [\( 2 + 3 \) \* 4])
1566 echo "$foo1"
1567 # Indirects via command substitution.
1568 AS_VAR_ARITH([`echo foo2`], [0 + -2 + $foo1 / 2])
1569 echo "$foo2"
1572 AT_CHECK_M4SH
1573 AT_CHECK([$CONFIG_SHELL ./script], [],
1579 AT_CLEANUP
1582 ## ----------------- ##
1583 ## AS_INIT cleanup.  ##
1584 ## ----------------- ##
1586 AT_SETUP([AS@&t@_INIT cleanup])
1587 AT_KEYWORDS([m4sh m4@&t@_wrap m4@&t@_wrap_lifo])
1589 AT_DATA_M4SH([script.as], [[dnl
1590 dnl Registered before AS_INIT's cleanups
1591 m4_wrap([echo cleanup 1
1593 m4_pushdef([_AS_SHELL_FN_SPY])dnl neutralize the spy, we don't care about it
1594 AS_INIT
1595 dnl Registered after AS_INIT's cleanups, thus goes to KILL diversion
1596 m4_wrap([echo cleanup 2
1597 dnl However, nested wraps and diversions can still be used
1598 dnl Also, test wrapping text that looks like parameter reference
1599 m4_wrap([echo cleanup 3
1600 m4_divert_text([M4SH-INIT], [m4_define([foo], [$1])dnl
1601 echo prep foo([4])
1602 ])])])
1603 dnl Registered before AS_INIT's cleanups
1604 m4_wrap_lifo([echo cleanup 5
1606 echo body
1609 AT_CHECK_M4SH
1610 AT_CHECK([$CONFIG_SHELL ./script], [], [[prep 4
1611 body
1612 cleanup 5
1613 cleanup 1
1616 AT_CLEANUP
1619 ## ------------------- ##
1620 ## AS_INIT_GENERATED.  ##
1621 ## ------------------- ##
1623 AT_SETUP([AS@&t@_INIT_GENERATED])
1624 AT_KEYWORDS([AS@&t@_MESSAGE AS@&t@_MESSAGE_LOG_FD])
1626 dnl First run, no logging, tests shell selection
1627 AT_DATA_M4SH([script.as], [[dnl
1628 AS_INIT
1629 AS_INIT_GENERATED([child], [echo hello from child])
1630 cat >>child <<\EOF
1631 AS_ECHO(["SHELL=$SHELL"])
1633 echo hello from parent
1634 AS_ECHO(["SHELL=$SHELL"])
1637 AT_CHECK_M4SH
1638 AT_CHECK([$CONFIG_SHELL ./script], [0], [stdout])
1639 AT_CHECK([grep 'SHELL=.' stdout], [0], [ignore])
1640 sed s/parent/child/ <stdout >expout
1641 AT_CHECK([./child], [0], [expout])
1642 SHELL=/bogus
1643 export SHELL
1644 cp stdout expout
1645 mv child child.bak
1646 AT_CHECK([$CONFIG_SHELL ./script], [0], [expout])
1647 AT_CHECK([cmp child child.bak])
1648 AT_CHECK([grep 'SHELL=.' stdout], [0], [ignore])
1649 sed s/parent/child/ <stdout >expout
1650 AT_CHECK([./child], [0], [expout])
1653 dnl Second run, with logging from parent and child, tests fd handling
1654 AT_DATA_M4SH([script.as], [[dnl
1655 AS_INIT
1656 child=${1-child}
1657 m4_define([AS_MESSAGE_LOG_FD], [5])
1658 exec AS_MESSAGE_LOG_FD>log
1659 AS_INIT_GENERATED([$child], [echo hello1 from $child]) || AS_EXIT([1])
1660 cat >>$child <<\EOF
1661 m4_pushdef([AS_MESSAGE_LOG_FD])
1662 AS_MESSAGE([hello2 from ${child}child])
1663 m4_popdef([AS_MESSAGE_LOG_FD])
1664 exec AS_MESSAGE_LOG_FD>>log
1665 AS_MESSAGE([hello3 from child])
1667 AS_MESSAGE([hello from parent])
1668 dnl close log in parent before spawning child, for mingw
1669 exec AS_MESSAGE_LOG_FD>&-
1670 ./$child
1673 rm -f script
1674 AT_CHECK_M4SH
1675 AT_CHECK([$CONFIG_SHELL ./script], [0], [[script: hello from parent
1676 hello1 from child
1677 child: hello2 from child
1678 child: hello3 from child
1680 AT_CHECK([[sed 's,:[0-9][0-9]*:,:0:,' log]], [0],
1681 [[script:0: hello from parent
1682 child:0: hello3 from child
1685 # Force write error creating a file on stdout
1686 if test -w /dev/full && test -c /dev/full; then
1687   AT_CHECK([$CONFIG_SHELL ./script /dev/full], [1], [ignore], [ignore])
1690 AT_CLEANUP
1693 ## --------------- ##
1694 ## AS_MESSAGE_FD.  ##
1695 ## --------------- ##
1697 AT_SETUP([AS@&t@_MESSAGE_FD])
1698 AT_KEYWORDS([AS@&t@_MESSAGE AS@&t@_MESSAGE_LOG_FD AS@&t_ORIGINAL_STDIN_FD])
1699 AT_KEYWORDS([AS@&t@_LINENO_PUSH])
1701 AT_DATA_M4SH([script.as], [[dnl
1702 AS_INIT
1703 m4_define([AS_ORIGINAL_STDIN_FD], [5])
1704 m4_define([AS_MESSAGE_LOG_FD], [6])
1705 m4_define([AS_MESSAGE_FD], [7])
1706 exec AS_ORIGINAL_STDIN_FD<&0 </dev/null AS_MESSAGE_LOG_FD>log
1707 if test $[#] -gt 0; then
1708   exec AS_MESSAGE_FD>/dev/null
1709 else
1710   exec AS_MESSAGE_FD>&1
1712 AS_LINENO_PUSH([100])
1713 cat # tests that stdin is neutralized
1714 AS_MESSAGE([hello world])
1715 cat <&AS_ORIGINAL_STDIN_FD
1718 AT_CHECK_M4SH
1719 AT_CHECK([echo goodbye | $CONFIG_SHELL ./script], [0],
1720 [[script: hello world
1721 goodbye
1723 AT_CHECK([cat log], [0],
1724 [[script:100: hello world
1726 rm log
1727 AT_CHECK([echo goodbye | $CONFIG_SHELL ./script silent], [0],
1728 [[goodbye
1730 AT_CHECK([cat log], [0],
1731 [[script:100: hello world
1734 AT_CLEANUP
1737 ## --------------- ##
1738 ## _AS_CLEAN_DIR.  ##
1739 ## --------------- ##
1741 AT_SETUP([_AS@&t@_CLEAN_DIR])
1743 dnl ensure that we can erase all files in a directory.  Note that
1744 dnl _AS_CLEAN_DIR needs three globs to catch all these files.
1745 AT_DATA_M4SH([script.as], [[dnl
1746 AS_INIT
1747 # Unwritable subdirectories are common during 'make distcheck'.
1748 mkdir sub sub/unwritable || AS_ERROR([failed to mkdir])
1749 touch sub/unwritable/file || AS_ERROR([failed to touch])
1750 chmod a-wx sub/unwritable || AS_ERROR([failed to chmod])
1751 # Cygwin 1.5 can't touch 'sub/...', so make that file optional.
1752 touch sub/a sub/aa sub/aaa sub/.a sub/..a sub/.aa \
1753   || AS_ERROR([failed to touch])
1754 touch sub/... 2>/dev/null
1755 _AS_CLEAN_DIR([sub]) || AS_ERROR([failed to clean])
1756 # rmdir instead of 'rm -fr' here proves that we emptied sub.
1757 rmdir sub || AS_ERROR([failed to rmdir])
1760 AT_CHECK_M4SH
1761 AT_CHECK([$CONFIG_SHELL ./script])
1763 AT_CLEANUP
1766 ## -------- ##
1767 ## ECHO_C.  ##
1768 ## -------- ##
1770 AT_SETUP([ECHO_C])
1772 AT_DATA_M4SH([script.as], [[dnl
1773 AS_INIT
1774 _AS_PREPARE
1775 foo=`echo foobar`
1776 echo "$foo"
1779 AT_CHECK_M4SH
1780 AT_CHECK([$CONFIG_SHELL ./script], [], [foobar
1783 AT_CLEANUP