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])
28 AT_DATA_M4SH([script.as],
30 AS_WARN([*watch out*])dnl
32 if test x"$die" != x; then
33 AS_ERROR([you're dead])dnl
42 AT_CHECK([$CONFIG_SHELL ./script], [],
44 ]], [[script: WARNING: *watch out*
46 AT_CHECK([die=: $CONFIG_SHELL ./script], [1],
47 [], [[script: WARNING: *watch out*
48 script: error: you're dead
53 AT_DATA_M4SH([script.as],
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
67 exec AS_MESSAGE_LOG_FD>&-
71 AT_CHECK([$CONFIG_SHELL ./script], [],
73 ]], [[script: WARNING: *watch out*
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
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])
85 ## ---------------- ##
87 ## ---------------- ##
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
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],
117 m4@&t@_divert_text([], [
119 AS@&t@_UNSET([LINENO])
122 AS@&t@_LINENO_PREPARE
124 grep 'Line: .*$4' "$[0]" >/dev/null ||
125 AS@&t@_ERROR([cannot find original script])
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])
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])
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)],
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)],
157 AT_CHECK([sh ./test/test-2], 0, [expout])
162 ## ---------------------- ##
163 ## LINENO stack support. ##
164 ## ---------------------- ##
166 AT_SETUP([LINENO stack])
169 AT_DATA_M4SH([script.as],
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])
177 test $as_lineno = 9999 || AS_ERROR([bad as_lineno at depth 1])
179 test x${as_lineno+set} = xset && AS_ERROR([as_lineno set at depth 0])
185 AT_CHECK([$CONFIG_SHELL ./script])
194 # Output a framed one-line message.
195 AT_SETUP([AS@&t@_BOX])
198 AT_DATA_M4SH([script.as],
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]'
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 ## ,,,,,,,,,,,,,,,,,,,,,,, ##
236 # Strip path from file.
237 AT_SETUP([AS@&t@_BASENAME])
240 AT_DATA_M4SH([script.as],
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])
284 AT_CHECK([$CONFIG_SHELL ./script])
293 # Strip filename component.
294 AT_SETUP([AS@&t@_DIRNAME])
297 AT_DATA_M4SH([script.as],
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])
344 AT_CHECK([$CONFIG_SHELL ./script])
349 ## ---------------- ##
350 ## AS_SET_CATFILE. ##
351 ## ---------------- ##
353 AT_SETUP([AS@&t@_SET_CATFILE])
356 AT_DATA_M4SH([script.as],
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.
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'])
387 AT_CHECK([$CONFIG_SHELL ./script])
396 # Print literal strings, with/without newline.
397 AT_SETUP([AS@&t@_ECHO and AS@&t@_ECHO_N])
400 AT_DATA_M4SH([script.as],
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])
414 ECHO_TEST([---...---])
423 ECHO_TEST([\a\b\c\f\n\r\t\v\"\])
435 AT_CHECK([$CONFIG_SHELL ./script])
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],
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
458 dnl Solaris /bin/sh 'set -e' doesn't react to failed function calls
460 && { echo 'skipping rest of test: set -e support is lousy'; exit 77; }
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])
495 AT_SETUP([AS@&t@_MKDIR_P])
498 AT_DATA_M4SH([script.as],
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])
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])
515 AT_CHECK([$CONFIG_SHELL ./script])
522 ## -------------------- ##
523 ## AS_VERSION_COMPARE. ##
524 ## -------------------- ##
526 # Three-way version comparison.
527 AT_SETUP([AS@&t@_VERSION_COMPARE])
530 AT_DATA_M4SH([script.as],
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])
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.
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
553 for test2 in $tst_svc_expect; do
554 VERSION_COMPARE_TEST([$test1], <, [$test2])
562 AT_CHECK([$CONFIG_SHELL ./script])
576 AT_DATA_M4SH([script.as],
579 test "$as_me" = script || AS_ECHO([["incorrect value of \$as_me: $as_me"]])
583 AT_CHECK([$CONFIG_SHELL ./script])
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])
600 AT_DATA_M4SH([script.as],
603 case 'with!two!bangs' in
605 *) AS_ERROR([[`*[!a-z]*' didn't match `with!two!bangs']]);;
609 *[[!a-z]]*) AS_ERROR([[`*[!a-z]*' matched `without']]);;
614 AT_CHECK([$CONFIG_SHELL ./script])
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])
628 AT_DATA_M4SH([script.as],
634 case ${a:-x}${b:-y}${c:-z} in
638 case ${a-x}${b-y}${c-z} in
643 case ${a+x}${b+y}${c+z} in
647 case ${a:+x}${b:+y}${c:+z} in
652 case ${a=x}${b=y}${c=z} in
657 case ${a:=x}${b:=y}${c:=z} in
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
680 AT_CHECK([$CONFIG_SHELL ./script])
685 ## ------------------- ##
686 ## Functions Support. ##
687 ## ------------------- ##
689 # All m4sh scripts require function support.
691 AT_SETUP([Functions Support])
694 AT_DATA_M4SH([script.as],
710 if func_success; then
711 if func_failure; then
712 AS_ERROR([func_failure passed])
715 AS_ERROR([func_success failed])
720 AT_CHECK([$CONFIG_SHELL ./script])
727 ## ------------------------------ ##
728 ## Functions and return Support. ##
729 ## ------------------------------ ##
731 # All m4sh scripts require working return within functions.
733 AT_SETUP([Functions and return Support])
736 AT_DATA_M4SH([script.as],
748 if func_success; then
749 if func_failure; then
750 AS_ERROR([func_failure passed])
753 AS_ERROR([func_success failed])
758 AT_CHECK([$CONFIG_SHELL ./script])
763 ## --------------------------- ##
764 ## Nested AS_REQUIRE_SHELL_FN. ##
765 ## --------------------------- ##
767 # Hypothesis: M4sh expands nested AS_REQUIRE_SHELL_FN
770 AT_SETUP([Nested AS@&t@_REQUIRE_SHELL_FN])
773 AT_DATA_M4SH([script.as], [[dnl
774 m4_define([INIT], [oops])dnl
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])
791 AT_CHECK([$CONFIG_SHELL ./script])
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])
806 AT_DATA_M4SH([script.as], [[dnl
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])
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
829 AT_CHECK([$CONFIG_SHELL ./script])
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])
844 AT_DATA_M4SH([script.as], [[dnl
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])
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])
873 AT_CHECK([$CONFIG_SHELL ./script])
882 AT_SETUP([AS@&t@_HELP_STRING])
883 AT_KEYWORDS([m4sh m4@&t@_text_wrap m4@&t@_expand])
885 AT_DATA_M4SH([script.as],
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],
941 echo "AS_HELP_STRING([--tune2], [check out the tuned formatting],
943 echo "AS_HELP_STRING([--tune3], [check out the tuned formatting],
945 echo "AS_HELP_STRING([--tune4], [check out the tuned formatting],
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
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
963 --foo[=bar] some other text which should wrap at our default of
965 --foo[=bar]123456789 some other text which should wrap at our default of
967 --foo[=bar]1234567890 some other text which should wrap at our default of
969 --foo[=bar]12345678901 some other text which should wrap at our default of
971 --foo[=bar]123456789012 some other text which should wrap at our default of
973 --foo[=bar]1234567890123
974 some other text which should wrap at our default of
976 --foo[=bar] some other [ex] which should wrap at our default of
978 --foo[=bar]123456789 some other [ex] which should wrap at our default of
980 --foo[=bar]1234567890 some other [ex] which should wrap at our default of
982 --foo[=bar]12345678901 some other [ex] which should wrap at our default of
984 --foo[=bar]123456789012 some other [ex] which should wrap at our default of
986 --foo[=bar]1234567890123
987 some other [ex] which should wrap at our default of
989 --foo[=bar] some other t[]t which should wrap at our default of
991 --foo[=bar]123456789 some other t[]t which should wrap at our default of
993 --foo[=bar]1234567890 some other t[]t which should wrap at our default of
995 --foo[=bar]12345678901 some other t[]t which should wrap at our default of
997 --foo[=bar]123456789012 some other t[]t which should wrap at our default of
999 --foo[=bar]1234567890123
1000 some other t[]t which should wrap at our default of
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
1010 --tune4 check out the tuned
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
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])
1032 AS_IF([false], [echo wrong],
1034 AS_IF([false], [echo wrong],
1037 AS_IF([false], [echo wrong],
1038 [false], [echo wrong])
1039 AS_IF([false], [echo wrong],
1040 [false], [echo wrong],
1042 AS_IF([false], [echo wrong],
1043 [false], [echo wrong],
1047 AS_CASE([foo], [echo seven])
1049 [foo], [echo eight],
1055 [bar], [echo wrong],
1059 # check for nesting, lists, and side effects, and quoting robustness
1061 AS_IF([AS_IF([$empty], [echo eleven])]) && AS_CASE([foo]) && echo twelve
1063 AS_IF([touch file; false]) && echo thirteen
1064 test -f file && echo fourteen
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], []
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
1082 [m4_require([FOO]]n[)dnl
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"
1101 echo "foo7=$foo7 bar7=$bar7"
1105 echo "foo8=$foo8 bar8=$bar8"
1109 echo "foo9=$foo9 bar9=$bar9"
1113 AT_CHECK([$CONFIG_SHELL ./script], [0], [[one
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
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])),
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
1166 AT_CHECK([$CONFIG_SHELL ./script default], [0], [[default
1178 AT_SETUP([AS@&t@_FOR])
1181 AT_DATA_M4SH([script.as], [[dnl
1185 AS_FOR([m4var], [shvar], [a],
1186 [echo "m4var $shvar"])
1187 AS_FOR([m4var], [shvar], [b c],
1188 [echo "m4var $shvar"])
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.
1201 AS_FOR([], [shvar], [],
1202 [echo "m4_defn([]) $shvar"])
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.
1212 AS_FOR([m4var], [shvar], [h i],
1213 [echo "m4var"; break 2])
1218 AS_FOR([m4var], [shvar], [j],
1219 [echo "m4var"; break 2])
1225 AT_CHECK([$CONFIG_SHELL ./script], [0], [[a a
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
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 ][
1270 echo AS_LITERAL_WORD_IF([ a ][
1272 echo AS_LITERAL_HEREDOC_IF([ a ][
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
1287 AT_CHECK([$CONFIG_SHELL ./script], [],
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
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]])
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]])
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`]])
1353 echo AS_TR_SH([a.b/c+*-=])
1354 echo AS_TR_CPP([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])
1364 AT_CHECK([$CONFIG_SHELL ./script], [],
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/,$ {
1398 }' script | wc -l], [], [[2
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
1415 m4_define([with], [WITH])
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])
1421 AS_VAR_SET_IF([foo], [echo ok])
1422 AS_VAR_SET([foo], ['\a "weird" `value` with; $fun '\''characters
1424 AS_VAR_COPY([bar], [foo])
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.
1438 AS_VAR_SET_IF([foo$num], [echo oops]) && echo ok
1439 AS_VAR_IF([foo$num], [], [echo ok], [echo oops])
1441 AS_VAR_SET_IF([foo$num], [echo ok])
1442 AS_VAR_SET([foo$num], ['\a "weird" `value` with; $fun '\''characters
1444 AS_VAR_COPY([bar], [foo$num])
1446 AS_VAR_COPY([foo$num], [bar])
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.
1459 AS_VAR_SET_IF([`echo foo3`], [echo oops]) && echo ok
1460 AS_VAR_IF([`echo foo3`], [], [echo ok], [echo oops])
1462 AS_VAR_SET_IF([`echo foo3`], [echo ok])
1463 AS_VAR_SET([`echo foo3`], ['\a "weird" `value` with; $fun '\''characters
1465 AS_VAR_COPY([bar], [`echo foo3`])
1467 AS_VAR_COPY([`echo foo4`], [bar])
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])
1481 AT_CHECK([$CONFIG_SHELL ./script], [], [[ok
1484 \a "weird" `value` WITH; $fun 'characters
1486 \a "weird" `value` WITH; $fun 'characters
1495 \a "weird" `value` WITH; $fun 'characters
1497 \a "weird" `value` WITH; $fun 'characters-
1505 \a "weird" `value` WITH; $fun 'characters
1507 \a "weird" `value` WITH; $fun 'characters-
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
1526 AS_VAR_APPEND([foo], ["hello, "])
1527 AS_VAR_APPEND([foo], [world])
1529 # Indirects via shell vars.
1531 AS_VAR_APPEND([foo$num], ['hello, '])
1532 AS_VAR_APPEND([foo$num], [`echo "world"`])
1534 # Indirects via command substitution.
1536 AS_VAR_APPEND([`echo foo2`], [${h}])
1537 AS_VAR_APPEND([`echo foo2`], ["$w"])
1542 AT_CHECK([$CONFIG_SHELL ./script], [],
1551 ## -------------- ##
1553 ## -------------- ##
1555 AT_SETUP([AS@&t@_VAR_ARITH])
1556 AT_KEYWORDS([m4sh AS@&t@_VAR])
1558 AT_DATA_M4SH([script.as], [[dnl
1561 AS_VAR_ARITH([foo], [1 + 1])
1563 # Indirects via shell vars.
1565 AS_VAR_ARITH([foo$num], [\( 2 + 3 \) \* 4])
1567 # Indirects via command substitution.
1568 AS_VAR_ARITH([`echo foo2`], [0 + -2 + $foo1 / 2])
1573 AT_CHECK([$CONFIG_SHELL ./script], [],
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
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
1603 dnl Registered before AS_INIT's cleanups
1604 m4_wrap_lifo([echo cleanup 5
1610 AT_CHECK([$CONFIG_SHELL ./script], [], [[prep 4
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
1629 AS_INIT_GENERATED([child], [echo hello from child])
1631 AS_ECHO(["SHELL=$SHELL"])
1633 echo hello from parent
1634 AS_ECHO(["SHELL=$SHELL"])
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])
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
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])
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>&-
1675 AT_CHECK([$CONFIG_SHELL ./script], [0], [[script: hello from parent
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])
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
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
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
1719 AT_CHECK([echo goodbye | $CONFIG_SHELL ./script], [0],
1720 [[script: hello world
1723 AT_CHECK([cat log], [0],
1724 [[script:100: hello world
1727 AT_CHECK([echo goodbye | $CONFIG_SHELL ./script silent], [0],
1730 AT_CHECK([cat log], [0],
1731 [[script:100: hello world
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
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])
1761 AT_CHECK([$CONFIG_SHELL ./script])
1772 AT_DATA_M4SH([script.as], [[dnl
1780 AT_CHECK([$CONFIG_SHELL ./script], [], [foobar