docs: avoid first person, and credit history to David MacKenzie
[autoconf.git] / tests / m4sh.at
blobc01027f694325ce6bbc1347513cf5f4ebb327e96
1 #                                                       -*- Autotest -*-
3 AT_BANNER([M4sh.])
5 # Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
6 # 2009, 2010 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 ## AS_WARN, AS_ERROR.  ##
23 ## ------------------- ##
25 AT_SETUP([AS@&t@_WARN and AS@&t@_ERROR])
26 AT_KEYWORDS([m4sh])
28 dnl without logging
29 AT_DATA_M4SH([script.as],
30 [[AS_INIT
31 AS_WARN([*watch out*])dnl
33 if test x"$die" != x; then
34   AS_ERROR([you're dead])dnl
36   AS_ERROR([really])dnl
39 echo got here
40 ]])
42 AT_CHECK_M4SH
43 AT_CHECK([$CONFIG_SHELL ./script], [],
44 [[got here
45 ]], [[script: WARNING: *watch out*
46 ]])
47 AT_CHECK([die=: $CONFIG_SHELL ./script], [1],
48 [], [[script: WARNING: *watch out*
49 script: error: you're dead
50 ]])
52 dnl with logging
53 rm script
54 AT_DATA_M4SH([script.as],
55 [[AS_INIT
56 m4_define([gone], [AS_ERROR([really])])
57 m4_define([AS_MESSAGE_LOG_FD], [5])
58 exec AS_MESSAGE_LOG_FD>log.txt
59 AS_WARN([*watch out*])dnl
61 if test x"$die" != x; then
62   AS_ERROR([you're dead])dnl
64   AS_ERROR([really])dnl
67 echo got here
68 exec AS_MESSAGE_LOG_FD>&-
69 ]])
71 AT_CHECK_M4SH
72 AT_CHECK([$CONFIG_SHELL ./script], [],
73 [[got here
74 ]], [[script: WARNING: *watch out*
75 ]])
76 AT_CHECK([[grep 'script:[0-9]*: WARNING: \*watch out\*' log.txt]], [], [ignore])
77 AT_CHECK([die=: $CONFIG_SHELL ./script], [1],
78 [], [[script: WARNING: *watch out*
79 script: error: you're dead
80 ]])
81 AT_CHECK([[grep 'script:[0-9]*: WARNING: \*watch out\*' log.txt]], [], [ignore])
82 AT_CHECK([[grep 'script:[0-9]*: error: you'\''re dead' log.txt]], [], [ignore])
84 AT_CLEANUP
86 ## ---------------- ##
87 ## LINENO support.  ##
88 ## ---------------- ##
90 AT_SETUP([LINENO])
91 AT_KEYWORDS([m4sh])
93 # We cannot unset LINENO with Zsh, yet this test case relies on
94 # unsetting LINENO to compare its result when (i) LINENO is supported
95 # and when (ii) it is not.
96 # So just skip if the shell is ZSH.
97 AT_CHECK([test -n "${ZSH_VERSION+set}" && exit 77], ignore)
99 # AT_DATA_LINENO(FILE-NAME,
100 #                UNSET-LINENO = true | false, COUNTER, COUNTER-RE)
101 # ----------------------------------------------------------------
102 # Produce the FILE-NAME M4sh script which uses the COUNTER LINENO or
103 # _oline_, which we can recognized via COUNTER-RE.  Unset LINENO is
104 # UNSET-LINENO.
106 # Use COUNTER, COUNTER-RE = [__LINENO__], [LINENO]
107 #  or                     = [__OLINE__],  [_oline__]
109 # instead of the obvious $LINENO and __oline__, because they would
110 # be replaced in the test suite itself, even before creating these
111 # scripts.  For the same reason, grep for LINENO and _oline__ (sic).
113 # UNSET-LINENO is a shell condition to make sure the scripts have the
114 # same number of lines in the output, so that their outputs be identical.
115 m4_define([AT_DATA_LINENO],
116 [AT_DATA([$1.tas],
117 [[AS@&t@_INIT
118 m4@&t@_divert_text([], [
119 if $2; then
120   AS@&t@_UNSET([LINENO])
123 AS@&t@_LINENO_PREPARE
124 echo "Line: $3"
125 grep 'Line: .*$4' "$[0]" >/dev/null ||
126   AS@&t@_ERROR([cannot find original script])
127 exit 0
129 # If occurrences of $LINENO or __@&t@oline__ were wanted, create them.
130 sed 's/__LINENO__/$''LINENO/g;s/__OLINE__/__''oline__/g' $1.tas >$1.as
131 AT_CHECK([autom4te -l m4sh $1.as -o $1])
132 ])# AT_DATA_LINENO
134 # `_oline_', once processed and ran, produces our reference.
135 # We check that we find ourselves by looking at a string which is
136 # available only in the original script: `_oline_'.
137 AT_DATA_LINENO([reference], [false], [__OLINE__], [_oline__])
138 AT_CHECK([./reference], 0, [stdout])
140 # The reference:
141 mv stdout expout
143 # Now using a maybe-functioning LINENO, with different call conventions.
144 # Be sure to be out of the PATH.
145 AT_CHECK([mkdir test || exit 77])
147 AT_DATA_LINENO([test/test-1], [false], [__LINENO__], [LINENO])
148 AT_CHECK([./test/test-1],                          0, [expout])
149 AT_CHECK([(PATH=test$PATH_SEPARATOR$PATH; export PATH; exec test-1)],
150                                                    0, [expout])
151 AT_CHECK([sh ./test/test-1],                       0, [expout])
153 # Now using a disabled LINENO, with different call conventions.
154 AT_DATA_LINENO([test/test-2], [true], [__LINENO__], [LINENO])
155 AT_CHECK([./test/test-2],                          0, [expout])
156 AT_CHECK([(PATH=test$PATH_SEPARATOR$PATH; export PATH; exec test-2)],
157                                                    0, [expout])
158 AT_CHECK([sh ./test/test-2],                       0, [expout])
160 AT_CLEANUP
163 ## ---------------------- ##
164 ## LINENO stack support.  ##
165 ## ---------------------- ##
167 AT_SETUP([LINENO stack])
168 AT_KEYWORDS([m4sh])
170 AT_DATA_M4SH([script.as],
171 [[AS_INIT
173 AS_LINENO_PUSH([9999])
174 test $as_lineno = 9999 || AS_ERROR([bad as_lineno at depth 1])
175 AS_LINENO_PUSH([8888])
176 test $as_lineno = 9999 || AS_ERROR([bad as_lineno at depth 2])
177 AS_LINENO_POP
178 test $as_lineno = 9999 || AS_ERROR([bad as_lineno at depth 1])
179 AS_LINENO_POP
180 test x${as_lineno+set} = xset && AS_ERROR([as_lineno set at depth 0])
182 AS_EXIT([0])
185 AT_CHECK_M4SH
186 AT_CHECK([$CONFIG_SHELL ./script])
188 AT_CLEANUP
191 ## -------- ##
192 ## AS_BOX.  ##
193 ## -------- ##
195 # Output a framed one-line message.
196 AT_SETUP([AS@&t@_BOX])
197 AT_KEYWORDS([m4sh])
199 AT_DATA_M4SH([script.as],
200 [[AS_INIT
201 echo
202 AS_BOX([Send a simple message, to foobar@example.com])
203 AS_BOX([Send a simple message, to foobar@example.com], [$])
204 m4_define([msg], [$complex])
205 complex='Not quite as simple |$[1]'
206 AS_BOX([msg])
207 AS_BOX([msg], [,])
208 AS_EXIT(0)
211 AT_CHECK_M4SH
212 AT_CHECK([sed -n '/ -\{44\} /,/ -\{44\} /p' script ]dnl
213 [| sed '1 s/.*## -/## -/; 3 s/- ##.*/- ##/'], [],
214 [[## -------------------------------------------- ##
215 ## Send a simple message, to foobar@example.com ##
216 ## -------------------------------------------- ##
219 AT_CHECK([$CONFIG_SHELL ./script], [], [[
220 ## -------------------------------------------- ##
221 ## Send a simple message, to foobar@example.com ##
222 ## -------------------------------------------- ##
223 ## $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ ##
224 ## Send a simple message, to foobar@example.com ##
225 ## $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ ##
226 ## ----------------------- ##
227 ## Not quite as simple |$1 ##
228 ## ----------------------- ##
229 ## ,,,,,,,,,,,,,,,,,,,,,,, ##
230 ## Not quite as simple |$1 ##
231 ## ,,,,,,,,,,,,,,,,,,,,,,, ##
234 AT_CLEANUP
237 # Strip path from file.
238 AT_SETUP([AS@&t@_BASENAME])
239 AT_KEYWORDS([m4sh])
241 AT_DATA_M4SH([script.as],
242 [[AS_INIT
244 m4_define([BASENAME_TEST],
245 [base=`AS_BASENAME([$1])`
246 test "$base" = "$2" ||
247   echo "basename($1) = $base instead of $2" >&2
249 base=`_AS_BASENAME_SED([$1])`
250 test "$base" = "$2" ||
251   echo "basename_sed($1) = $base instead of $2" >&2])
253 BASENAME_TEST([//1],             [1])
254 BASENAME_TEST([/1],              [1])
255 BASENAME_TEST([./1],             [1])
256 BASENAME_TEST([../../2],         [2])
257 BASENAME_TEST([//1/],            [1])
258 BASENAME_TEST([/1/],             [1])
259 BASENAME_TEST([./1/],            [1])
260 BASENAME_TEST([../../2],         [2])
261 BASENAME_TEST([//1/3],           [3])
262 BASENAME_TEST([/1/3],            [3])
263 BASENAME_TEST([./1/3],           [3])
264 BASENAME_TEST([../../2/3],       [3])
265 BASENAME_TEST([//1/3///],        [3])
266 BASENAME_TEST([/1/3///],         [3])
267 BASENAME_TEST([./1/3///],        [3])
268 BASENAME_TEST([../../2/3///],    [3])
269 BASENAME_TEST([//1//3/],         [3])
270 BASENAME_TEST([/1//3/],          [3])
271 BASENAME_TEST([./1//3/],         [3])
272 BASENAME_TEST([a.c],             [a.c])
273 BASENAME_TEST([a.c/],            [a.c])
274 BASENAME_TEST([/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 BASENAME_TEST([./1/a.c/],        [a.c])
281 AS_EXIT(0)
284 AT_CHECK_M4SH
285 AT_CHECK([$CONFIG_SHELL ./script])
287 AT_CLEANUP
290 ## ------------ ##
291 ## AS_DIRNAME.  ##
292 ## ------------ ##
294 # Strip filename component.
295 AT_SETUP([AS@&t@_DIRNAME])
296 AT_KEYWORDS([m4sh])
298 AT_DATA_M4SH([script.as],
299 [[AS_INIT
301 # The EXPR variant is allowed to fail if `expr' was considered as too
302 # weak for us, in which case `as_expr=false'.
303 m4_define([DIRNAME_TEST],
304 [dir=`AS_DIRNAME([$1])`
305 test "$dir" = "$2" || (test -n "$3" && test "$dir" = "$3") ||
306   echo "dirname($1) = $dir instead of $2" >&2
308 if test "$as_expr" != false; then
309   dir=`_AS_DIRNAME_EXPR([$1])`
310   test "$dir" = "$2" || (test -n "$3" && test "$dir" = "$3") ||
311     echo "dirname_expr($1) = $dir instead of $2" >&2
314 dir=`_AS_DIRNAME_SED([$1])`
315 test "$dir" = "$2" || (test -n "$3" && test "$dir" = "$3") ||
316   echo "dirname_sed($1) = $dir instead of $2" >&2])
318 DIRNAME_TEST([/],               [/])
319 DIRNAME_TEST([//],              [//],   [/])
320 DIRNAME_TEST([///],             [/])
321 DIRNAME_TEST([//1],             [//],   [/])
322 DIRNAME_TEST([/1],              [/])
323 DIRNAME_TEST([./1],             [.])
324 DIRNAME_TEST([../../2],         [../..])
325 DIRNAME_TEST([//1/],            [//],   [/])
326 DIRNAME_TEST([/1/],             [/])
327 DIRNAME_TEST([./1/],            [.])
328 DIRNAME_TEST([../../2],         [../..])
329 DIRNAME_TEST([//1/3],           [//1])
330 DIRNAME_TEST([/1/3],            [/1])
331 DIRNAME_TEST([./1/3],           [./1])
332 DIRNAME_TEST([../../2/3],       [../../2])
333 DIRNAME_TEST([//1/3///],        [//1])
334 DIRNAME_TEST([/1/3///],         [/1])
335 DIRNAME_TEST([./1/3///],        [./1])
336 DIRNAME_TEST([../../2/3///],    [../../2])
337 DIRNAME_TEST([//1//3/],         [//1])
338 DIRNAME_TEST([/1//3/],          [/1])
339 DIRNAME_TEST([./1//3/],         [./1])
340 DIRNAME_TEST([../../2//3/],     [../../2])
341 AS_EXIT(0)
344 AT_CHECK_M4SH
345 AT_CHECK([$CONFIG_SHELL ./script])
347 AT_CLEANUP
350 ## ---------------- ##
351 ## AS_SET_CATFILE.  ##
352 ## ---------------- ##
354 AT_SETUP([AS@&t@_SET_CATFILE])
355 AT_KEYWORDS([m4sh])
357 AT_DATA_M4SH([script.as],
358 [[AS_INIT
360 # CATFILE_TEST(DIR, FILE, EXPECTED)
361 m4_define([CATFILE_TEST],
362 [# AS_SET_CATFILE works and can be used in a compound list.
363 if AS_SET_CATFILE([var], [$1], [$2]) \
364    && test "$var" = $3; then :; else
365   echo "catfile($1, $2) = $var != $3" >&2
367 # AS_SET_CATFILE can use non-literals in its arguments.
368 varname=var2
369 dirpart=$1
370 filepart=$2
371 if AS_SET_CATFILE([$varname], [$dirpart], [$filepart]) \
372    && test "$var2" = $3; then :; else
373   echo "catfile($dirpart, $filepart) = $var2 != $3" >&2
377 CATFILE_TEST([dir], [file], [dir/file])
378 CATFILE_TEST([.], [file], [file])
379 CATFILE_TEST([dir], [.], [dir])
380 CATFILE_TEST([dir], [/abs/file], [/abs/file])
381 CATFILE_TEST([dir], [C:/abs/file], [C:/abs/file])
382 CATFILE_TEST(["dir  name"], ['file  name'], ['dir  name/file  name'])
384 AS_EXIT(0)
387 AT_CHECK_M4SH
388 AT_CHECK([$CONFIG_SHELL ./script])
390 AT_CLEANUP
393 ## --------- ##
394 ## AS_ECHO.  ##
395 ## --------- ##
397 # Print literal strings, with/without newline.
398 AT_SETUP([AS@&t@_ECHO and AS@&t@_ECHO_N])
399 AT_KEYWORDS([m4sh])
401 AT_DATA_M4SH([script.as],
402 [[AS_INIT
404 m4_define([ECHO_TEST],
405 [echo=`AS_ECHO(['$1'])`
406 test "X$echo" = 'X$1' ||
407   echo "AS@&t@_ECHO('"'$1'"') outputs '$echo'" >&2
409 echo=`AS_ECHO_N(['$1'])`
410 test "X$echo" = 'X$1' ||
411   echo "AS@&t@_ECHO_N('"'$1'"') outputs '$echo'" >&2])
413 ECHO_TEST([-])
414 ECHO_TEST([--])
415 ECHO_TEST([---...---])
416 ECHO_TEST([      ])
417 ECHO_TEST([-e])
418 ECHO_TEST([-E])
419 ECHO_TEST([-n])
420 ECHO_TEST([-n -n])
421 ECHO_TEST([-e -n])
422 ECHO_TEST([ab\ncd])
423 ECHO_TEST([abcd\c])
424 ECHO_TEST([\a\b\c\f\n\r\t\v\"\])
425 ECHO_TEST([ab
428 ECHO_TEST([
429  ])
430 ECHO_TEST([
431 \c])
432 AS_EXIT(0)
435 AT_CHECK_M4SH
436 AT_CHECK([$CONFIG_SHELL ./script])
438 AT_CLEANUP
442 ## --------- ##
443 ## AS_EXIT.  ##
444 ## --------- ##
446 # Exit scripts with given status.
447 AT_SETUP([AS@&t@_EXIT])
448 AT_KEYWORDS([m4sh AS@&t@_SET_STATUS])
450 AT_DATA_M4SH([script.as],
451 [[AS_INIT
452 test x${1} = xa && AS_EXIT
453 test x${1} = xb && AS_EXIT([${2}])
454 test x${1} = xc && { AS_SET_STATUS([${2}]); AS_EXIT; }
455 test x${1} = xd && trap 's=$?; echo $s; AS_EXIT([$s])' 0
456 test x${2} = xe && set -e
457 test $[#] -gt 0 || AS_EXIT
458 AS_SET_STATUS([3])
459 dnl Solaris /bin/sh 'set -e' doesn't react to failed function calls
460 test x${2} = xe \
461   && { echo 'skipping rest of test: set -e support is lousy'; exit 77; }
462 AS_SET_STATUS([4])
465 AT_CHECK_M4SH
466 AT_CHECK([$CONFIG_SHELL ./script], [1])
467 AT_CHECK([$CONFIG_SHELL ./script ''], [4])
468 AT_CHECK([$CONFIG_SHELL ./script a], [0])
469 AT_CHECK([$CONFIG_SHELL ./script b], [0])
470 AT_CHECK([$CONFIG_SHELL ./script b 0], [0])
471 AT_CHECK([$CONFIG_SHELL ./script b 2], [2])
472 AT_CHECK([$CONFIG_SHELL ./script c 0], [0])
473 AT_CHECK([$CONFIG_SHELL ./script c 2], [2])
474 AT_CHECK([$CONFIG_SHELL ./script d], [4], [[4
476 dnl If we got to this point without a FAIL, then AS_EXIT at least works.
477 dnl The rest of this test relies on semi-decent 'set -e' support, even
478 dnl though m4sh in general should not try to rely on it because of
479 dnl portability nightmares on what constructs are considered errors across
480 dnl various shells; therefore, an overall SKIP result is desirable on
481 dnl broken shells like Solaris /bin/sh.
482 AT_CHECK([$CONFIG_SHELL ./script '' e], [3])
483 AT_CHECK([$CONFIG_SHELL ./script d e], [3], [stdout])
484 dnl NetBSD sh fails to output on stderr here.
485 AT_CHECK([grep 3 stdout || exit 77], [], [ignore])
487 AT_CLEANUP
491 ## ------------ ##
492 ## AS_MKDIR_P.  ##
493 ## ------------ ##
495 # Build nested dirs.
496 AT_SETUP([AS@&t@_MKDIR_P])
497 AT_KEYWORDS([m4sh])
499 AT_DATA_M4SH([script.as],
500 [[AS_INIT
502 pwd=`pwd`
503 set -e
504 # Absolute
505 AS_MKDIR_P(["$pwd/1/2/3/4/5/6"])
506 test -d "$pwd/1/2/3/4/5/6" ||
507   AS_ERROR([$pwd/1/2/3/4/5/6 has not been properly created])
508 # Relative
509 AS_MKDIR_P(["a/b/c/d/e/f"])
510 test -d a/b/c/d/e/f ||
511   AS_ERROR([a/b/c/d/e/f has not been properly created])
512 AS_EXIT(0)
515 AT_CHECK_M4SH
516 AT_CHECK([$CONFIG_SHELL ./script])
518 AT_CLEANUP
523 ## -------------------- ##
524 ## AS_VERSION_COMPARE.  ##
525 ## -------------------- ##
527 # Three-way version comparison.
528 AT_SETUP([AS@&t@_VERSION_COMPARE])
529 AT_KEYWORDS([m4sh])
531 AT_DATA_M4SH([script.as],
532 [[AS_INIT
534 m4_define([VERSION_COMPARE_TEST],
535 [AS_VERSION_COMPARE([$1], [$3], [result='<'], [result='='], [result='>'])
536 test "X$result" = "X$2" ||
537   AS_ERROR([version $1 $result $3; should be $1 $2 $3])
538 m4_if([$1], <,
539 [AS_VERSION_COMPARE([$3], [$1], [result='<'], [result='='], [result='>'])
540 test "X$result" = "X>" ||
541   AS_ERROR([version $3 $result $1; should be $3 > $1])])])
543 VERSION_COMPARE_TEST([], =, [])
544 VERSION_COMPARE_TEST([1.0], =, [1.0])
545 VERSION_COMPARE_TEST([alpha-1.0], =, [alpha-1.0])
547 # These tests are taken from libc/string/tst-svc.expect.
548 tst_svc_expect='
549   000 001 00 00a 01 01a 0 0a 2.8 2.8-0.4 20 21 22 212 CP037 CP345 CP1257
550   foo foo-0.4 foo-0.4a foo-0.4b foo-0.5 foo-0.10.5 foo-3.01 foo-3.0
551   foo-3.0.0 foo-3.0.1 foo-3.2 foo-3.10 foo00 foo0
553 test1=''
554 for test2 in $tst_svc_expect; do
555   VERSION_COMPARE_TEST([$test1], <, [$test2])
556   test1=$test2
557 done
559 AS_EXIT(0)
562 AT_CHECK_M4SH
563 AT_CHECK([$CONFIG_SHELL ./script])
565 AT_CLEANUP
570 ## ------- ##
571 ## as_me.  ##
572 ## ------- ##
574 AT_SETUP([as_me])
575 AT_KEYWORDS([m4sh])
577 AT_DATA_M4SH([script.as],
578 [[AS_INIT
579 AS_ME_PREPARE
580 test "$as_me" = script || AS_ECHO([["incorrect value of \$as_me: $as_me"]])
583 AT_CHECK_M4SH
584 AT_CHECK([$CONFIG_SHELL ./script])
586 AT_CLEANUP
591 ## ----------------------------- ##
592 ## Negated classes in globbing.  ##
593 ## ----------------------------- ##
595 # According to http://www.in-ulm.de/~mascheck/bourne/, all shells with
596 # functions also support `[!...]'.  But `[^...]' is not universally supported.
598 AT_SETUP([Negated classes in globbing])
599 AT_KEYWORDS([m4sh])
601 AT_DATA_M4SH([script.as],
602 [[AS_INIT
604 case 'with!two!bangs' in
605   *[[!a-z]]*) ;;
606            *) AS_ERROR([[`*[!a-z]*' didn't match `with!two!bangs']]);;
607 esac
609 case without in
610   *[[!a-z]]*) AS_ERROR([[`*[!a-z]*' matched `without']]);;
611 esac
614 AT_CHECK_M4SH
615 AT_CHECK([$CONFIG_SHELL ./script])
617 AT_CLEANUP
619 ## ---------------------------- ##
620 ## Null variable substitution.  ##
621 ## ---------------------------- ##
623 # According to http://www.in-ulm.de/~mascheck/bourne/, all shells with
624 # functions also support `${a:-b}'.
626 AT_SETUP([Null variable substitution])
627 AT_KEYWORDS([m4sh])
629 AT_DATA_M4SH([script.as],
630 [[AS_INIT
632 AS_UNSET([a])
635 case ${a:-x}${b:-y}${c:-z} in
636   xy.) ;;
637   *) exit 1 ;;
638 esac
639 case ${a-x}${b-y}${c-z} in
640   x.) ;;
641   *) exit 2 ;;
642 esac
644 case ${a+x}${b+y}${c+z} in
645   yz) ;;
646   *) exit 3 ;;
647 esac
648 case ${a:+x}${b:+y}${c:+z} in
649   z) ;;
650   *) exit 4 ;;
651 esac
653 case ${a=x}${b=y}${c=z} in
654   x.) ;;
655   *) exit 5 ;;
656 esac
657 AS_UNSET([a])
658 case ${a:=x}${b:=y}${c:=z} in
659   xy.) ;;
660   *) exit 6 ;;
661 esac
662 case $a$b$c in
663   xy.) ;;
664   *) exit 7 ;;
665 esac
666 AS_UNSET([a])
669 (: ${a?oops}; echo fail) 2>err && exit 8
670 grep oops err >/dev/null || exit 9
671 test "${b?oops}" = '' || exit 10
672 test "${c?oops}" = . || exit 11
673 (: ${a:?oops}; echo fail) 2>err && exit 12
674 grep oops err >/dev/null || exit 13
675 (: ${b:?oops}; echo fail) 2>err && exit 14
676 grep oops err >/dev/null || exit 15
677 test "${c:?oops}" = . || exit 16
680 AT_CHECK_M4SH
681 AT_CHECK([$CONFIG_SHELL ./script])
683 AT_CLEANUP
686 ## ------------------- ##
687 ## Functions Support.  ##
688 ## ------------------- ##
690 # All m4sh scripts require function support.
692 AT_SETUP([Functions Support])
693 AT_KEYWORDS([m4sh])
695 AT_DATA_M4SH([script.as],
696 [[AS_INIT
697 AS_LINENO_PREPARE
699 func_return () {
700   (exit $1)
703 func_success () {
704   func_return 0
707 func_failure () {
708   func_return 1
711 if func_success; then
712   if func_failure; then
713     AS_ERROR([func_failure passed])
714   fi
715 else
716   AS_ERROR([func_success failed])
720 AT_CHECK_M4SH
721 AT_CHECK([$CONFIG_SHELL ./script])
723 AT_CLEANUP
728 ## ------------------------------ ##
729 ## Functions and return Support.  ##
730 ## ------------------------------ ##
732 # All m4sh scripts require working return within functions.
734 AT_SETUP([Functions and return Support])
735 AT_KEYWORDS([m4sh])
737 AT_DATA_M4SH([script.as],
738 [[AS_INIT
739 AS_LINENO_PREPARE
741 func_success () {
742   return 0
745 func_failure () {
746   return 1
749 if func_success; then
750   if func_failure; then
751     AS_ERROR([func_failure passed])
752   fi
753 else
754   AS_ERROR([func_success failed])
758 AT_CHECK_M4SH
759 AT_CHECK([$CONFIG_SHELL ./script])
761 AT_CLEANUP
764 ## --------------------------- ##
765 ## Nested AS_REQUIRE_SHELL_FN. ##
766 ## --------------------------- ##
768 # Hypothesis: M4sh expands nested AS_REQUIRE_SHELL_FN
769 # separately.
771 AT_SETUP([Nested AS@&t@_REQUIRE_SHELL_FN])
772 AT_KEYWORDS([m4sh])
774 AT_DATA_M4SH([script.as], [[dnl
775 m4_define([INIT], [oops])dnl
776 AS_INIT
778 m4_defun([TEST_FUNC2_BODY], [
782 m4_defun([TEST_FUNC1_BODY], [
783 AS_REQUIRE_SHELL_FN([test_func2], [], [TEST_FUNC2_BODY])
787 AS_REQUIRE_SHELL_FN([test_func1], [], [TEST_FUNC1_BODY])
788 test_func2
791 AT_CHECK_M4SH
792 AT_CHECK([$CONFIG_SHELL ./script])
794 AT_CLEANUP
797 ## ------------------- ##
798 ## Nested AS_REQUIRE.  ##
799 ## ------------------- ##
801 # Hypothesis: M4sh expands the requirements of AS_REQUIRE in the
802 # requested diversion, even if other AS_REQUIREs are interleaved.
804 AT_SETUP([Nested AS@&t@_REQUIRE])
805 AT_KEYWORDS([m4sh])
807 AT_DATA_M4SH([script.as], [[dnl
808 AS_INIT
810 m4_defun([in_fn_diversion], still_in_m4sh_init_fn=yes)
811 m4_defun([not_in_fn_diversion], still_in_m4sh_init_fn=no)
813 m4_defun([NESTED], [nested_require_in_fn_diversion=$still_in_m4sh_init_fn])
815 m4_defun([OUTER], [AS_REQUIRE([NESTED])dnl
816 outer_require_in_fn_diversion=$still_in_m4sh_init_fn])
818 m4_defun([test_init], [
819 AS_REQUIRE([in_fn_diversion], , [M4SH-INIT-FN])
820 AS_REQUIRE([OUTER], , [M4SH-INIT-FN])
821 AS_REQUIRE([not_in_fn_diversion], , [M4SH-INIT-FN])
824 test_init
825 if test $outer_require_in_fn_diversion != yes; then AS_EXIT([1]); fi
826 if test $nested_require_in_fn_diversion != no; then AS_EXIT([1]); fi
829 AT_CHECK_M4SH
830 AT_CHECK([$CONFIG_SHELL ./script])
832 AT_CLEANUP
835 ## ------------------------------------ ##
836 ## AS_REQUIRE_SHELL_FN and m4_require.  ##
837 ## ------------------------------------ ##
839 # Hypothesis: M4sh expands the requirements of AS_REQUIRE_SHELL_FN
840 # in M4SH-INIT-FN.  This changed after Autoconf 2.63.
842 AT_SETUP([AS@&t@_REQUIRE_SHELL_FN and m4@&t@_require])
843 AT_KEYWORDS([m4sh])
845 AT_DATA_M4SH([script.as], [[dnl
846 AS_INIT
848 m4_defun([in_m4_sh_init], still_in_m4sh_init=yes)
849 m4_defun([not_in_m4_sh_init], still_in_m4sh_init=no)
851 m4_defun([error_if_emitted_in_m4sh_init], [
852   if test x$still_in_m4sh_init = xyes; then
853     AS_ERROR([requirement emitted in M4SH-INIT])
854   fi
857 m4_defun([TEST_FUNC_BODY], [
858 m4_require([error_if_emitted_in_m4sh_init])
859 : echo in shell function, with parameter = [$]1
863 m4_defun([test_init], [
864 AS_REQUIRE([in_m4_sh_init], , [M4SH-INIT-FN])
865 AS_REQUIRE_SHELL_FN([test_func], [], [TEST_FUNC_BODY])
866 AS_REQUIRE([not_in_m4_sh_init])
869 test_init
870 test_func parameter1
873 AT_CHECK_M4SH
874 AT_CHECK([$CONFIG_SHELL ./script])
876 AT_CLEANUP
879 ## -------------- ##
880 ## AS_HELP_STRING ##
881 ## -------------- ##
883 AT_SETUP([AS@&t@_HELP_STRING])
884 AT_KEYWORDS([m4sh m4@&t@_text_wrap m4@&t@_expand])
886 AT_DATA_M4SH([script.as],
887 [[AS_INIT
889 echo "AS_HELP_STRING([--an-option],[some text])"
890 echo "AS_HELP_STRING([--another-much-longer-option],
891 [some other text which should wrap at our default of 80 characters.])"
892 echo "AS_HELP_STRING([--fooT=barT], [foo bar])"
893 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@], [foo bar])"
894 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@123456789], [foo bar])"
895 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@1234567890], [foo bar])"
896 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@12345678901], [foo bar])"
897 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@123456789012], [foo bar])"
898 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@1234567890123], [foo bar])"
899 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@],
900 [some other text which should wrap at our default of 80 characters.])"
901 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@123456789],
902 [some other text which should wrap at our default of 80 characters.])"
903 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@1234567890],
904 [some other text which should wrap at our default of 80 characters.])"
905 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@12345678901],
906 [some other text which should wrap at our default of 80 characters.])"
907 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@123456789012],
908 [some other text which should wrap at our default of 80 characters.])"
909 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@1234567890123],
910 [some other text which should wrap at our default of 80 characters.])"
911 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@],
912 [some other @<][:@ex@:][>@ which should wrap at our default of 80 characters.])"
913 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@123456789],
914 [some other @<][:@ex@:][>@ which should wrap at our default of 80 characters.])"
915 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@1234567890],
916 [some other @<][:@ex@:][>@ which should wrap at our default of 80 characters.])"
917 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@12345678901],
918 [some other @<][:@ex@:][>@ which should wrap at our default of 80 characters.])"
919 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@123456789012],
920 [some other @<][:@ex@:][>@ which should wrap at our default of 80 characters.])"
921 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@1234567890123],
922 [some other @<][:@ex@:][>@ which should wrap at our default of 80 characters.])"
923 echo "AS_HELP_STRING([[--foo[=bar]]],
924 [some other t[]t which should wrap at our default of 80 characters.])"
925 echo "AS_HELP_STRING([[--foo[=bar]123456789]],
926 [some other t[]t which should wrap at our default of 80 characters.])"
927 echo "AS_HELP_STRING([[--foo[=bar]1234567890]],
928 [some other t[]t which should wrap at our default of 80 characters.])"
929 echo "AS_HELP_STRING([[--foo[=bar]12345678901]],
930 [some other t[]t which should wrap at our default of 80 characters.])"
931 echo "AS_HELP_STRING([[--foo[=bar]123456789012]],
932 [some other t[]t which should wrap at our default of 80 characters.])"
933 echo "AS_HELP_STRING([[--foo[=bar]1234567890123]],
934 [some other t[]t which should wrap at our default of 80 characters.])"
935 m4_define([mac], [MACRO])dnl
936 echo "AS_HELP_STRING([--mac], [mac])"
937 echo "AS_HELP_STRING([--o1, --o2], [two
938 options,        one  description])"
939 echo "AS_HELP_STRING([[[--o3, --o4]]], [comma inside literal quoting])"
940 echo "AS_HELP_STRING([--tune1], [check out the tuned formatting],
941 [            ])"
942 echo "AS_HELP_STRING([--tune2], [check out the tuned formatting],
943 [12])"
944 echo "AS_HELP_STRING([--tune3], [check out the tuned formatting],
945 [], [40])"
946 echo "AS_HELP_STRING([--tune4], [check out the tuned formatting],
947 [12], [40])"
950 AT_CHECK_M4SH
951 AT_CHECK([$CONFIG_SHELL ./script], [0],
952 [[  --an-option             some text
953   --another-much-longer-option
954                           some other text which should wrap at our default of
955                           80 characters.
956   --fooT=barT             foo bar
957   --foo[=bar]             foo bar
958   --foo[=bar]123456789    foo bar
959   --foo[=bar]1234567890   foo bar
960   --foo[=bar]12345678901  foo bar
961   --foo[=bar]123456789012 foo bar
962   --foo[=bar]1234567890123
963                           foo bar
964   --foo[=bar]             some other text which should wrap at our default of
965                           80 characters.
966   --foo[=bar]123456789    some other text which should wrap at our default of
967                           80 characters.
968   --foo[=bar]1234567890   some other text which should wrap at our default of
969                           80 characters.
970   --foo[=bar]12345678901  some other text which should wrap at our default of
971                           80 characters.
972   --foo[=bar]123456789012 some other text which should wrap at our default of
973                           80 characters.
974   --foo[=bar]1234567890123
975                           some other text which should wrap at our default of
976                           80 characters.
977   --foo[=bar]             some other [ex] which should wrap at our default of
978                           80 characters.
979   --foo[=bar]123456789    some other [ex] which should wrap at our default of
980                           80 characters.
981   --foo[=bar]1234567890   some other [ex] which should wrap at our default of
982                           80 characters.
983   --foo[=bar]12345678901  some other [ex] which should wrap at our default of
984                           80 characters.
985   --foo[=bar]123456789012 some other [ex] which should wrap at our default of
986                           80 characters.
987   --foo[=bar]1234567890123
988                           some other [ex] which should wrap at our default of
989                           80 characters.
990   --foo[=bar]             some other t[]t which should wrap at our default of
991                           80 characters.
992   --foo[=bar]123456789    some other t[]t which should wrap at our default of
993                           80 characters.
994   --foo[=bar]1234567890   some other t[]t which should wrap at our default of
995                           80 characters.
996   --foo[=bar]12345678901  some other t[]t which should wrap at our default of
997                           80 characters.
998   --foo[=bar]123456789012 some other t[]t which should wrap at our default of
999                           80 characters.
1000   --foo[=bar]1234567890123
1001                           some other t[]t which should wrap at our default of
1002                           80 characters.
1003   --MACRO                 mac
1004   --o1, --o2              two options, one description
1005   [--o3, --o4]            comma inside literal quoting
1006   --tune1   check out the tuned formatting
1007   --tune2   check out the tuned formatting
1008   --tune3                 check out the
1009                           tuned
1010                           formatting
1011   --tune4   check out the tuned
1012             formatting
1015 AT_CLEANUP
1018 ## ------------------- ##
1019 ## AS_IF and AS_CASE.  ##
1020 ## ------------------- ##
1022 AT_SETUP([AS@&t@_IF and AS@&t@_CASE])
1023 AT_KEYWORDS([m4sh m4@&t@_map_args_pair])
1025 AT_DATA_M4SH([script.as], [[dnl
1026 AS_INIT
1027 # Syntax checks: cope with empty arguments.
1028 AS_IF([:], [], [echo wrong])
1029 AS_IF([:], [echo one], [echo wrong])
1030 AS_IF([false], [echo wrong], [echo two])
1031 AS_IF([false], [echo wrong])
1032 # n-ary version
1033 AS_IF([false], [echo wrong],
1034       [:], [echo three])
1035 AS_IF([false], [echo wrong],
1036       [:], [echo four],
1037       [echo wrong])
1038 AS_IF([false], [echo wrong],
1039       [false], [echo wrong])
1040 AS_IF([false], [echo wrong],
1041       [false], [echo wrong],
1042       [echo five])
1043 AS_IF([false], [echo wrong],
1044       [false], [echo wrong],
1045       [:], [echo six],
1046       [echo wrong])
1047 AS_CASE([foo])
1048 AS_CASE([foo], [echo seven])
1049 AS_CASE([foo],
1050         [foo], [echo eight],
1051         [echo wrong])
1052 AS_CASE([foo],
1053         [foo], [echo nine],
1054         [*],   [echo wrong])
1055 AS_CASE([foo],
1056         [bar], [echo wrong],
1057         [foo], [echo ten],
1058         [*],   [echo wrong])
1060 # check for nesting, lists, and side effects, and quoting robustness
1061 empty=
1062 AS_IF([AS_IF([$empty], [echo eleven])]) && AS_CASE([foo]) && echo twelve
1063 rm -f file
1064 AS_IF([touch file; false]) && echo thirteen
1065 test -f file && echo fourteen
1066 rm -f file
1067 AS_CASE([`touch file; false`]) && test -f file && echo fifteen
1068 dnl The next line is badly underquoted; don't intentionally copy this style.
1069 AS_CASE([foo], [foo], m4_do(AS_CASE([bar], [bar], [echo sixteen])))
1070 dnl Handle blank arguments.
1071 AS_IF([false], [:], [ ]) && AS_CASE([foo], [foo], []
1072 ) && echo seventeen
1073 m4_define([empty])AS_IF([:], [empty]
1074 ) && AS_CASE([foo], [foo], [empty]) && echo eighteen
1075 dnl We can't handle AS_IF([false], [:], [empty]) unless m4_expand is
1076 dnl taught how to handle m4_require.  The user is responsible for
1077 dnl avoiding the syntax error in that case.
1079 # check that require works correctly
1080 m4_for([n], 1, 9, [],
1081 [m4_defun([FOO]n, [foo]n[=]n)dnl
1082 m4_defun([BAR]n,
1083          [m4_require([FOO]]n[)dnl
1084 bar]n[=]n)[]dnl
1087 AS_IF([:], [BAR1])
1088 echo "foo1=$foo1 bar1=$bar1"
1089 AS_IF([:], [], [BAR2])
1090 echo "foo2=$foo2 bar2=$bar2"
1091 AS_IF([false], [BAR3])
1092 echo "foo3=$foo3 bar3=$bar3"
1093 AS_IF([false], [], [BAR4])
1094 echo "foo4=$foo4 bar4=$bar4"
1095 AS_CASE([x], [x], [BAR5])
1096 echo "foo5=$foo5 bar5=$bar5"
1097 AS_CASE([x], [y], [BAR6])
1098 echo "foo6=$foo6 bar6=$bar6"
1099 AS_CASE([x],
1100         [x], [:],
1101         [BAR7])
1102 echo "foo7=$foo7 bar7=$bar7"
1103 AS_CASE([x],
1104         [y], [:],
1105         [BAR8])
1106 echo "foo8=$foo8 bar8=$bar8"
1107 AS_CASE([x],
1108         [y], [:],
1109         [x], [BAR9])
1110 echo "foo9=$foo9 bar9=$bar9"
1113 AT_CHECK_M4SH
1114 AT_CHECK([$CONFIG_SHELL ./script], [0], [[one
1116 three
1117 four
1118 five
1120 seven
1121 eight
1122 nine
1124 eleven
1125 twelve
1126 thirteen
1127 fourteen
1128 fifteen
1129 sixteen
1130 seventeen
1131 eighteen
1132 foo1=1 bar1=1
1133 foo2=2 bar2=
1134 foo3=3 bar3=
1135 foo4=4 bar4=4
1136 foo5=5 bar5=5
1137 foo6=6 bar6=
1138 foo7=7 bar7=
1139 foo8=8 bar8=8
1140 foo9=9 bar9=9
1143 dnl stress test for large number of conditionals
1144 dnl too large, and we start tickling shell bugs
1145 m4_pushdef([limit], [1000])dnl
1146 AT_DATA_M4SH([script.as], [[dnl
1147 AS_INIT
1148 AS_IF(m4_shift(m4_for([i], [1], ]limit[, [], [, test $[1] = i, echo i])))
1149 AS_IF(m4_shift(m4_for([i], [1], ]limit[, [], [, test $[1] = i, echo i])),
1150       [echo default])
1151 AS_CASE([$[1]]m4_for([i], [1], ]limit[, [], [, i, echo i]))
1152 AS_CASE([$[1]]m4_for([i], [1], ]limit[, [], [, i, echo i]), [echo default])
1155 dnl Add --force so autom4te doesn't think `script' is still up to date.
1156 AT_CHECK_M4SH([--force])
1157 AT_CHECK([$CONFIG_SHELL ./script 1], [0], [[1
1162 AT_CHECK([$CONFIG_SHELL ./script limit], [0], [limit
1163 limit
1164 limit
1165 limit
1167 AT_CHECK([$CONFIG_SHELL ./script default], [0], [[default
1168 default
1170 m4_popdef([limit])
1172 AT_CLEANUP
1175 ## -------- ##
1176 ## AS_FOR.  ##
1177 ## -------- ##
1179 AT_SETUP([AS@&t@_FOR])
1180 AT_KEYWORDS([m4sh])
1182 AT_DATA_M4SH([script.as], [[dnl
1183 AS_INIT
1185 # Simple checks.
1186 AS_FOR([m4var], [shvar], [a],
1187 [echo "m4var $shvar"])
1188 AS_FOR([m4var], [shvar], [b c],
1189 [echo "m4var $shvar"])
1190 list='d e'
1191 AS_FOR([m4var], [shvar], [$list],
1192 [echo "m4var $shvar"])
1193 AS_FOR([m4var], [shvar], ["$list"],
1194 [echo "m4var $shvar"])
1195 AS_FOR([m4var], [shvar], ['$list'],
1196 [echo "m4var $shvar"])
1197 AS_FOR([m4var], [shvar], [\'],
1198 [echo "m4var $shvar"])
1200 # Syntax checks: cope with empty/blank arguments.
1201 set f g
1202 AS_FOR([], [shvar], [],
1203 [echo "m4_defn([]) $shvar"])
1204 rm -f file
1205 AS_FOR([], [shvar], [`touch file`])
1206 test -f file || exit 1
1207 AS_FOR([], [shvar], [], [ ])
1208 m4_define([empty])AS_FOR([], [shvar], [], [empty])
1210 # Check that break works.
1211 while :
1213   AS_FOR([m4var], [shvar], [h i],
1214     [echo "m4var"; break 2])
1215   exit 1
1216 done
1217 while :
1219   AS_FOR([m4var], [shvar], [j],
1220     [echo "m4var"; break 2])
1221   exit 1
1222 done
1225 AT_CHECK_M4SH
1226 AT_CHECK([$CONFIG_SHELL ./script], [0], [[a a
1227 b b
1228 c c
1229 d d
1230 e e
1231 d e d e
1232 $list $list
1233 ' '
1234 f f
1235 g g
1240 AT_CLEANUP
1243 ## --------------- ##
1244 ## AS_LITERAL_IF.  ##
1245 ## --------------- ##
1247 AT_SETUP([AS@&t@_LITERAL_IF])
1248 AT_KEYWORDS([m4sh AS@&t@_LITERAL_WORD_IF AS@&t@_LITERAL_HEREDOC_IF])
1250 AT_DATA_M4SH([script.as], [[dnl
1251 AS_INIT
1252 echo AS_LITERAL_IF([lit], [ok], [ERR]) 1
1253 echo AS_LITERAL_IF([l-/.it], [ok], [ERR]) 2
1254 echo AS_LITERAL_IF([l''it], [ERR], [ok]) 3
1255 echo AS_LITERAL_IF([l$it], [ERR], [ok]) 4
1256 echo AS_LITERAL_IF([l$it], [ERR1], [ERR2], [ok]) 5
1257 echo AS_LITERAL_IF([l${it}], [ERR1], [ERR2], [ok]) 6
1258 echo AS_LITERAL_IF([l`case a in b) ;; esac`it], [ERR], [ok]) 7
1259 echo AS_LITERAL_IF([l`case a in b) ;; esac`it], [ERR1], [ok], [ERR2]) 8
1260 m4_define([mac], [l-/.it])
1261 echo AS_LITERAL_IF([mac], [ok], [ERR]) 9
1262 echo AS_LITERAL_IF([mac($, ``)], [ok], [ERR]) 10
1263 m4_define([mac], [l$it])
1264 echo AS_LITERAL_IF([mac], [ERR], [ok]) 11
1265 echo AS_LITERAL_IF([mac], [ERR1], [ERR2], [ok]) 12
1266 m4_define([mac], [l``it])
1267 echo AS_LITERAL_IF([mac], [ERR], [ok]) 13
1268 echo AS_LITERAL_IF([mac], [ERR1], [ok], [ERR2]) 14
1269 echo AS_LITERAL_IF([    a ][
1270 b], [ok], [ERR]) 15
1271 echo AS_LITERAL_WORD_IF([       a ][
1272 b], [ERR], [ok]) 16
1273 echo AS_LITERAL_HEREDOC_IF([    a ][
1274 b], [ok], [ERR]) 17
1275 echo AS_LITERAL_IF([(a)], [ERR], [ok]) 18
1276 echo AS_LITERAL_WORD_IF([(a)], [ERR], [ok]) 19
1277 echo AS_LITERAL_HEREDOC_IF([(a)], [ok], [ERR]) 20
1278 echo AS_LITERAL_IF([@S|@a], [ERR], [ok]) 21
1279 echo AS_LITERAL_WORD_IF([@S|@a], [ERR], [ok]) 22
1280 echo AS_LITERAL_HEREDOC_IF([@S|@a], [ERR], [ok]) 23
1281 echo AS_LITERAL_IF([${a+b}], [ERR1], [ok], [ERR2]) 24
1282 echo AS_LITERAL_IF([${a=b}], [ERR1], [ok], [ERR2]) 25
1283 echo AS_LITERAL_IF([a+b], [ok], [ERR1], [ERR2]) 26
1284 echo AS_LITERAL_IF([a=b], [ok], [ERR1], [ERR2]) 27
1287 AT_CHECK_M4SH
1288 AT_CHECK([$CONFIG_SHELL ./script], [],
1289 [[ok 1
1290 ok 2
1291 ok 3
1292 ok 4
1293 ok 5
1294 ok 6
1295 ok 7
1296 ok 8
1297 ok 9
1298 ok 10
1299 ok 11
1300 ok 12
1301 ok 13
1302 ok 14
1303 ok 15
1304 ok 16
1305 ok 17
1306 ok 18
1307 ok 19
1308 ok 20
1309 ok 21
1310 ok 22
1311 ok 23
1312 ok 24
1313 ok 25
1314 ok 26
1315 ok 27
1318 AT_CLEANUP
1321 ## --------------------- ##
1322 ## AS_TR_SH, AS_TR_CPP.  ##
1323 ## --------------------- ##
1325 AT_SETUP([AS@&t@_TR_SH and AS@&t@_TR_CPP])
1327 AT_DATA_M4SH([script.as], [[dnl
1328 AS_INIT
1329 m4_define([abc], [hI])m4_define([ABC], [Hi])
1330 m4_define([hi], [oops])m4_define([HI], [OOPS])
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_SH([[abc]]) AS_TR_SH([[aBc]]) AS_TR_SH([[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 AS_TR_CPP([[abc]]) AS_TR_CPP([[aBc]]) AS_TR_CPP([[ABC]])
1337 echo ===
1338 [var=abc vAr=aBc VAR=ABC]
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_SH([[$var]]) AS_TR_SH([[$vAr]]) AS_TR_SH([[$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 AS_TR_CPP([[$var]]) AS_TR_CPP([[$vAr]]) AS_TR_CPP([[$VAR]])
1345 echo ===
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_SH([[`echo abc`]]) AS_TR_SH([[`echo aBc`]]) AS_TR_SH([[`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 AS_TR_CPP([[`echo abc`]]) AS_TR_CPP([[`echo aBc`]]) AS_TR_CPP([[`echo ABC`]])
1352 echo ===
1353 # start here
1354 echo AS_TR_SH([a.b/c+*-=])
1355 echo AS_TR_CPP([a.b/c+*-=])
1356 var=a.b/c+*-=
1357 echo AS_TR_SH([$var])
1358 echo AS_TR_CPP([$var])
1359 m4_define([macro], [a.b/c+*-=])
1360 echo AS_TR_SH([macro])
1361 echo AS_TR_CPP([macro])
1364 AT_CHECK_M4SH
1365 AT_CHECK([$CONFIG_SHELL ./script], [],
1366 [[hI aBc Hi
1367 hI aBc Hi
1368 abc aBc ABC
1369 HI ABC HI
1370 HI ABC HI
1371 ABC ABC ABC
1373 abc aBc ABC
1374 abc aBc ABC
1375 abc aBc ABC
1376 ABC ABC ABC
1377 ABC ABC ABC
1378 ABC ABC ABC
1380 hI aBc Hi
1381 hI aBc Hi
1382 abc aBc ABC
1383 HI ABC HI
1384 HI ABC HI
1385 ABC ABC ABC
1387 a_b_cpp__
1388 A_B_C_P__
1389 a_b_cpp__
1390 A_B_C_P__
1391 a_b_cpp__
1392 A_B_C_P__
1395 dnl Check that of the last 6 macros, only 2 needed command substitution.
1396 dnl This test abuses our knowledge of m4sh internals a bit; oh well.
1397 AT_CHECK([sed -n '/start here/,$ {
1398 /`.*`/p
1399 }' script | wc -l], [], [[2
1402 AT_CLEANUP
1405 ## ---------- ##
1406 ## AS_VAR_*.  ##
1407 ## ---------- ##
1409 AT_SETUP([AS@&t@_VAR basics])
1410 AT_KEYWORDS([m4sh AS@&t@_VAR_COPY AS@&t@_VAR_SET AS@&t@_VAR_GET])
1411 AT_KEYWORDS([AS@&t@_VAR_TEST_SET AS@&t@_VAR_SET_IF AS@&t@_VAR_IF])
1412 AT_KEYWORDS([AS@&t@_VAR_PUSHDEF AS@&t@_VAR_POPDEF])
1414 AT_DATA_M4SH([script.as], [[dnl
1415 AS_INIT
1416  m4_define([with], [WITH])
1417 # Literals.
1418 dnl AS_VAR_SET_IF also covers AS_VAR_TEST_SET
1419 AS_VAR_SET_IF([foo], [echo oops]) && echo ok
1420 AS_VAR_IF([foo], [], [echo ok], [echo oops])
1421 foo=
1422 AS_VAR_SET_IF([foo], [echo ok])
1423 AS_VAR_SET([foo], ['\a  "weird" `value` with; $fun '\''characters
1424 ']) # 'font-lock
1425 AS_VAR_COPY([bar], [foo])
1426 AS_ECHO(["$bar-"])
1427 AS_ECHO(["AS_VAR_GET([foo])-"])
1428 AS_VAR_SET_IF([foo], [echo ok], [echo oops])
1429 AS_VAR_IF([foo], [string], [echo oops]) && echo ok
1430 AS_VAR_PUSHDEF([tmp], [foo])
1431 AS_VAR_IF([tmp], ['\a  "weird" `value` with; $fun '\''characters
1432 '], [echo ok], [echo oops]) # 'font-lock
1433 AS_VAR_POPDEF([tmp])
1434 m4_ifdef([tmp], [echo oops])
1436 # Indirects via shell vars.
1437 echo '===='
1438 num=1
1439 AS_VAR_SET_IF([foo$num], [echo oops]) && echo ok
1440 AS_VAR_IF([foo$num], [], [echo ok], [echo oops])
1441 foo1=
1442 AS_VAR_SET_IF([foo$num], [echo ok])
1443 AS_VAR_SET([foo$num], ['\a  "weird" `value` with; $fun '\''characters
1444 ']) # 'font-lock
1445 AS_VAR_COPY([bar], [foo$num])
1446 num=2
1447 AS_VAR_COPY([foo$num], [bar])
1448 AS_ECHO(["$foo2-"])
1449 AS_ECHO(["AS_VAR_GET([foo$num])-"])
1450 AS_VAR_SET_IF([foo$num], [echo ok], [echo oops])
1451 AS_VAR_IF([foo$num], [string], [echo oops]) && echo ok
1452 AS_VAR_PUSHDEF([tmp], [foo$num])
1453 AS_VAR_IF([tmp], ['\a  "weird" `value` with; $fun '\''characters
1454 '], [echo ok], [echo oops]) # 'font-lock
1455 AS_VAR_POPDEF([tmp])
1456 m4_ifdef([tmp], [echo oops])
1458 # Indirects via command substitution.
1459 echo '===='
1460 AS_VAR_SET_IF([`echo foo3`], [echo oops]) && echo ok
1461 AS_VAR_IF([`echo foo3`], [], [echo ok], [echo oops])
1462 foo3=
1463 AS_VAR_SET_IF([`echo foo3`], [echo ok])
1464 AS_VAR_SET([`echo foo3`], ['\a  "weird" `value` with; $fun '\''characters
1465 ']) # 'font-lock
1466 AS_VAR_COPY([bar], [`echo foo3`])
1467 num=2
1468 AS_VAR_COPY([`echo foo4`], [bar])
1469 AS_ECHO(["$foo4-"])
1470 AS_ECHO(["AS_VAR_GET([`echo foo4`])-"])
1471 AS_VAR_SET_IF([`echo foo4`], [echo ok], [echo oops])
1472 AS_VAR_IF([`echo foo4`], [string], [echo oops]) && echo ok
1473 AS_VAR_PUSHDEF([tmp], [`echo foo4`])
1474 AS_VAR_IF([tmp], ['\a  "weird" `value` with; $fun '\''characters
1475 '], [echo ok], [echo oops]) # 'font-lock
1476 AS_VAR_POPDEF([tmp])
1477 m4_ifdef([tmp], [echo oops])
1481 AT_CHECK_M4SH
1482 AT_CHECK([$CONFIG_SHELL ./script], [], [[ok
1485 \a  "weird" `value` WITH; $fun 'characters
1487 \a  "weird" `value` WITH; $fun 'characters
1492 ====
1496 \a  "weird" `value` WITH; $fun 'characters
1498 \a  "weird" `value` WITH; $fun 'characters-
1502 ====
1506 \a  "weird" `value` WITH; $fun 'characters
1508 \a  "weird" `value` WITH; $fun 'characters-
1514 AT_CLEANUP
1517 ## --------------- ##
1518 ## AS_VAR_APPEND.  ##
1519 ## --------------- ##
1521 AT_SETUP([AS@&t@_VAR_APPEND])
1522 AT_KEYWORDS([m4sh AS@&t@_VAR])
1524 AT_DATA_M4SH([script.as], [[dnl
1525 AS_INIT
1526 # Literals.
1527 AS_VAR_APPEND([foo], ["hello,  "])
1528 AS_VAR_APPEND([foo], [world])
1529 echo "$foo"
1530 # Indirects via shell vars.
1531 num=1
1532 AS_VAR_APPEND([foo$num], ['hello,  '])
1533 AS_VAR_APPEND([foo$num], [`echo "world"`])
1534 echo "$foo1"
1535 # Indirects via command substitution.
1536 h=hello w=',  world'
1537 AS_VAR_APPEND([`echo foo2`], [${h}])
1538 AS_VAR_APPEND([`echo foo2`], ["$w"])
1539 echo "$foo2"
1542 AT_CHECK_M4SH
1543 AT_CHECK([$CONFIG_SHELL ./script], [],
1544 [[hello,  world
1545 hello,  world
1546 hello,  world
1549 AT_CLEANUP
1552 ## -------------- ##
1553 ## AS_VAR_ARITH.  ##
1554 ## -------------- ##
1556 AT_SETUP([AS@&t@_VAR_ARITH])
1557 AT_KEYWORDS([m4sh AS@&t@_VAR])
1559 AT_DATA_M4SH([script.as], [[dnl
1560 AS_INIT
1561 # Literals.
1562 AS_VAR_ARITH([foo], [1 + 1])
1563 echo "$foo"
1564 # Indirects via shell vars.
1565 num=1
1566 AS_VAR_ARITH([foo$num], [\( 2 + 3 \) \* 4])
1567 echo "$foo1"
1568 # Indirects via command substitution.
1569 AS_VAR_ARITH([`echo foo2`], [0 + -2 + $foo1 / 2])
1570 echo "$foo2"
1573 AT_CHECK_M4SH
1574 AT_CHECK([$CONFIG_SHELL ./script], [],
1580 AT_CLEANUP
1583 ## ----------------- ##
1584 ## AS_INIT cleanup.  ##
1585 ## ----------------- ##
1587 AT_SETUP([AS@&t@_INIT cleanup])
1588 AT_KEYWORDS([m4sh m4@&t@_wrap m4@&t@_wrap_lifo])
1590 AT_DATA_M4SH([script.as], [[dnl
1591 dnl Registered before AS_INIT's cleanups
1592 m4_wrap([echo cleanup 1
1594 m4_pushdef([_AS_SHELL_FN_SPY])dnl neutralize the spy, we don't care about it
1595 AS_INIT
1596 dnl Registered after AS_INIT's cleanups, thus goes to KILL diversion
1597 m4_wrap([echo cleanup 2
1598 dnl However, nested wraps and diversions can still be used
1599 dnl Also, test wrapping text that looks like parameter reference
1600 m4_wrap([echo cleanup 3
1601 m4_divert_text([M4SH-INIT], [m4_define([foo], [$1])dnl
1602 echo prep foo([4])
1603 ])])])
1604 dnl Registered before AS_INIT's cleanups
1605 m4_wrap_lifo([echo cleanup 5
1607 echo body
1610 AT_CHECK_M4SH
1611 AT_CHECK([$CONFIG_SHELL ./script], [], [[prep 4
1612 body
1613 cleanup 5
1614 cleanup 1
1617 AT_CLEANUP
1620 ## ------------------- ##
1621 ## AS_INIT_GENERATED.  ##
1622 ## ------------------- ##
1624 AT_SETUP([AS@&t@_INIT_GENERATED])
1625 AT_KEYWORDS([AS@&t@_MESSAGE AS@&t@_MESSAGE_LOG_FD])
1627 dnl First run, no logging, tests shell selection
1628 AT_DATA_M4SH([script.as], [[dnl
1629 AS_INIT
1630 AS_INIT_GENERATED([child], [echo hello from child])
1631 cat >>child <<\EOF
1632 AS_ECHO(["SHELL=$SHELL"])
1634 echo hello from parent
1635 AS_ECHO(["SHELL=$SHELL"])
1638 AT_CHECK_M4SH
1639 AT_CHECK([$CONFIG_SHELL ./script], [0], [stdout])
1640 AT_CHECK([grep 'SHELL=.' stdout], [0], [ignore])
1641 sed s/parent/child/ <stdout >expout
1642 AT_CHECK([./child], [0], [expout])
1643 SHELL=/bogus
1644 export SHELL
1645 cp stdout expout
1646 mv child child.bak
1647 AT_CHECK([$CONFIG_SHELL ./script], [0], [expout])
1648 AT_CHECK([cmp child child.bak])
1649 AT_CHECK([grep 'SHELL=.' stdout], [0], [ignore])
1650 sed s/parent/child/ <stdout >expout
1651 AT_CHECK([./child], [0], [expout])
1654 dnl Second run, with logging from parent and child, tests fd handling
1655 AT_DATA_M4SH([script.as], [[dnl
1656 AS_INIT
1657 child=${1-child}
1658 m4_define([AS_MESSAGE_LOG_FD], [5])
1659 exec AS_MESSAGE_LOG_FD>log
1660 AS_INIT_GENERATED([$child], [echo hello1 from $child]) || AS_EXIT([1])
1661 cat >>$child <<\EOF
1662 m4_pushdef([AS_MESSAGE_LOG_FD])
1663 AS_MESSAGE([hello2 from ${child}child])
1664 m4_popdef([AS_MESSAGE_LOG_FD])
1665 exec AS_MESSAGE_LOG_FD>>log
1666 AS_MESSAGE([hello3 from child])
1668 AS_MESSAGE([hello from parent])
1669 dnl close log in parent before spawning child, for mingw
1670 exec AS_MESSAGE_LOG_FD>&-
1671 ./$child
1674 rm -f script
1675 AT_CHECK_M4SH
1676 AT_CHECK([$CONFIG_SHELL ./script], [0], [[script: hello from parent
1677 hello1 from child
1678 child: hello2 from child
1679 child: hello3 from child
1681 AT_CHECK([[sed 's,:[0-9][0-9]*:,:0:,' log]], [0],
1682 [[script:0: hello from parent
1683 child:0: hello3 from child
1686 # Force write error creating a file on stdout
1687 if test -w /dev/full && test -c /dev/full; then
1688   AT_CHECK([$CONFIG_SHELL ./script /dev/full], [1], [ignore], [ignore])
1691 AT_CLEANUP
1694 ## --------------- ##
1695 ## AS_MESSAGE_FD.  ##
1696 ## --------------- ##
1698 AT_SETUP([AS@&t@_MESSAGE_FD])
1699 AT_KEYWORDS([AS@&t@_MESSAGE AS@&t@_MESSAGE_LOG_FD AS@&t_ORIGINAL_STDIN_FD])
1700 AT_KEYWORDS([AS@&t@_LINENO_PUSH])
1702 AT_DATA_M4SH([script.as], [[dnl
1703 AS_INIT
1704 m4_define([AS_ORIGINAL_STDIN_FD], [5])
1705 m4_define([AS_MESSAGE_LOG_FD], [6])
1706 m4_define([AS_MESSAGE_FD], [7])
1707 exec AS_ORIGINAL_STDIN_FD<&0 </dev/null AS_MESSAGE_LOG_FD>log
1708 if test $[#] -gt 0; then
1709   exec AS_MESSAGE_FD>/dev/null
1710 else
1711   exec AS_MESSAGE_FD>&1
1713 AS_LINENO_PUSH([100])
1714 cat # tests that stdin is neutralized
1715 AS_MESSAGE([hello world])
1716 cat <&AS_ORIGINAL_STDIN_FD
1719 AT_CHECK_M4SH
1720 AT_CHECK([echo goodbye | $CONFIG_SHELL ./script], [0],
1721 [[script: hello world
1722 goodbye
1724 AT_CHECK([cat log], [0],
1725 [[script:100: hello world
1727 rm log
1728 AT_CHECK([echo goodbye | $CONFIG_SHELL ./script silent], [0],
1729 [[goodbye
1731 AT_CHECK([cat log], [0],
1732 [[script:100: hello world
1735 AT_CLEANUP
1738 ## --------------- ##
1739 ## _AS_CLEAN_DIR.  ##
1740 ## --------------- ##
1742 AT_SETUP([_AS@&t@_CLEAN_DIR])
1744 dnl ensure that we can erase all files in a directory.  Note that
1745 dnl _AS_CLEAN_DIR needs three globs to catch all these files.
1746 AT_DATA_M4SH([script.as], [[dnl
1747 AS_INIT
1748 # Unwritable subdirectories are common during 'make distcheck'.
1749 mkdir sub sub/unwritable || AS_ERROR([failed to mkdir])
1750 touch sub/unwritable/file || AS_ERROR([failed to touch])
1751 chmod a-wx sub/unwritable || AS_ERROR([failed to chmod])
1752 # Cygwin 1.5 can't touch 'sub/...', so make that file optional.
1753 touch sub/a sub/aa sub/aaa sub/.a sub/..a sub/.aa \
1754   || AS_ERROR([failed to touch])
1755 touch sub/... 2>/dev/null
1756 _AS_CLEAN_DIR([sub]) || AS_ERROR([failed to clean])
1757 # rmdir instead of 'rm -fr' here proves that we emptied sub.
1758 rmdir sub || AS_ERROR([failed to rmdir])
1761 AT_CHECK_M4SH
1762 AT_CHECK([$CONFIG_SHELL ./script])
1764 AT_CLEANUP
1767 ## -------- ##
1768 ## ECHO_C.  ##
1769 ## -------- ##
1771 AT_SETUP([ECHO_C])
1773 AT_DATA_M4SH([script.as], [[dnl
1774 AS_INIT
1775 _AS_PREPARE
1776 foo=`echo foobar`
1777 echo "$foo"
1780 AT_CHECK_M4SH
1781 AT_CHECK([$CONFIG_SHELL ./script], [], [foobar
1784 AT_CLEANUP