5 # Copyright (C) 2000-2017 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 <https://www.gnu.org/licenses/>.
20 ## --------------------------- ##
21 ## Re-exec with CONFIG_SHELL. ##
22 ## --------------------------- ##
24 AT_SETUP([No extra re-exec with CONFIG_SHELL])
25 AT_KEYWORDS([CONFIG_SHELL])
26 AT_DATA_M4SH([script.as],
28 dnl We have to muck with internal details to goad the script into
29 dnl thinking that the default shell is always good enough.
30 m4_define([_AS_DETECT_REQUIRED_BODY], [])dnl
31 m4_define([_AS_DETECT_SUGGESTED_BODY], [])dnl
36 AT_CHECK([CONFIG_SHELL=/bin/false ./script], [0], [], [])
37 AT_CHECK([test -f ok], [0])
42 AT_SETUP([Forced re-exec with CONFIG_SHELL])
43 AT_KEYWORDS([CONFIG_SHELL])
45 AT_DATA_M4SH([script.as],
46 [[m4_define([_AS_FORCE_REEXEC_WITH_CONFIG_SHELL], [yes])
52 # Calling the script simply 'script' could cause problems with
53 # Solaris /usr/xpg4/bin/sh in the invocation 'sh script' below.
58 echo 'Fake shell executed.'
68 AT_CHECK([CONFIG_SHELL=./fake-shell ./script2 1 2 4 8], [0],
76 AT_CHECK([test ! -f sentinel], [0])
77 test ! -f sentinel || rm -f sentinel # Cleanup for next test.
80 [CONFIG_SHELL=`pwd`/fake-shell sh script2 a 'b c' ' d e '],
88 AT_CHECK([test ! -f sentinel], [0])
89 test ! -f sentinel || rm -f sentinel # Cleanup for next test.
91 AT_CHECK([(PATH=`pwd`:$PATH; export PATH;
92 CONFIG_SHELL=fake-shell script2 '' '&' '!;*' '<($[]@%:@)>,' 'x
105 AT_CHECK([test ! -f sentinel], [0])
106 test ! -f sentinel || rm -f sentinel # Cleanup for next test.
110 AT_SETUP([Configure re-execs self with CONFIG_SHELL])
112 AT_DATA([configure.ac],
126 AT_CAPTURE_FILE([config.log])
127 # Export CONFIG_SITE to /dev/null to avoid spurious diffs in expected
129 AT_CHECK([env CONFIG_SITE=/dev/null CONFIG_SHELL=./cfg-sh ./configure],
131 # ./configure re-executed itself.
132 AT_CHECK([test -f cfg-sh-has-run], [0])
133 # And did that not to cause extra execution of later commands.
134 AT_CHECK([cat quux], [0], [foobar
141 ## ------------------- ##
142 ## AS_WARN, AS_ERROR. ##
143 ## ------------------- ##
145 AT_SETUP([AS@&t@_WARN and AS@&t@_ERROR])
149 AT_DATA_M4SH([script.as],
151 AS_WARN([*watch out*])dnl
153 if test x"$die" != x; then
154 AS_ERROR([you're dead])dnl
156 AS_ERROR([really])dnl
163 AT_CHECK([$CONFIG_SHELL ./script], [],
165 ]], [[script: WARNING: *watch out*
167 AT_CHECK([die=: $CONFIG_SHELL ./script], [1],
168 [], [[script: WARNING: *watch out*
169 script: error: you're dead
174 AT_DATA_M4SH([script.as],
176 m4_define([gone], [AS_ERROR([really])])
177 m4_define([AS_MESSAGE_LOG_FD], [5])
178 exec AS_MESSAGE_LOG_FD>log.txt
179 AS_WARN([*watch out*])dnl
181 if test x"$die" != x; then
182 AS_ERROR([you're dead])dnl
184 AS_ERROR([really])dnl
188 exec AS_MESSAGE_LOG_FD>&-
192 AT_CHECK([$CONFIG_SHELL ./script], [],
194 ]], [[script: WARNING: *watch out*
196 AT_CHECK([[grep 'script:[0-9]*: WARNING: \*watch out\*' log.txt]], [], [ignore])
197 AT_CHECK([die=: $CONFIG_SHELL ./script], [1],
198 [], [[script: WARNING: *watch out*
199 script: error: you're dead
201 AT_CHECK([[grep 'script:[0-9]*: WARNING: \*watch out\*' log.txt]], [], [ignore])
202 AT_CHECK([[grep 'script:[0-9]*: error: you'\''re dead' log.txt]], [], [ignore])
206 ## ---------------- ##
207 ## LINENO support. ##
208 ## ---------------- ##
213 # We cannot unset LINENO with Zsh, yet this test case relies on
214 # unsetting LINENO to compare its result when (i) LINENO is supported
215 # and when (ii) it is not.
216 # So just skip if the shell is ZSH.
217 AT_CHECK([test ${ZSH_VERSION+y} && exit 77], ignore)
219 # AT_DATA_LINENO(FILE-NAME,
220 # UNSET-LINENO = true | false, COUNTER, COUNTER-RE)
221 # ----------------------------------------------------------------
222 # Produce the FILE-NAME M4sh script which uses the COUNTER LINENO or
223 # _oline_, which we can recognized via COUNTER-RE. Unset LINENO is
226 # Use COUNTER, COUNTER-RE = [__LINENO__], [LINENO]
227 # or = [__OLINE__], [_oline__]
229 # instead of the obvious $LINENO and __oline__, because they would
230 # be replaced in the test suite itself, even before creating these
231 # scripts. For the same reason, grep for LINENO and _oline__ (sic).
233 # UNSET-LINENO is a shell condition to make sure the scripts have the
234 # same number of lines in the output, so that their outputs be identical.
235 m4_define([AT_DATA_LINENO],
238 m4@&t@_divert_text([], [
240 AS@&t@_UNSET([LINENO])
243 AS@&t@_LINENO_PREPARE
245 grep 'Line: .*$4' "$[0]" >/dev/null ||
246 AS@&t@_ERROR([cannot find original script])
249 # If occurrences of $LINENO or __@&t@oline__ were wanted, create them.
250 sed 's/__LINENO__/$''LINENO/g;s/__OLINE__/__''oline__/g' $1.tas >$1.as
251 AT_CHECK([autom4te -l m4sh $1.as -o $1])
254 # `_oline_', once processed and ran, produces our reference.
255 # We check that we find ourselves by looking at a string which is
256 # available only in the original script: `_oline_'.
257 AT_DATA_LINENO([reference], [false], [__OLINE__], [_oline__])
258 AT_CHECK([./reference], 0, [stdout])
263 # Now using a maybe-functioning LINENO, with different call conventions.
264 # Be sure to be out of the PATH.
265 AT_CHECK([mkdir test || exit 77])
267 AT_DATA_LINENO([test/test-1], [false], [__LINENO__], [LINENO])
268 AT_CHECK([./test/test-1], 0, [expout])
269 AT_CHECK([(PATH=test$PATH_SEPARATOR$PATH; export PATH; exec test-1)],
271 AT_CHECK([sh ./test/test-1], 0, [expout])
273 # Now using a disabled LINENO, with different call conventions.
274 AT_DATA_LINENO([test/test-2], [true], [__LINENO__], [LINENO])
275 AT_CHECK([./test/test-2], 0, [expout])
276 AT_CHECK([(PATH=test$PATH_SEPARATOR$PATH; export PATH; exec test-2)],
278 AT_CHECK([sh ./test/test-2], 0, [expout])
283 ## ---------------------- ##
284 ## LINENO stack support. ##
285 ## ---------------------- ##
287 AT_SETUP([LINENO stack])
290 AT_DATA_M4SH([script.as],
293 AS_LINENO_PUSH([9999])
294 test $as_lineno = 9999 || AS_ERROR([bad as_lineno at depth 1])
295 AS_LINENO_PUSH([8888])
296 test $as_lineno = 9999 || AS_ERROR([bad as_lineno at depth 2])
298 test $as_lineno = 9999 || AS_ERROR([bad as_lineno at depth 1])
300 test ${as_lineno+y} && AS_ERROR([as_lineno set at depth 0])
306 AT_CHECK([$CONFIG_SHELL ./script])
315 # Output a framed one-line message.
316 AT_SETUP([AS@&t@_BOX])
319 AT_DATA_M4SH([script.as],
322 AS_BOX([Send a simple message, to foobar@example.com])
323 AS_BOX([Send a simple message, to foobar@example.com], [$])
324 m4_define([msg], [$complex])
325 complex='Not quite as simple |$[1]'
332 AT_CHECK([sed -n '/ -\{44\} /,/ -\{44\} /p' script ]dnl
333 [| sed '1 s/.*## -/## -/; 3 s/- ##.*/- ##/'], [],
334 [[## -------------------------------------------- ##
335 ## Send a simple message, to foobar@example.com ##
336 ## -------------------------------------------- ##
339 AT_CHECK([$CONFIG_SHELL ./script], [], [[
340 ## -------------------------------------------- ##
341 ## Send a simple message, to foobar@example.com ##
342 ## -------------------------------------------- ##
343 ## $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ ##
344 ## Send a simple message, to foobar@example.com ##
345 ## $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ ##
346 ## ----------------------- ##
347 ## Not quite as simple |$1 ##
348 ## ----------------------- ##
349 ## ,,,,,,,,,,,,,,,,,,,,,,, ##
350 ## Not quite as simple |$1 ##
351 ## ,,,,,,,,,,,,,,,,,,,,,,, ##
357 # Strip path from file.
358 AT_SETUP([AS@&t@_BASENAME])
361 AT_DATA_M4SH([script.as],
364 m4_define([BASENAME_TEST],
365 [base=`AS_BASENAME([$1])`
366 test "$base" = "$2" ||
367 echo "basename($1) = $base instead of $2" >&2
369 base=`_AS_BASENAME_SED([$1])`
370 test "$base" = "$2" ||
371 echo "basename_sed($1) = $base instead of $2" >&2])
373 BASENAME_TEST([//1], [1])
374 BASENAME_TEST([/1], [1])
375 BASENAME_TEST([./1], [1])
376 BASENAME_TEST([../../2], [2])
377 BASENAME_TEST([//1/], [1])
378 BASENAME_TEST([/1/], [1])
379 BASENAME_TEST([./1/], [1])
380 BASENAME_TEST([../../2], [2])
381 BASENAME_TEST([//1/3], [3])
382 BASENAME_TEST([/1/3], [3])
383 BASENAME_TEST([./1/3], [3])
384 BASENAME_TEST([../../2/3], [3])
385 BASENAME_TEST([//1/3///], [3])
386 BASENAME_TEST([/1/3///], [3])
387 BASENAME_TEST([./1/3///], [3])
388 BASENAME_TEST([../../2/3///], [3])
389 BASENAME_TEST([//1//3/], [3])
390 BASENAME_TEST([/1//3/], [3])
391 BASENAME_TEST([./1//3/], [3])
392 BASENAME_TEST([a.c], [a.c])
393 BASENAME_TEST([a.c/], [a.c])
394 BASENAME_TEST([/a.c/], [a.c])
395 BASENAME_TEST([/1/a.c], [a.c])
396 BASENAME_TEST([/1/a.c/], [a.c])
397 BASENAME_TEST([/1/../a.c], [a.c])
398 BASENAME_TEST([/1/../a.c/], [a.c])
399 BASENAME_TEST([./1/a.c], [a.c])
400 BASENAME_TEST([./1/a.c/], [a.c])
405 AT_CHECK([$CONFIG_SHELL ./script])
414 # Strip filename component.
415 AT_SETUP([AS@&t@_DIRNAME])
418 AT_DATA_M4SH([script.as],
421 # The EXPR variant is allowed to fail if `expr' was considered as too
422 # weak for us, in which case `as_expr=false'.
423 m4_define([DIRNAME_TEST],
424 [dir=`AS_DIRNAME([$1])`
425 test "$dir" = "$2" || (test -n "$3" && test "$dir" = "$3") ||
426 echo "dirname($1) = $dir instead of $2" >&2
428 if test "$as_expr" != false; then
429 dir=`_AS_DIRNAME_EXPR([$1])`
430 test "$dir" = "$2" || (test -n "$3" && test "$dir" = "$3") ||
431 echo "dirname_expr($1) = $dir instead of $2" >&2
434 dir=`_AS_DIRNAME_SED([$1])`
435 test "$dir" = "$2" || (test -n "$3" && test "$dir" = "$3") ||
436 echo "dirname_sed($1) = $dir instead of $2" >&2])
438 DIRNAME_TEST([/], [/])
439 DIRNAME_TEST([//], [//], [/])
440 DIRNAME_TEST([///], [/])
441 DIRNAME_TEST([//1], [//], [/])
442 DIRNAME_TEST([/1], [/])
443 DIRNAME_TEST([./1], [.])
444 DIRNAME_TEST([../../2], [../..])
445 DIRNAME_TEST([//1/], [//], [/])
446 DIRNAME_TEST([/1/], [/])
447 DIRNAME_TEST([./1/], [.])
448 DIRNAME_TEST([../../2], [../..])
449 DIRNAME_TEST([//1/3], [//1])
450 DIRNAME_TEST([/1/3], [/1])
451 DIRNAME_TEST([./1/3], [./1])
452 DIRNAME_TEST([../../2/3], [../../2])
453 DIRNAME_TEST([//1/3///], [//1])
454 DIRNAME_TEST([/1/3///], [/1])
455 DIRNAME_TEST([./1/3///], [./1])
456 DIRNAME_TEST([../../2/3///], [../../2])
457 DIRNAME_TEST([//1//3/], [//1])
458 DIRNAME_TEST([/1//3/], [/1])
459 DIRNAME_TEST([./1//3/], [./1])
460 DIRNAME_TEST([../../2//3/], [../../2])
465 AT_CHECK([$CONFIG_SHELL ./script])
470 ## ---------------- ##
471 ## AS_SET_CATFILE. ##
472 ## ---------------- ##
474 AT_SETUP([AS@&t@_SET_CATFILE])
477 AT_DATA_M4SH([script.as],
480 # CATFILE_TEST(DIR, FILE, EXPECTED)
481 m4_define([CATFILE_TEST],
482 [# AS_SET_CATFILE works and can be used in a compound list.
483 if AS_SET_CATFILE([var], [$1], [$2]) \
484 && test "$var" = $3; then :; else
485 echo "catfile($1, $2) = $var != $3" >&2
487 # AS_SET_CATFILE can use non-literals in its arguments.
491 if AS_SET_CATFILE([$varname], [$dirpart], [$filepart]) \
492 && test "$var2" = $3; then :; else
493 echo "catfile($dirpart, $filepart) = $var2 != $3" >&2
497 CATFILE_TEST([dir], [file], [dir/file])
498 CATFILE_TEST([.], [file], [file])
499 CATFILE_TEST([dir], [.], [dir])
500 CATFILE_TEST([dir], [/abs/file], [/abs/file])
501 CATFILE_TEST([dir], [C:/abs/file], [C:/abs/file])
502 CATFILE_TEST(["dir name"], ['file name'], ['dir name/file name'])
508 AT_CHECK([$CONFIG_SHELL ./script])
517 # Print literal strings, with/without newline.
518 AT_SETUP([AS@&t@_ECHO and AS@&t@_ECHO_N])
521 AT_DATA_M4SH([script.as],
524 m4_define([ECHO_TEST],
525 [echo=`AS_ECHO(['$1'])`
526 test "X$echo" = 'X$1' ||
527 echo "AS@&t@_ECHO('"'$1'"') outputs '$echo'" >&2
529 echo=`AS_ECHO_N(['$1'])`
530 test "X$echo" = 'X$1' ||
531 echo "AS@&t@_ECHO_N('"'$1'"') outputs '$echo'" >&2])
535 ECHO_TEST([---...---])
544 ECHO_TEST([\a\b\c\f\n\r\t\v\"\])
556 AT_CHECK([$CONFIG_SHELL ./script])
562 ## ----------------- ##
563 ## AS_EXECUTABLE_P. ##
564 ## ----------------- ##
566 # Check for executable regular files.
567 AT_SETUP([AS@&t@_EXECUTABLE_P])
570 AT_DATA_M4SH([script.as],
573 if AS_EXECUTABLE_P([/]); then
578 cat > foo.sh <<\EOF || AS_EXIT([1])
582 # File systems like FAT tend to fake executable permissions on all files.
583 # At this point, foo.sh should be executable iff permissions are faked.
584 AS_EXECUTABLE_P([foo.sh])
586 (./foo.sh) >/dev/null 2>&1
589 *[[1-9]]*:*[[1-9]]* | 0:0 ) echo 2 ;;
590 *) echo "fail ($st1:$st2)" ;;
592 # Now things better be executable
593 chmod a+x foo.sh || AS_EXIT([2])
594 mkdir 'two spaces' || AS_EXIT([3])
595 'two spaces'/../foo.sh || AS_EXIT([4])
596 if AS_EXECUTABLE_P(["two spaces/../foo.sh"]); then
604 AT_CHECK([$CONFIG_SHELL ./script], [],
618 # Exit scripts with given status.
619 AT_SETUP([AS@&t@_EXIT])
620 AT_KEYWORDS([m4sh AS@&t@_SET_STATUS])
622 AT_DATA_M4SH([script.as],
624 test x${1} = xa && AS_EXIT
625 test x${1} = xb && AS_EXIT([${2}])
626 test x${1} = xc && { AS_SET_STATUS([${2}]); AS_EXIT; }
627 test x${1} = xd && trap 's=$?; echo $s; AS_EXIT([$s])' 0
628 test x${2} = xe && set -e
629 test $[#] -gt 0 || AS_EXIT
631 dnl Solaris /bin/sh 'set -e' doesn't react to failed function calls
633 && { echo 'skipping rest of test: set -e support is lousy'; exit 77; }
638 AT_CHECK([$CONFIG_SHELL ./script], [1])
639 AT_CHECK([$CONFIG_SHELL ./script ''], [4])
640 AT_CHECK([$CONFIG_SHELL ./script a], [0])
641 AT_CHECK([$CONFIG_SHELL ./script b], [0])
642 AT_CHECK([$CONFIG_SHELL ./script b 0], [0])
643 AT_CHECK([$CONFIG_SHELL ./script b 2], [2])
644 AT_CHECK([$CONFIG_SHELL ./script c 0], [0])
645 AT_CHECK([$CONFIG_SHELL ./script c 2], [2])
646 AT_CHECK([$CONFIG_SHELL ./script d], [4], [[4
648 dnl If we got to this point without a FAIL, then AS_EXIT at least works.
649 dnl The rest of this test relies on semi-decent 'set -e' support, even
650 dnl though m4sh in general should not try to rely on it because of
651 dnl portability nightmares on what constructs are considered errors across
652 dnl various shells; therefore, an overall SKIP result is desirable on
653 dnl broken shells like Solaris /bin/sh.
654 AT_CHECK([$CONFIG_SHELL ./script '' e], [3])
655 AT_CHECK([$CONFIG_SHELL ./script d e], [3], [stdout])
656 dnl NetBSD sh fails to output on stderr here.
657 AT_CHECK([grep 3 stdout || exit 77], [], [ignore])
668 AT_SETUP([AS@&t@_MKDIR_P])
671 AT_DATA_M4SH([script.as],
677 AS_MKDIR_P(["$pwd/1/2/3/4/5/6"])
678 test -d "$pwd/1/2/3/4/5/6" ||
679 AS_ERROR([$pwd/1/2/3/4/5/6 has not been properly created])
681 AS_MKDIR_P(["a/b/c/d/e/f"])
682 test -d a/b/c/d/e/f ||
683 AS_ERROR([a/b/c/d/e/f has not been properly created])
688 AT_CHECK([$CONFIG_SHELL ./script])
695 ## -------------------- ##
696 ## AS_VERSION_COMPARE. ##
697 ## -------------------- ##
699 # Three-way version comparison.
700 AT_SETUP([AS@&t@_VERSION_COMPARE])
703 AT_DATA_M4SH([script.as],
706 m4_define([VERSION_COMPARE_TEST],
707 [AS_VERSION_COMPARE([$1], [$3], [result='<'], [result='='], [result='>'])
708 test "X$result" = "X$2" ||
709 AS_ERROR([version $1 $result $3; should be $1 $2 $3])
711 [AS_VERSION_COMPARE([$3], [$1], [result='<'], [result='='], [result='>'])
712 test "X$result" = "X>" ||
713 AS_ERROR([version $3 $result $1; should be $3 > $1])])])
715 VERSION_COMPARE_TEST([], =, [])
716 VERSION_COMPARE_TEST([1.0], =, [1.0])
717 VERSION_COMPARE_TEST([alpha-1.0], =, [alpha-1.0])
719 # These tests are taken from libc/string/tst-svc.expect.
721 000 001 00 00a 01 01a 0 0a 2.8 2.8-0.4 20 21 22 212 CP037 CP345 CP1257
722 foo foo-0.4 foo-0.4a foo-0.4b foo-0.5 foo-0.10.5 foo-3.01 foo-3.0
723 foo-3.0.0 foo-3.0.1 foo-3.2 foo-3.10 foo00 foo0
726 for test2 in $tst_svc_expect; do
727 VERSION_COMPARE_TEST([$test1], <, [$test2])
735 AT_CHECK([$CONFIG_SHELL ./script])
749 AT_DATA_M4SH([script.as],
752 test "$as_me" = script || AS_ECHO([["incorrect value of \$as_me: $as_me"]])
756 AT_CHECK([$CONFIG_SHELL ./script])
763 ## ----------------------------- ##
764 ## Negated classes in globbing. ##
765 ## ----------------------------- ##
767 # According to https://www.in-ulm.de/~mascheck/bourne/, all shells with
768 # functions also support `[!...]'. But `[^...]' is not universally supported.
770 AT_SETUP([Negated classes in globbing])
773 AT_DATA_M4SH([script.as],
776 case 'with!two!bangs' in
778 *) AS_ERROR([[`*[!a-z]*' didn't match `with!two!bangs']]);;
782 *[[!a-z]]*) AS_ERROR([[`*[!a-z]*' matched `without']]);;
787 AT_CHECK([$CONFIG_SHELL ./script])
791 ## ---------------------------- ##
792 ## Null variable substitution. ##
793 ## ---------------------------- ##
795 # According to https://www.in-ulm.de/~mascheck/bourne/, all shells with
796 # functions also support `${a:-b}'.
798 AT_SETUP([Null variable substitution])
801 AT_DATA_M4SH([script.as],
807 case ${a:-x}${b:-y}${c:-z} in
811 case ${a-x}${b-y}${c-z} in
816 case ${a+x}${b+y}${c+z} in
820 case ${a:+x}${b:+y}${c:+z} in
825 case ${a=x}${b=y}${c=z} in
830 case ${a:=x}${b:=y}${c:=z} in
841 (: ${a?oops}; echo fail) 2>err && exit 8
842 grep oops err >/dev/null || exit 9
843 test "${b?oops}" = '' || exit 10
844 test "${c?oops}" = . || exit 11
845 (: ${a:?oops}; echo fail) 2>err && exit 12
846 grep oops err >/dev/null || exit 13
847 (: ${b:?oops}; echo fail) 2>err && exit 14
848 grep oops err >/dev/null || exit 15
849 test "${c:?oops}" = . || exit 16
853 AT_CHECK([$CONFIG_SHELL ./script])
858 ## ------------------- ##
859 ## Functions Support. ##
860 ## ------------------- ##
862 # All m4sh scripts require function support.
864 AT_SETUP([Functions Support])
867 AT_DATA_M4SH([script.as],
883 if func_success; then
884 if func_failure; then
885 AS_ERROR([func_failure passed])
888 AS_ERROR([func_success failed])
893 AT_CHECK([$CONFIG_SHELL ./script])
900 ## ------------------------------ ##
901 ## Functions and return Support. ##
902 ## ------------------------------ ##
904 # All m4sh scripts require working return within functions.
906 AT_SETUP([Functions and return Support])
909 AT_DATA_M4SH([script.as],
921 if func_success; then
922 if func_failure; then
923 AS_ERROR([func_failure passed])
926 AS_ERROR([func_success failed])
931 AT_CHECK([$CONFIG_SHELL ./script])
936 ## --------------------------- ##
937 ## Nested AS_REQUIRE_SHELL_FN. ##
938 ## --------------------------- ##
940 # Hypothesis: M4sh expands nested AS_REQUIRE_SHELL_FN
943 AT_SETUP([Nested AS@&t@_REQUIRE_SHELL_FN])
946 AT_DATA_M4SH([script.as], [[dnl
947 m4_define([INIT], [oops])dnl
950 m4_defun([TEST_FUNC2_BODY], [
954 m4_defun([TEST_FUNC1_BODY], [
955 AS_REQUIRE_SHELL_FN([test_func2], [], [TEST_FUNC2_BODY])
959 AS_REQUIRE_SHELL_FN([test_func1], [], [TEST_FUNC1_BODY])
964 AT_CHECK([$CONFIG_SHELL ./script])
969 ## ------------------- ##
970 ## Nested AS_REQUIRE. ##
971 ## ------------------- ##
973 # Hypothesis: M4sh expands the requirements of AS_REQUIRE in the
974 # requested diversion, even if other AS_REQUIREs are interleaved.
976 AT_SETUP([Nested AS@&t@_REQUIRE])
979 AT_DATA_M4SH([script.as], [[dnl
982 m4_defun([in_fn_diversion], still_in_m4sh_init_fn=yes)
983 m4_defun([not_in_fn_diversion], still_in_m4sh_init_fn=no)
985 m4_defun([NESTED], [nested_require_in_fn_diversion=$still_in_m4sh_init_fn])
987 m4_defun([OUTER], [AS_REQUIRE([NESTED])dnl
988 outer_require_in_fn_diversion=$still_in_m4sh_init_fn])
990 m4_defun([test_init], [
991 AS_REQUIRE([in_fn_diversion], , [M4SH-INIT-FN])
992 AS_REQUIRE([OUTER], , [M4SH-INIT-FN])
993 AS_REQUIRE([not_in_fn_diversion], , [M4SH-INIT-FN])
997 if test $outer_require_in_fn_diversion != yes; then AS_EXIT([1]); fi
998 if test $nested_require_in_fn_diversion != no; then AS_EXIT([1]); fi
1002 AT_CHECK([$CONFIG_SHELL ./script])
1007 ## ------------------------------------ ##
1008 ## AS_REQUIRE_SHELL_FN and m4_require. ##
1009 ## ------------------------------------ ##
1011 # Hypothesis: M4sh expands the requirements of AS_REQUIRE_SHELL_FN
1012 # in M4SH-INIT-FN. This changed after Autoconf 2.63.
1014 AT_SETUP([AS@&t@_REQUIRE_SHELL_FN and m4@&t@_require])
1017 AT_DATA_M4SH([script.as], [[dnl
1020 m4_defun([in_m4_sh_init], still_in_m4sh_init=yes)
1021 m4_defun([not_in_m4_sh_init], still_in_m4sh_init=no)
1023 m4_defun([error_if_emitted_in_m4sh_init], [
1024 if test x$still_in_m4sh_init = xyes; then
1025 AS_ERROR([requirement emitted in M4SH-INIT])
1029 m4_defun([TEST_FUNC_BODY], [
1030 m4_require([error_if_emitted_in_m4sh_init])
1031 : echo in shell function, with parameter = [$]1
1035 m4_defun([test_init], [
1036 AS_REQUIRE([in_m4_sh_init], , [M4SH-INIT-FN])
1037 AS_REQUIRE_SHELL_FN([test_func], [], [TEST_FUNC_BODY])
1038 AS_REQUIRE([not_in_m4_sh_init])
1042 test_func parameter1
1046 AT_CHECK([$CONFIG_SHELL ./script])
1051 ## -------------- ##
1052 ## AS_HELP_STRING ##
1053 ## -------------- ##
1055 AT_SETUP([AS@&t@_HELP_STRING])
1056 AT_KEYWORDS([m4sh m4@&t@_text_wrap m4@&t@_expand])
1058 AT_DATA_M4SH([script.as],
1061 echo "AS_HELP_STRING([--an-option],[some text])"
1062 echo "AS_HELP_STRING([--another-much-longer-option],
1063 [some other text which should wrap at our default of 80 characters.])"
1064 echo "AS_HELP_STRING([--fooT=barT], [foo bar])"
1065 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@], [foo bar])"
1066 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@123456789], [foo bar])"
1067 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@1234567890], [foo bar])"
1068 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@12345678901], [foo bar])"
1069 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@123456789012], [foo bar])"
1070 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@1234567890123], [foo bar])"
1071 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@],
1072 [some other text which should wrap at our default of 80 characters.])"
1073 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@123456789],
1074 [some other text which should wrap at our default of 80 characters.])"
1075 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@1234567890],
1076 [some other text which should wrap at our default of 80 characters.])"
1077 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@12345678901],
1078 [some other text which should wrap at our default of 80 characters.])"
1079 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@123456789012],
1080 [some other text which should wrap at our default of 80 characters.])"
1081 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@1234567890123],
1082 [some other text which should wrap at our default of 80 characters.])"
1083 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@],
1084 [some other @<][:@ex@:][>@ which should wrap at our default of 80 characters.])"
1085 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@123456789],
1086 [some other @<][:@ex@:][>@ which should wrap at our default of 80 characters.])"
1087 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@1234567890],
1088 [some other @<][:@ex@:][>@ which should wrap at our default of 80 characters.])"
1089 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@12345678901],
1090 [some other @<][:@ex@:][>@ which should wrap at our default of 80 characters.])"
1091 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@123456789012],
1092 [some other @<][:@ex@:][>@ which should wrap at our default of 80 characters.])"
1093 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@1234567890123],
1094 [some other @<][:@ex@:][>@ which should wrap at our default of 80 characters.])"
1095 echo "AS_HELP_STRING([[--foo[=bar]]],
1096 [some other t[]t which should wrap at our default of 80 characters.])"
1097 echo "AS_HELP_STRING([[--foo[=bar]123456789]],
1098 [some other t[]t which should wrap at our default of 80 characters.])"
1099 echo "AS_HELP_STRING([[--foo[=bar]1234567890]],
1100 [some other t[]t which should wrap at our default of 80 characters.])"
1101 echo "AS_HELP_STRING([[--foo[=bar]12345678901]],
1102 [some other t[]t which should wrap at our default of 80 characters.])"
1103 echo "AS_HELP_STRING([[--foo[=bar]123456789012]],
1104 [some other t[]t which should wrap at our default of 80 characters.])"
1105 echo "AS_HELP_STRING([[--foo[=bar]1234567890123]],
1106 [some other t[]t which should wrap at our default of 80 characters.])"
1107 m4_define([mac], [MACRO])dnl
1108 echo "AS_HELP_STRING([--mac], [mac])"
1109 echo "AS_HELP_STRING([--o1, --o2], [two
1110 options, one description])"
1111 echo "AS_HELP_STRING([[[--o3, --o4]]], [comma inside literal quoting])"
1112 echo "AS_HELP_STRING([--tune1], [check out the tuned formatting],
1114 echo "AS_HELP_STRING([--tune2], [check out the tuned formatting],
1116 echo "AS_HELP_STRING([--tune3], [check out the tuned formatting],
1118 echo "AS_HELP_STRING([--tune4], [check out the tuned formatting],
1123 AT_CHECK([$CONFIG_SHELL ./script], [0],
1124 [[ --an-option some text
1125 --another-much-longer-option
1126 some other text which should wrap at our default of
1130 --foo[=bar]123456789 foo bar
1131 --foo[=bar]1234567890 foo bar
1132 --foo[=bar]12345678901 foo bar
1133 --foo[=bar]123456789012 foo bar
1134 --foo[=bar]1234567890123
1136 --foo[=bar] some other text which should wrap at our default of
1138 --foo[=bar]123456789 some other text which should wrap at our default of
1140 --foo[=bar]1234567890 some other text which should wrap at our default of
1142 --foo[=bar]12345678901 some other text which should wrap at our default of
1144 --foo[=bar]123456789012 some other text which should wrap at our default of
1146 --foo[=bar]1234567890123
1147 some other text which should wrap at our default of
1149 --foo[=bar] some other [ex] which should wrap at our default of
1151 --foo[=bar]123456789 some other [ex] which should wrap at our default of
1153 --foo[=bar]1234567890 some other [ex] which should wrap at our default of
1155 --foo[=bar]12345678901 some other [ex] which should wrap at our default of
1157 --foo[=bar]123456789012 some other [ex] which should wrap at our default of
1159 --foo[=bar]1234567890123
1160 some other [ex] which should wrap at our default of
1162 --foo[=bar] some other t[]t which should wrap at our default of
1164 --foo[=bar]123456789 some other t[]t which should wrap at our default of
1166 --foo[=bar]1234567890 some other t[]t which should wrap at our default of
1168 --foo[=bar]12345678901 some other t[]t which should wrap at our default of
1170 --foo[=bar]123456789012 some other t[]t which should wrap at our default of
1172 --foo[=bar]1234567890123
1173 some other t[]t which should wrap at our default of
1176 --o1, --o2 two options, one description
1177 [--o3, --o4] comma inside literal quoting
1178 --tune1 check out the tuned formatting
1179 --tune2 check out the tuned formatting
1180 --tune3 check out the
1183 --tune4 check out the tuned
1190 ## ------------------- ##
1191 ## AS_IF and AS_CASE. ##
1192 ## ------------------- ##
1194 AT_SETUP([AS@&t@_IF and AS@&t@_CASE])
1195 AT_KEYWORDS([m4sh m4@&t@_map_args_pair])
1197 AT_DATA_M4SH([script.as], [[dnl
1199 # Syntax checks: cope with empty arguments.
1200 AS_IF([:], [], [echo wrong])
1201 AS_IF([:], [echo one], [echo wrong])
1202 AS_IF([false], [echo wrong], [echo two])
1203 AS_IF([false], [echo wrong])
1205 AS_IF([false], [echo wrong],
1207 AS_IF([false], [echo wrong],
1210 AS_IF([false], [echo wrong],
1211 [false], [echo wrong])
1212 AS_IF([false], [echo wrong],
1213 [false], [echo wrong],
1215 AS_IF([false], [echo wrong],
1216 [false], [echo wrong],
1220 AS_CASE([foo], [echo seven])
1222 [foo], [echo eight],
1228 [bar], [echo wrong],
1232 # check for nesting, lists, and side effects, and quoting robustness
1234 AS_IF([AS_IF([$empty], [echo eleven])]) && AS_CASE([foo]) && echo twelve
1236 AS_IF([touch file; false]) && echo thirteen
1237 test -f file && echo fourteen
1239 AS_CASE([`touch file; false`]) && test -f file && echo fifteen
1240 dnl The next line is badly underquoted; don't intentionally copy this style.
1241 AS_CASE([foo], [foo], m4_do(AS_CASE([bar], [bar], [echo sixteen])))
1242 dnl Handle blank arguments.
1243 AS_IF([false], [:], [ ]) && AS_CASE([foo], [foo], []
1245 m4_define([empty])AS_IF([:], [empty]
1246 ) && AS_CASE([foo], [foo], [empty]) && echo eighteen
1247 dnl Allow for users that don't know to avoid trailing whitespace
1250 dnl We can't handle AS_IF([false], [:], [empty]) unless m4_expand is
1251 dnl taught how to handle m4_require. The user is responsible for
1252 dnl avoiding the syntax error in that case.
1254 # check that require works correctly
1255 m4_for([n], 1, 9, [],
1256 [m4_defun([FOO]n, [foo]n[=]n)dnl
1258 [m4_require([FOO]]n[)dnl
1263 echo "foo1=$foo1 bar1=$bar1"
1264 AS_IF([:], [], [BAR2])
1265 echo "foo2=$foo2 bar2=$bar2"
1266 AS_IF([false], [BAR3])
1267 echo "foo3=$foo3 bar3=$bar3"
1268 AS_IF([false], [], [BAR4])
1269 echo "foo4=$foo4 bar4=$bar4"
1270 AS_CASE([x], [x], [BAR5])
1271 echo "foo5=$foo5 bar5=$bar5"
1272 AS_CASE([x], [y], [BAR6])
1273 echo "foo6=$foo6 bar6=$bar6"
1277 echo "foo7=$foo7 bar7=$bar7"
1281 echo "foo8=$foo8 bar8=$bar8"
1285 echo "foo9=$foo9 bar9=$bar9"
1289 AT_CHECK([$CONFIG_SHELL ./script], [0], [[one
1319 dnl stress test for large number of conditionals
1320 dnl too large, and we start tickling shell bugs
1321 m4_pushdef([limit], [1000])dnl
1322 AT_DATA_M4SH([script.as], [[dnl
1324 AS_IF(m4_shift(m4_for([i], [1], ]limit[, [], [, test $[1] = i, echo i])))
1325 AS_IF(m4_shift(m4_for([i], [1], ]limit[, [], [, test $[1] = i, echo i])),
1327 AS_CASE([$[1]]m4_for([i], [1], ]limit[, [], [, i, echo i]))
1328 AS_CASE([$[1]]m4_for([i], [1], ]limit[, [], [, i, echo i]), [echo default])
1331 dnl Add --force so autom4te doesn't think `script' is still up to date.
1332 AT_CHECK_M4SH([--force])
1333 AT_CHECK([$CONFIG_SHELL ./script 1], [0], [[1
1338 AT_CHECK([$CONFIG_SHELL ./script limit], [0], [limit
1343 AT_CHECK([$CONFIG_SHELL ./script default], [0], [[default
1355 AT_SETUP([AS@&t@_FOR])
1358 AT_DATA_M4SH([script.as], [[dnl
1362 AS_FOR([m4var], [shvar], [a],
1363 [echo "m4var $shvar"])
1364 AS_FOR([m4var], [shvar], [b c],
1365 [echo "m4var $shvar"])
1367 AS_FOR([m4var], [shvar], [$list],
1368 [echo "m4var $shvar"])
1369 AS_FOR([m4var], [shvar], ["$list"],
1370 [echo "m4var $shvar"])
1371 AS_FOR([m4var], [shvar], ['$list'],
1372 [echo "m4var $shvar"])
1373 AS_FOR([m4var], [shvar], [\'],
1374 [echo "m4var $shvar"])
1376 # Syntax checks: cope with empty/blank arguments.
1378 AS_FOR([], [shvar], [],
1379 [echo "m4_defn([]) $shvar"])
1381 AS_FOR([], [shvar], [`touch file`])
1382 test -f file || exit 1
1383 AS_FOR([], [shvar], [], [ ])
1384 m4_define([empty])AS_FOR([], [shvar], [], [empty])
1386 # Check that break works.
1389 AS_FOR([m4var], [shvar], [h i],
1390 [echo "m4var"; break 2])
1395 AS_FOR([m4var], [shvar], [j],
1396 [echo "m4var"; break 2])
1402 AT_CHECK([$CONFIG_SHELL ./script], [0], [[a a
1419 ## --------------- ##
1420 ## AS_LITERAL_IF. ##
1421 ## --------------- ##
1423 AT_SETUP([AS@&t@_LITERAL_IF])
1424 AT_KEYWORDS([m4sh AS@&t@_LITERAL_WORD_IF AS@&t@_LITERAL_HEREDOC_IF])
1426 AT_DATA_M4SH([script.as], [[dnl
1428 echo AS_LITERAL_IF([lit], [ok], [ERR]) 1
1429 echo AS_LITERAL_IF([l-/.it], [ok], [ERR]) 2
1430 echo AS_LITERAL_IF([l''it], [ERR], [ok]) 3
1431 echo AS_LITERAL_IF([l$it], [ERR], [ok]) 4
1432 echo AS_LITERAL_IF([l$it], [ERR1], [ERR2], [ok]) 5
1433 echo AS_LITERAL_IF([l${it}], [ERR1], [ERR2], [ok]) 6
1434 echo AS_LITERAL_IF([l`case a in b) ;; esac`it], [ERR], [ok]) 7
1435 echo AS_LITERAL_IF([l`case a in b) ;; esac`it], [ERR1], [ok], [ERR2]) 8
1436 m4_define([mac], [l-/.it])
1437 echo AS_LITERAL_IF([mac], [ok], [ERR]) 9
1438 echo AS_LITERAL_IF([mac($, ``)], [ok], [ERR]) 10
1439 m4_define([mac], [l$it])
1440 echo AS_LITERAL_IF([mac], [ERR], [ok]) 11
1441 echo AS_LITERAL_IF([mac], [ERR1], [ERR2], [ok]) 12
1442 m4_define([mac], [l``it])
1443 echo AS_LITERAL_IF([mac], [ERR], [ok]) 13
1444 echo AS_LITERAL_IF([mac], [ERR1], [ok], [ERR2]) 14
1445 echo AS_LITERAL_IF([ a ][
1447 echo AS_LITERAL_WORD_IF([ a ][
1449 echo AS_LITERAL_HEREDOC_IF([ a ][
1451 echo AS_LITERAL_IF([(a)], [ERR], [ok]) 18
1452 echo AS_LITERAL_WORD_IF([(a)], [ERR], [ok]) 19
1453 echo AS_LITERAL_HEREDOC_IF([(a)], [ok], [ERR]) 20
1454 echo AS_LITERAL_IF([@S|@a], [ERR], [ok]) 21
1455 echo AS_LITERAL_WORD_IF([@S|@a], [ERR], [ok]) 22
1456 echo AS_LITERAL_HEREDOC_IF([@S|@a], [ERR], [ok]) 23
1457 echo AS_LITERAL_IF([${a+b}], [ERR1], [ok], [ERR2]) 24
1458 echo AS_LITERAL_IF([${a=b}], [ERR1], [ok], [ERR2]) 25
1459 echo AS_LITERAL_IF([a+b], [ok], [ERR1], [ERR2]) 26
1460 echo AS_LITERAL_IF([a=b], [ok], [ERR1], [ERR2]) 27
1464 AT_CHECK([$CONFIG_SHELL ./script], [],
1497 ## --------------------- ##
1498 ## AS_TR_SH, AS_TR_CPP. ##
1499 ## --------------------- ##
1501 AT_SETUP([AS@&t@_TR_SH and AS@&t@_TR_CPP])
1503 AT_DATA_M4SH([script.as], [[dnl
1505 m4_define([abc], [hI])m4_define([ABC], [Hi])
1506 m4_define([hi], [oops])m4_define([HI], [OOPS])
1507 echo AS_TR_SH(abc) AS_TR_SH(aBc) AS_TR_SH(ABC)
1508 echo AS_TR_SH([abc]) AS_TR_SH([aBc]) AS_TR_SH([ABC])
1509 echo AS_TR_SH([[abc]]) AS_TR_SH([[aBc]]) AS_TR_SH([[ABC]])
1510 echo AS_TR_CPP(abc) AS_TR_CPP(aBc) AS_TR_CPP(ABC)
1511 echo AS_TR_CPP([abc]) AS_TR_CPP([aBc]) AS_TR_CPP([ABC])
1512 echo AS_TR_CPP([[abc]]) AS_TR_CPP([[aBc]]) AS_TR_CPP([[ABC]])
1514 [var=abc vAr=aBc VAR=ABC]
1515 echo AS_TR_SH($var) AS_TR_SH($vAr) AS_TR_SH($VAR)
1516 echo AS_TR_SH([$var]) AS_TR_SH([$vAr]) AS_TR_SH([$VAR])
1517 echo AS_TR_SH([[$var]]) AS_TR_SH([[$vAr]]) AS_TR_SH([[$VAR]])
1518 echo AS_TR_CPP($var) AS_TR_CPP($vAr) AS_TR_CPP($VAR)
1519 echo AS_TR_CPP([$var]) AS_TR_CPP([$vAr]) AS_TR_CPP([$VAR])
1520 echo AS_TR_CPP([[$var]]) AS_TR_CPP([[$vAr]]) AS_TR_CPP([[$VAR]])
1522 echo AS_TR_SH(`echo abc`) AS_TR_SH(`echo aBc`) AS_TR_SH(`echo ABC`)
1523 echo AS_TR_SH([`echo abc`]) AS_TR_SH([`echo aBc`]) AS_TR_SH([`echo ABC`])
1524 echo AS_TR_SH([[`echo abc`]]) AS_TR_SH([[`echo aBc`]]) AS_TR_SH([[`echo ABC`]])
1525 echo AS_TR_CPP(`echo abc`) AS_TR_CPP(`echo aBc`) AS_TR_CPP(`echo ABC`)
1526 echo AS_TR_CPP([`echo abc`]) AS_TR_CPP([`echo aBc`]) AS_TR_CPP([`echo ABC`])
1527 echo AS_TR_CPP([[`echo abc`]]) AS_TR_CPP([[`echo aBc`]]) AS_TR_CPP([[`echo ABC`]])
1530 echo AS_TR_SH([a.b/c+*-=])
1531 echo AS_TR_CPP([a.b/c+*-=])
1533 echo AS_TR_SH([$var])
1534 echo AS_TR_CPP([$var])
1535 m4_define([macro], [a.b/c+*-=])
1536 echo AS_TR_SH([macro])
1537 echo AS_TR_CPP([macro])
1541 AT_CHECK([$CONFIG_SHELL ./script], [],
1571 dnl Check that of the last 6 macros, only 2 needed command substitution.
1572 dnl This test abuses our knowledge of m4sh internals a bit; oh well.
1573 AT_CHECK([tab=' ' # a single ASCII tab character
1574 sed -n '/start here/,$ {
1576 }' script | wc -l | sed "s/[[ $tab]]//g" ], [], [[2
1586 AT_SETUP([AS@&t@_VAR basics])
1587 AT_KEYWORDS([m4sh AS@&t@_VAR_COPY AS@&t@_VAR_SET AS@&t@_VAR_GET])
1588 AT_KEYWORDS([AS@&t@_VAR_TEST_SET AS@&t@_VAR_SET_IF AS@&t@_VAR_IF])
1589 AT_KEYWORDS([AS@&t@_VAR_PUSHDEF AS@&t@_VAR_POPDEF])
1591 AT_DATA_M4SH([script.as], [[dnl
1593 m4_define([with], [WITH])
1595 dnl AS_VAR_SET_IF also covers AS_VAR_TEST_SET
1596 AS_VAR_SET_IF([foo], [echo oops]) && echo ok
1597 AS_VAR_IF([foo], [], [echo ok], [echo oops])
1599 AS_VAR_SET_IF([foo], [echo ok])
1600 AS_VAR_SET([foo], ['\a "weird" `value` with; $fun '\''characters
1602 AS_VAR_COPY([bar], [foo])
1604 AS_ECHO(["AS_VAR_GET([foo])-"])
1605 AS_VAR_SET_IF([foo], [echo ok], [echo oops])
1606 AS_VAR_IF([foo], [string], [echo oops]) && echo ok
1607 AS_VAR_PUSHDEF([tmp], [foo])
1608 AS_VAR_IF([tmp], ['\a "weird" `value` with; $fun '\''characters
1609 '], [echo ok], [echo oops]) # 'font-lock
1610 AS_VAR_POPDEF([tmp])
1611 m4_ifdef([tmp], [echo oops])
1613 # Indirects via shell vars.
1616 AS_VAR_SET_IF([foo$num], [echo oops]) && echo ok
1617 AS_VAR_IF([foo$num], [], [echo ok], [echo oops])
1619 AS_VAR_SET_IF([foo$num], [echo ok])
1620 AS_VAR_SET([foo$num], ['\a "weird" `value` with; $fun '\''characters
1622 AS_VAR_COPY([bar], [foo$num])
1624 AS_VAR_COPY([foo$num], [bar])
1626 AS_ECHO(["AS_VAR_GET([foo$num])-"])
1627 AS_VAR_SET_IF([foo$num], [echo ok], [echo oops])
1628 AS_VAR_IF([foo$num], [string], [echo oops]) && echo ok
1629 AS_VAR_PUSHDEF([tmp], [foo$num])
1630 AS_VAR_IF([tmp], ['\a "weird" `value` with; $fun '\''characters
1631 '], [echo ok], [echo oops]) # 'font-lock
1632 AS_VAR_POPDEF([tmp])
1633 m4_ifdef([tmp], [echo oops])
1635 # Indirects via command substitution.
1637 AS_VAR_SET_IF([`echo foo3`], [echo oops]) && echo ok
1638 AS_VAR_IF([`echo foo3`], [], [echo ok], [echo oops])
1640 AS_VAR_SET_IF([`echo foo3`], [echo ok])
1641 AS_VAR_SET([`echo foo3`], ['\a "weird" `value` with; $fun '\''characters
1643 AS_VAR_COPY([bar], [`echo foo3`])
1645 AS_VAR_COPY([`echo foo4`], [bar])
1647 AS_ECHO(["AS_VAR_GET([`echo foo4`])-"])
1648 AS_VAR_SET_IF([`echo foo4`], [echo ok], [echo oops])
1649 AS_VAR_IF([`echo foo4`], [string], [echo oops]) && echo ok
1650 AS_VAR_PUSHDEF([tmp], [`echo foo4`])
1651 AS_VAR_IF([tmp], ['\a "weird" `value` with; $fun '\''characters
1652 '], [echo ok], [echo oops]) # 'font-lock
1653 AS_VAR_POPDEF([tmp])
1654 m4_ifdef([tmp], [echo oops])
1659 AT_CHECK([$CONFIG_SHELL ./script], [], [[ok
1662 \a "weird" `value` WITH; $fun 'characters
1664 \a "weird" `value` WITH; $fun 'characters
1673 \a "weird" `value` WITH; $fun 'characters
1675 \a "weird" `value` WITH; $fun 'characters-
1683 \a "weird" `value` WITH; $fun 'characters
1685 \a "weird" `value` WITH; $fun 'characters-
1694 ## --------------- ##
1695 ## AS_VAR_APPEND. ##
1696 ## --------------- ##
1698 AT_SETUP([AS@&t@_VAR_APPEND])
1699 AT_KEYWORDS([m4sh AS@&t@_VAR])
1701 AT_DATA_M4SH([script.as], [[dnl
1704 AS_VAR_APPEND([foo], ["hello, "])
1705 AS_VAR_APPEND([foo], [world])
1707 # Indirects via shell vars.
1709 AS_VAR_APPEND([foo$num], ['hello, '])
1710 AS_VAR_APPEND([foo$num], [`echo "world"`])
1712 # Indirects via command substitution.
1714 AS_VAR_APPEND([`echo foo2`], [${h}])
1715 AS_VAR_APPEND([`echo foo2`], ["$w"])
1720 AT_CHECK([$CONFIG_SHELL ./script], [],
1729 ## -------------- ##
1731 ## -------------- ##
1733 AT_SETUP([AS@&t@_VAR_ARITH])
1734 AT_KEYWORDS([m4sh AS@&t@_VAR])
1736 AT_DATA_M4SH([script.as], [[dnl
1739 AS_VAR_ARITH([foo], [1 + 1])
1741 # Indirects via shell vars.
1743 AS_VAR_ARITH([foo$num], [\( 2 + 3 \) \* 4])
1745 # Indirects via command substitution.
1746 AS_VAR_ARITH([`echo foo2`], [0 + -2 + $foo1 / 2])
1751 AT_CHECK([$CONFIG_SHELL ./script], [],
1760 ## ----------------- ##
1761 ## AS_INIT cleanup. ##
1762 ## ----------------- ##
1764 AT_SETUP([AS@&t@_INIT cleanup])
1765 AT_KEYWORDS([m4sh m4@&t@_wrap m4@&t@_wrap_lifo])
1767 AT_DATA_M4SH([script.as], [[dnl
1768 dnl Registered before AS_INIT's cleanups
1769 m4_wrap([echo cleanup 1
1771 m4_pushdef([_AS_SHELL_FN_SPY])dnl neutralize the spy, we don't care about it
1773 dnl Registered after AS_INIT's cleanups, thus goes to KILL diversion
1774 m4_wrap([echo cleanup 2
1775 dnl However, nested wraps and diversions can still be used
1776 dnl Also, test wrapping text that looks like parameter reference
1777 m4_wrap([echo cleanup 3
1778 m4_divert_text([M4SH-INIT], [m4_define([foo], [$1])dnl
1781 dnl Registered before AS_INIT's cleanups
1782 m4_wrap_lifo([echo cleanup 5
1788 AT_CHECK([$CONFIG_SHELL ./script], [], [[prep 4
1797 ## ------------------- ##
1798 ## AS_INIT_GENERATED. ##
1799 ## ------------------- ##
1801 AT_SETUP([AS@&t@_INIT_GENERATED])
1802 AT_KEYWORDS([AS@&t@_MESSAGE AS@&t@_MESSAGE_LOG_FD])
1804 dnl First run, no logging, tests shell selection
1805 AT_DATA_M4SH([script.as], [[dnl
1807 AS_INIT_GENERATED([child], [echo hello from child])
1809 AS_ECHO(["SHELL=$SHELL"])
1811 echo hello from parent
1812 AS_ECHO(["SHELL=$SHELL"])
1816 AT_CHECK([$CONFIG_SHELL ./script], [0], [stdout])
1817 AT_CHECK([grep 'SHELL=.' stdout], [0], [ignore])
1818 sed s/parent/child/ <stdout >expout
1819 AT_CHECK([./child], [0], [expout])
1824 AT_CHECK([$CONFIG_SHELL ./script], [0], [expout])
1825 AT_CHECK([cmp child child.bak])
1826 AT_CHECK([grep 'SHELL=.' stdout], [0], [ignore])
1827 sed s/parent/child/ <stdout >expout
1828 AT_CHECK([./child], [0], [expout])
1831 dnl Second run, with logging from parent and child, tests fd handling
1832 AT_DATA_M4SH([script.as], [[dnl
1835 m4_define([AS_MESSAGE_LOG_FD], [5])
1836 exec AS_MESSAGE_LOG_FD>log
1837 AS_INIT_GENERATED([$child], [echo hello1 from $child]) || AS_EXIT([1])
1839 m4_pushdef([AS_MESSAGE_LOG_FD])
1840 AS_MESSAGE([hello2 from ${child}child])
1841 m4_popdef([AS_MESSAGE_LOG_FD])
1842 exec AS_MESSAGE_LOG_FD>>log
1843 AS_MESSAGE([hello3 from child])
1845 AS_MESSAGE([hello from parent])
1846 dnl close log in parent before spawning child, for mingw
1847 exec AS_MESSAGE_LOG_FD>&-
1853 AT_CHECK([$CONFIG_SHELL ./script], [0], [[script: hello from parent
1855 child: hello2 from child
1856 child: hello3 from child
1858 AT_CHECK([[sed 's,:[0-9][0-9]*:,:0:,' log]], [0],
1859 [[script:0: hello from parent
1860 child:0: hello3 from child
1863 # Force write error creating a file on stdout
1864 if test -w /dev/full && test -c /dev/full; then
1865 AT_CHECK([$CONFIG_SHELL ./script /dev/full], [1], [ignore], [ignore])
1871 ## --------------- ##
1872 ## AS_MESSAGE_FD. ##
1873 ## --------------- ##
1875 AT_SETUP([AS@&t@_MESSAGE_FD])
1876 AT_KEYWORDS([AS@&t@_MESSAGE AS@&t@_MESSAGE_LOG_FD AS@&t_ORIGINAL_STDIN_FD])
1877 AT_KEYWORDS([AS@&t@_LINENO_PUSH])
1879 AT_DATA_M4SH([script.as], [[dnl
1881 m4_define([AS_ORIGINAL_STDIN_FD], [5])
1882 m4_define([AS_MESSAGE_LOG_FD], [6])
1883 m4_define([AS_MESSAGE_FD], [7])
1884 exec AS_ORIGINAL_STDIN_FD<&0 </dev/null AS_MESSAGE_LOG_FD>log
1885 if test $[#] -gt 0; then
1886 exec AS_MESSAGE_FD>/dev/null
1888 exec AS_MESSAGE_FD>&1
1890 AS_LINENO_PUSH([100])
1891 cat # tests that stdin is neutralized
1892 AS_MESSAGE([hello world])
1893 cat <&AS_ORIGINAL_STDIN_FD
1897 AT_CHECK([echo goodbye | $CONFIG_SHELL ./script], [0],
1898 [[script: hello world
1901 AT_CHECK([cat log], [0],
1902 [[script:100: hello world
1905 AT_CHECK([echo goodbye | $CONFIG_SHELL ./script silent], [0],
1908 AT_CHECK([cat log], [0],
1909 [[script:100: hello world
1915 ## --------------- ##
1916 ## _AS_CLEAN_DIR. ##
1917 ## --------------- ##
1919 AT_SETUP([_AS@&t@_CLEAN_DIR])
1921 dnl ensure that we can erase all files in a directory. Note that
1922 dnl _AS_CLEAN_DIR needs three globs to catch all these files.
1923 AT_DATA_M4SH([script.as], [[dnl
1925 # Unwritable subdirectories are common during 'make distcheck'.
1926 mkdir sub sub/unwritable || AS_ERROR([failed to mkdir])
1927 touch sub/unwritable/file || AS_ERROR([failed to touch])
1928 chmod a-wx sub/unwritable || AS_ERROR([failed to chmod])
1929 # Cygwin 1.5 can't touch 'sub/...', so make that file optional.
1930 touch sub/a sub/aa sub/aaa sub/.a sub/..a sub/.aa \
1931 || AS_ERROR([failed to touch])
1932 touch sub/... 2>/dev/null
1933 _AS_CLEAN_DIR([sub]) || AS_ERROR([failed to clean])
1934 # rmdir instead of 'rm -fr' here proves that we emptied sub.
1935 rmdir sub || AS_ERROR([failed to rmdir])
1939 AT_CHECK([$CONFIG_SHELL ./script])
1950 AT_DATA_M4SH([script.as], [[dnl
1958 AT_CHECK([$CONFIG_SHELL ./script], [], [foobar