5 # Copyright (C) 2000-2017, 2020-2023 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],
127 AT_CAPTURE_FILE([config.log])
128 AT_CHECK([env CONFIG_SHELL=./cfg-sh ./configure],
130 [[configure: creating ./config.status
132 # ./configure re-executed itself.
133 AT_CHECK([test -f cfg-sh-has-run], [0])
134 # And did that not to cause extra execution of later commands.
135 AT_CHECK([cat quux], [0], [foobar
142 ## ------------------- ##
143 ## AS_WARN, AS_ERROR. ##
144 ## ------------------- ##
146 AT_SETUP([AS@&t@_WARN and AS@&t@_ERROR])
150 AT_DATA_M4SH([script.as],
152 AS_WARN([*watch out*])dnl
154 if test x"$die" != x; then
155 AS_ERROR([you're dead])dnl
157 AS_ERROR([really])dnl
164 AT_CHECK([$CONFIG_SHELL ./script], [],
166 ]], [[script: WARNING: *watch out*
168 AT_CHECK([die=: $CONFIG_SHELL ./script], [1],
169 [], [[script: WARNING: *watch out*
170 script: error: you're dead
175 AT_DATA_M4SH([script.as],
177 m4_define([gone], [AS_ERROR([really])])
178 m4_define([AS_MESSAGE_LOG_FD], [5])
179 exec AS_MESSAGE_LOG_FD>log.txt
180 AS_WARN([*watch out*])dnl
182 if test x"$die" != x; then
183 AS_ERROR([you're dead])dnl
185 AS_ERROR([really])dnl
189 exec AS_MESSAGE_LOG_FD>&-
193 AT_CHECK([$CONFIG_SHELL ./script], [],
195 ]], [[script: WARNING: *watch out*
197 AT_CHECK([[grep 'script:[0-9]*: WARNING: \*watch out\*' log.txt]], [], [ignore])
198 AT_CHECK([die=: $CONFIG_SHELL ./script], [1],
199 [], [[script: WARNING: *watch out*
200 script: error: you're dead
202 AT_CHECK([[grep 'script:[0-9]*: WARNING: \*watch out\*' log.txt]], [], [ignore])
203 AT_CHECK([[grep 'script:[0-9]*: error: you'\''re dead' log.txt]], [], [ignore])
207 ## ---------------- ##
208 ## LINENO support. ##
209 ## ---------------- ##
214 # We cannot unset LINENO with Zsh, yet this test case relies on
215 # unsetting LINENO to compare its result when (i) LINENO is supported
216 # and when (ii) it is not.
217 # So just skip if the shell is ZSH.
218 AT_CHECK([test ${ZSH_VERSION+y} && exit 77], ignore)
220 # AT_DATA_LINENO(FILE-NAME,
221 # UNSET-LINENO = true | false, COUNTER, COUNTER-RE)
222 # ----------------------------------------------------------------
223 # Produce the FILE-NAME M4sh script which uses the COUNTER LINENO or
224 # _oline_, which we can recognized via COUNTER-RE. Unset LINENO is
227 # Use COUNTER, COUNTER-RE = [__LINENO__], [LINENO]
228 # or = [__OLINE__], [_oline__]
230 # instead of the obvious $LINENO and __oline@&t@__, because they would
231 # be replaced in the test suite itself, even before creating these
232 # scripts. For the same reason, grep for LINENO and _oline__ (sic).
234 # UNSET-LINENO is a shell condition to make sure the scripts have the
235 # same number of lines in the output, so that their outputs be identical.
236 m4_define([AT_DATA_LINENO],
239 m4@&t@_divert_text([], [
241 AS@&t@_UNSET([LINENO])
244 AS@&t@_LINENO_PREPARE
246 grep 'Line: .*$4' "$[0]" >/dev/null ||
247 AS@&t@_ERROR([cannot find original script])
250 # If occurrences of $LINENO or __@&t@oline__ were wanted, create them.
251 sed 's/__LINENO__/$''LINENO/g;s/__OLINE__/__''oline__/g' $1.tas >$1.as
252 AT_CHECK([autom4te -l m4sh $1.as -o $1])
255 # '_oline_', once processed and ran, produces our reference.
256 # We check that we find ourselves by looking at a string which is
257 # available only in the original script: '_oline_'.
258 AT_DATA_LINENO([reference], [true], [__OLINE__], [_oline__])
259 AT_CHECK([./reference], 0, [stdout])
264 # Now using a maybe-functioning LINENO, with different call conventions.
265 # Be sure to be out of the PATH.
266 AT_CHECK([mkdir test || exit 77])
268 AT_DATA_LINENO([test/test-1], [true], [__LINENO__], [LINENO])
269 AT_CHECK([./test/test-1], 0, [expout])
270 AT_CHECK([(PATH=test$PATH_SEPARATOR$PATH; export PATH; exec test-1)],
272 AT_CHECK([sh ./test/test-1], 0, [expout])
274 # Now using a disabled LINENO, with different call conventions.
275 AT_DATA_LINENO([test/test-2], [true], [__LINENO__], [LINENO])
276 AT_CHECK([./test/test-2], 0, [expout])
277 AT_CHECK([(PATH=test$PATH_SEPARATOR$PATH; export PATH; exec test-2)],
279 AT_CHECK([sh ./test/test-2], 0, [expout])
284 ## ---------------------- ##
285 ## LINENO stack support. ##
286 ## ---------------------- ##
288 AT_SETUP([LINENO stack])
291 AT_DATA_M4SH([script.as],
294 AS_LINENO_PUSH([9999])
295 test $as_lineno = 9999 || AS_ERROR([bad as_lineno at depth 1])
296 AS_LINENO_PUSH([8888])
297 test $as_lineno = 9999 || AS_ERROR([bad as_lineno at depth 2])
299 test $as_lineno = 9999 || AS_ERROR([bad as_lineno at depth 1])
301 test ${as_lineno+y} && AS_ERROR([as_lineno set at depth 0])
307 AT_CHECK([$CONFIG_SHELL ./script])
316 # Output a framed one-line message.
317 AT_SETUP([AS@&t@_BOX])
320 AT_DATA_M4SH([script.as],
323 AS_BOX([Send a simple message, to foobar@example.com])
324 AS_BOX([Send a simple message, to foobar@example.com], [$])
325 m4_define([msg], [$complex])
326 complex='Not quite as simple |$[1]'
333 AT_CHECK([sed -n '/ -\{44\} /,/ -\{44\} /p' script ]dnl
334 [| sed '1 s/.*## -/## -/; 3 s/- ##.*/- ##/'], [],
335 [[## -------------------------------------------- ##
336 ## Send a simple message, to foobar@example.com ##
337 ## -------------------------------------------- ##
340 AT_CHECK([$CONFIG_SHELL ./script], [], [[
341 ## -------------------------------------------- ##
342 ## Send a simple message, to foobar@example.com ##
343 ## -------------------------------------------- ##
344 ## $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ ##
345 ## Send a simple message, to foobar@example.com ##
346 ## $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ ##
347 ## ----------------------- ##
348 ## Not quite as simple |$1 ##
349 ## ----------------------- ##
350 ## ,,,,,,,,,,,,,,,,,,,,,,, ##
351 ## Not quite as simple |$1 ##
352 ## ,,,,,,,,,,,,,,,,,,,,,,, ##
358 # Strip path from file.
359 AT_SETUP([AS@&t@_BASENAME])
362 AT_DATA_M4SH([script.as],
365 m4_define([BASENAME_TEST],
366 [base=`AS_BASENAME([$1])`
367 test "$base" = "$2" ||
368 echo "basename($1) = $base instead of $2" >&2
370 base=`_AS_BASENAME_SED([$1])`
371 test "$base" = "$2" ||
372 echo "basename_sed($1) = $base instead of $2" >&2])
374 BASENAME_TEST([//1], [1])
375 BASENAME_TEST([/1], [1])
376 BASENAME_TEST([./1], [1])
377 BASENAME_TEST([../../2], [2])
378 BASENAME_TEST([//1/], [1])
379 BASENAME_TEST([/1/], [1])
380 BASENAME_TEST([./1/], [1])
381 BASENAME_TEST([../../2], [2])
382 BASENAME_TEST([//1/3], [3])
383 BASENAME_TEST([/1/3], [3])
384 BASENAME_TEST([./1/3], [3])
385 BASENAME_TEST([../../2/3], [3])
386 BASENAME_TEST([//1/3///], [3])
387 BASENAME_TEST([/1/3///], [3])
388 BASENAME_TEST([./1/3///], [3])
389 BASENAME_TEST([../../2/3///], [3])
390 BASENAME_TEST([//1//3/], [3])
391 BASENAME_TEST([/1//3/], [3])
392 BASENAME_TEST([./1//3/], [3])
393 BASENAME_TEST([a.c], [a.c])
394 BASENAME_TEST([a.c/], [a.c])
395 BASENAME_TEST([/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])
401 BASENAME_TEST([./1/a.c/], [a.c])
406 AT_CHECK([$CONFIG_SHELL ./script])
415 # Strip filename component.
416 AT_SETUP([AS@&t@_DIRNAME])
419 AT_DATA_M4SH([script.as],
422 # The EXPR variant is allowed to fail if 'expr' was considered as too
423 # weak for us, in which case 'as_expr=false'.
424 m4_define([DIRNAME_TEST],
425 [dir=`AS_DIRNAME([$1])`
426 test "$dir" = "$2" || (test -n "$3" && test "$dir" = "$3") ||
427 echo "dirname($1) = $dir instead of $2" >&2
429 if test "$as_expr" != false; then
430 dir=`_AS_DIRNAME_EXPR([$1])`
431 test "$dir" = "$2" || (test -n "$3" && test "$dir" = "$3") ||
432 echo "dirname_expr($1) = $dir instead of $2" >&2
435 dir=`_AS_DIRNAME_SED([$1])`
436 test "$dir" = "$2" || (test -n "$3" && test "$dir" = "$3") ||
437 echo "dirname_sed($1) = $dir instead of $2" >&2])
439 DIRNAME_TEST([/], [/])
440 DIRNAME_TEST([//], [//], [/])
441 DIRNAME_TEST([///], [/])
442 DIRNAME_TEST([//1], [//], [/])
443 DIRNAME_TEST([/1], [/])
444 DIRNAME_TEST([./1], [.])
445 DIRNAME_TEST([../../2], [../..])
446 DIRNAME_TEST([//1/], [//], [/])
447 DIRNAME_TEST([/1/], [/])
448 DIRNAME_TEST([./1/], [.])
449 DIRNAME_TEST([../../2], [../..])
450 DIRNAME_TEST([//1/3], [//1])
451 DIRNAME_TEST([/1/3], [/1])
452 DIRNAME_TEST([./1/3], [./1])
453 DIRNAME_TEST([../../2/3], [../../2])
454 DIRNAME_TEST([//1/3///], [//1])
455 DIRNAME_TEST([/1/3///], [/1])
456 DIRNAME_TEST([./1/3///], [./1])
457 DIRNAME_TEST([../../2/3///], [../../2])
458 DIRNAME_TEST([//1//3/], [//1])
459 DIRNAME_TEST([/1//3/], [/1])
460 DIRNAME_TEST([./1//3/], [./1])
461 DIRNAME_TEST([../../2//3/], [../../2])
466 AT_CHECK([$CONFIG_SHELL ./script])
471 ## ---------------- ##
472 ## AS_SET_CATFILE. ##
473 ## ---------------- ##
475 AT_SETUP([AS@&t@_SET_CATFILE])
478 AT_DATA_M4SH([script.as],
481 # CATFILE_TEST(DIR, FILE, EXPECTED)
482 m4_define([CATFILE_TEST],
483 [# AS_SET_CATFILE works and can be used in a compound list.
484 if AS_SET_CATFILE([var], [$1], [$2]) \
485 && test "$var" = $3; then :; else
486 echo "catfile($1, $2) = $var != $3" >&2
488 # AS_SET_CATFILE can use non-literals in its arguments.
492 if AS_SET_CATFILE([$varname], [$dirpart], [$filepart]) \
493 && test "$var2" = $3; then :; else
494 echo "catfile($dirpart, $filepart) = $var2 != $3" >&2
498 CATFILE_TEST([dir], [file], [dir/file])
499 CATFILE_TEST([.], [file], [file])
500 CATFILE_TEST([dir], [.], [dir])
501 CATFILE_TEST([dir], [/abs/file], [/abs/file])
502 CATFILE_TEST([dir], [C:/abs/file], [C:/abs/file])
503 CATFILE_TEST(["dir name"], ['file name'], ['dir name/file name'])
509 AT_CHECK([$CONFIG_SHELL ./script])
518 # Print literal strings, with/without newline.
519 AT_SETUP([AS@&t@_ECHO and AS@&t@_ECHO_N])
522 AT_DATA_M4SH([script.as],
525 m4_define([ECHO_TEST],
526 [echo=`AS_ECHO(['$1'])`
527 test "X$echo" = 'X$1' ||
528 echo "AS@&t@_ECHO('"'$1'"') outputs '$echo'" >&2
530 echo=`AS_ECHO_N(['$1'])`
531 test "X$echo" = 'X$1' ||
532 echo "AS@&t@_ECHO_N('"'$1'"') outputs '$echo'" >&2])
536 ECHO_TEST([---...---])
545 ECHO_TEST([\a\b\c\f\n\r\t\v\"\])
557 AT_CHECK([$CONFIG_SHELL ./script])
561 # Obsolete shell variables with the same functionality as above.
562 AT_SETUP([obsolete $as@&t@_echo and $as@&t@_echo_n])
565 AT_DATA_M4SH([script.as],
567 AS_REQUIRE([_AS_ECHO_N_PREPARE])
569 m4_define([ECHO_TEST],
570 [echo=`$as_echo '$1'`
571 test "X$echo" = 'X$1' ||
572 echo "\$as@&t@_echo '$1' outputs '$echo'" >&2
574 echo=`$as_echo_n '$1'`
575 test "X$echo" = 'X$1' ||
576 echo "\$as@&t@_echo_n '$1' outputs '$echo'" >&2])
580 ECHO_TEST([---...---])
589 ECHO_TEST([\a\b\c\f\n\r\t\v\"\])
600 AT_CHECK_M4SH([], 0, [],
601 [[script.as:13: warning: $as@&t@_echo is obsolete; use AS@&t@_ECHO(["message"]) instead
602 script.as:13: warning: $as@&t@_echo_n is obsolete; use AS@&t@_ECHO_N(["message"]) instead
603 script.as:14: warning: $as@&t@_echo is obsolete; use AS@&t@_ECHO(["message"]) instead
604 script.as:14: warning: $as@&t@_echo_n is obsolete; use AS@&t@_ECHO_N(["message"]) instead
605 script.as:15: warning: $as@&t@_echo is obsolete; use AS@&t@_ECHO(["message"]) instead
606 script.as:15: warning: $as@&t@_echo_n is obsolete; use AS@&t@_ECHO_N(["message"]) instead
607 script.as:16: warning: $as@&t@_echo is obsolete; use AS@&t@_ECHO(["message"]) instead
608 script.as:16: warning: $as@&t@_echo_n is obsolete; use AS@&t@_ECHO_N(["message"]) instead
609 script.as:17: warning: $as@&t@_echo is obsolete; use AS@&t@_ECHO(["message"]) instead
610 script.as:17: warning: $as@&t@_echo_n is obsolete; use AS@&t@_ECHO_N(["message"]) instead
611 script.as:18: warning: $as@&t@_echo is obsolete; use AS@&t@_ECHO(["message"]) instead
612 script.as:18: warning: $as@&t@_echo_n is obsolete; use AS@&t@_ECHO_N(["message"]) instead
613 script.as:19: warning: $as@&t@_echo is obsolete; use AS@&t@_ECHO(["message"]) instead
614 script.as:19: warning: $as@&t@_echo_n is obsolete; use AS@&t@_ECHO_N(["message"]) instead
615 script.as:20: warning: $as@&t@_echo is obsolete; use AS@&t@_ECHO(["message"]) instead
616 script.as:20: warning: $as@&t@_echo_n is obsolete; use AS@&t@_ECHO_N(["message"]) instead
617 script.as:21: warning: $as@&t@_echo is obsolete; use AS@&t@_ECHO(["message"]) instead
618 script.as:21: warning: $as@&t@_echo_n is obsolete; use AS@&t@_ECHO_N(["message"]) instead
619 script.as:22: warning: $as@&t@_echo is obsolete; use AS@&t@_ECHO(["message"]) instead
620 script.as:22: warning: $as@&t@_echo_n is obsolete; use AS@&t@_ECHO_N(["message"]) instead
621 script.as:23: warning: $as@&t@_echo is obsolete; use AS@&t@_ECHO(["message"]) instead
622 script.as:23: warning: $as@&t@_echo_n is obsolete; use AS@&t@_ECHO_N(["message"]) instead
623 script.as:24: warning: $as@&t@_echo is obsolete; use AS@&t@_ECHO(["message"]) instead
624 script.as:24: warning: $as@&t@_echo_n is obsolete; use AS@&t@_ECHO_N(["message"]) instead
625 script.as:25: warning: $as@&t@_echo is obsolete; use AS@&t@_ECHO(["message"]) instead
626 script.as:25: warning: $as@&t@_echo_n is obsolete; use AS@&t@_ECHO_N(["message"]) instead
627 script.as:28: warning: $as@&t@_echo is obsolete; use AS@&t@_ECHO(["message"]) instead
628 script.as:28: warning: $as@&t@_echo_n is obsolete; use AS@&t@_ECHO_N(["message"]) instead
629 script.as:30: warning: $as@&t@_echo is obsolete; use AS@&t@_ECHO(["message"]) instead
630 script.as:30: warning: $as@&t@_echo_n is obsolete; use AS@&t@_ECHO_N(["message"]) instead
632 AT_CHECK([$CONFIG_SHELL ./script])
637 ## ------------------------------ ##
638 ## Redefining AS_ECHO internals. ##
639 ## ------------------------------ ##
641 AT_SETUP([Redefining AS@&t@_ECHO internals])
643 # None of the tests below do any AC_DEFINEs, so running autoheader is
644 # a waste of time, but the skeleton generated by AT_CONFIGURE_AC needs
645 # this file to exist anyway.
646 AT_DATA([config.hin])
648 # Defining a macro named 's' or 'n' should not affect AS_ECHO or
649 # macros that use it.
652 [[m4@&t@_pushdef([s], [z])
653 m4@&t@_pushdef([n], [u])
654 AC_MSG_NOTICE([checking whether m4sugar echo works... yes])
655 AC_MSG_CHECKING([whether m4sugar echo_n works])
662 AT_CHECK_CONFIGURE([], [],
663 [[configure: checking whether m4sugar echo works... yes
664 checking whether m4sugar echo_n works... yes
665 configure: creating ./config.status
666 config.status: creating config.h
671 # More elaborate version of the above; derived from actual code in
672 # ruby 2.7.2's configure script.
675 [[AC@&t@_DEFUN([RUBY_CHECK_SIZEOF],[
676 AS@&t@_VAR_PUSHDEF([s], [ac_cv_sizeof_size])
677 AC@&t@_CACHE_CHECK([size of $1],
678 [AS@&t@_TR_SH([ac_cv_sizeof_$1])],
679 [AS@&t@_TR_SH(ac_cv_sizeof_$1)=1])
681 # fake use of 's' for illustrative purposes:
683 echo "s is defined as ${s}"
685 AS@&t@_VAR_POPDEF([s])
688 RUBY_CHECK_SIZEOF(int)
689 echo "ac_cv_sizeof_int=${ac_cv_sizeof_int}"
693 AT_CHECK_CONFIGURE([], [],
694 [[checking size of int... 1
695 ac_cv_sizeof_size is defined as 42
697 configure: creating ./config.status
698 config.status: creating config.h
703 # However, defining a macro named 'printf' _is_ expected to affect
704 # the functioning of AS_ECHO.
707 [[# At this point in a configure script, defining shell functions is safe.
708 fn_printf_override () {
710 printf '+ %s\n' "$arg"
714 m4@&t@_pushdef([printf], [fn_printf_override])
715 AC_MSG_NOTICE([checking whether m4sugar echo works... yes])
716 AC_MSG_CHECKING([whether m4sugar echo_n works])
718 m4@&t@_popdef([printf])
722 AT_CHECK_CONFIGURE([], [],
724 + configure: checking whether m4sugar echo works... yes
726 + checking whether m4sugar echo_n works... @&t@
729 configure: creating ./config.status
730 config.status: creating config.h
737 ## ----------------- ##
738 ## AS_EXECUTABLE_P. ##
739 ## ----------------- ##
741 # Check for executable regular files.
742 AT_SETUP([AS@&t@_EXECUTABLE_P])
745 AT_DATA_M4SH([script.as],
748 if AS_EXECUTABLE_P([/]); then
753 cat > foo.sh <<\EOF || AS_EXIT([1])
757 # File systems like FAT tend to fake executable permissions on all files.
758 # At this point, foo.sh should be executable iff permissions are faked.
759 AS_EXECUTABLE_P([foo.sh])
761 (./foo.sh) >/dev/null 2>&1
764 *[[1-9]]*:*[[1-9]]* | 0:0 ) echo 2 ;;
765 *) echo "fail ($st1:$st2)" ;;
767 # Now things better be executable
768 chmod a+x foo.sh || AS_EXIT([2])
769 mkdir 'two spaces' || AS_EXIT([3])
770 'two spaces'/../foo.sh || AS_EXIT([4])
771 if AS_EXECUTABLE_P(["two spaces/../foo.sh"]); then
779 AT_CHECK([$CONFIG_SHELL ./script], [],
793 # Exit scripts with given status.
794 AT_SETUP([AS@&t@_EXIT])
795 AT_KEYWORDS([m4sh AS@&t@_SET_STATUS])
797 AT_DATA_M4SH([script.as],
799 test x${1} = xa && AS_EXIT
800 test x${1} = xb && AS_EXIT([${2}])
801 test x${1} = xc && { AS_SET_STATUS([${2}]); AS_EXIT; }
802 test x${1} = xd && trap 's=$?; echo $s; AS_EXIT([$s])' 0
803 test x${2} = xe && set -e
804 test $[#] -gt 0 || AS_EXIT
806 dnl Solaris /bin/sh 'set -e' doesn't react to failed function calls
808 && { echo 'skipping rest of test: set -e support is lousy'; exit 77; }
813 AT_CHECK([$CONFIG_SHELL ./script], [1])
814 AT_CHECK([$CONFIG_SHELL ./script ''], [4])
815 AT_CHECK([$CONFIG_SHELL ./script a], [0])
816 AT_CHECK([$CONFIG_SHELL ./script b], [0])
817 AT_CHECK([$CONFIG_SHELL ./script b 0], [0])
818 AT_CHECK([$CONFIG_SHELL ./script b 2], [2])
819 AT_CHECK([$CONFIG_SHELL ./script c 0], [0])
820 AT_CHECK([$CONFIG_SHELL ./script c 2], [2])
821 AT_CHECK([$CONFIG_SHELL ./script d], [4], [[4
823 dnl If we got to this point without a FAIL, then AS_EXIT at least works.
824 dnl The rest of this test relies on semi-decent 'set -e' support, even
825 dnl though m4sh in general should not try to rely on it because of
826 dnl portability nightmares on what constructs are considered errors across
827 dnl various shells; therefore, an overall SKIP result is desirable on
828 dnl broken shells like Solaris /bin/sh.
829 AT_CHECK([$CONFIG_SHELL ./script '' e], [3])
830 AT_CHECK([$CONFIG_SHELL ./script d e], [3], [stdout])
831 dnl NetBSD sh fails to output on stderr here.
832 AT_CHECK([grep 3 stdout || exit 77], [], [ignore])
843 AT_SETUP([AS@&t@_MKDIR_P])
846 AT_DATA_M4SH([script.as],
852 AS_MKDIR_P(["$pwd/1/2/3/4/5/6"])
853 test -d "$pwd/1/2/3/4/5/6" ||
854 AS_ERROR([$pwd/1/2/3/4/5/6 has not been properly created])
856 AS_MKDIR_P(["a/b/c/d/e/f"])
857 test -d a/b/c/d/e/f ||
858 AS_ERROR([a/b/c/d/e/f has not been properly created])
863 AT_CHECK([$CONFIG_SHELL ./script])
870 ## -------------------- ##
871 ## AS_VERSION_COMPARE. ##
872 ## -------------------- ##
874 # Three-way version comparison.
875 AT_SETUP([AS@&t@_VERSION_COMPARE])
878 AT_DATA_M4SH([script.as],
881 m4_define([VERSION_COMPARE_TEST],
882 [AS_VERSION_COMPARE([$1], [$3], [result='<'], [result='='], [result='>'])
883 test "X$result" = "X$2" ||
884 AS_ERROR([version $1 $result $3; should be $1 $2 $3])
886 [AS_VERSION_COMPARE([$3], [$1], [result='<'], [result='='], [result='>'])
887 test "X$result" = "X>" ||
888 AS_ERROR([version $3 $result $1; should be $3 > $1])])])
890 VERSION_COMPARE_TEST([], =, [])
891 VERSION_COMPARE_TEST([1.0], =, [1.0])
892 VERSION_COMPARE_TEST([alpha-1.0], =, [alpha-1.0])
894 # These tests are taken from libc/string/tst-svc.expect.
896 000 001 00 00a 01 01a 0 0a 2.8 2.8-0.4 20 21 22 212 CP037 CP345 CP1257
897 foo foo-0.4 foo-0.4a foo-0.4b foo-0.5 foo-0.10.5 foo-3.01 foo-3.0
898 foo-3.0.0 foo-3.0.1 foo-3.2 foo-3.10 foo00 foo0
901 for test2 in $tst_svc_expect; do
902 VERSION_COMPARE_TEST([$test1], <, [$test2])
910 AT_CHECK([$CONFIG_SHELL ./script])
924 AT_DATA_M4SH([script.as],
927 test "$as_me" = script || AS_ECHO([["incorrect value of \$as_me: $as_me"]])
931 AT_CHECK([$CONFIG_SHELL ./script])
938 ## ----------------------------- ##
939 ## Negated classes in globbing. ##
940 ## ----------------------------- ##
942 # According to https://www.in-ulm.de/~mascheck/bourne/, all shells with
943 # functions also support '[!...]'. But '[^...]' is not universally supported.
945 AT_SETUP([Negated classes in globbing])
948 AT_DATA_M4SH([script.as],
951 case 'with!two!bangs' in
953 *) AS_ERROR([['*[!a-z]*' didn't match 'with!two!bangs']]);;
957 *[[!a-z]]*) AS_ERROR([['*[!a-z]*' matched 'without']]);;
962 AT_CHECK([$CONFIG_SHELL ./script])
966 ## ---------------------------- ##
967 ## Null variable substitution. ##
968 ## ---------------------------- ##
970 # According to https://www.in-ulm.de/~mascheck/bourne/, all shells with
971 # functions also support '${a:-b}'.
973 AT_SETUP([Null variable substitution])
976 AT_DATA_M4SH([script.as],
982 case ${a:-x}${b:-y}${c:-z} in
986 case ${a-x}${b-y}${c-z} in
991 case ${a+x}${b+y}${c+z} in
995 case ${a:+x}${b:+y}${c:+z} in
1000 case ${a=x}${b=y}${c=z} in
1005 case ${a:=x}${b:=y}${c:=z} in
1016 (: ${a?oops}; echo fail) 2>err && exit 8
1017 grep oops err >/dev/null || exit 9
1018 test "${b?oops}" = '' || exit 10
1019 test "${c?oops}" = . || exit 11
1020 (: ${a:?oops}; echo fail) 2>err && exit 12
1021 grep oops err >/dev/null || exit 13
1022 (: ${b:?oops}; echo fail) 2>err && exit 14
1023 grep oops err >/dev/null || exit 15
1024 test "${c:?oops}" = . || exit 16
1028 AT_CHECK([$CONFIG_SHELL ./script])
1033 ## ------------------- ##
1034 ## Functions Support. ##
1035 ## ------------------- ##
1037 # All m4sh scripts require function support.
1039 AT_SETUP([Functions Support])
1042 AT_DATA_M4SH([script.as],
1058 if func_success; then
1059 if func_failure; then
1060 AS_ERROR([func_failure passed])
1063 AS_ERROR([func_success failed])
1068 AT_CHECK([$CONFIG_SHELL ./script])
1075 ## ------------------------------ ##
1076 ## Functions and return Support. ##
1077 ## ------------------------------ ##
1079 # All m4sh scripts require working return within functions.
1081 AT_SETUP([Functions and return Support])
1084 AT_DATA_M4SH([script.as],
1096 if func_success; then
1097 if func_failure; then
1098 AS_ERROR([func_failure passed])
1101 AS_ERROR([func_success failed])
1106 AT_CHECK([$CONFIG_SHELL ./script])
1111 ## --------------------------- ##
1112 ## Nested AS_REQUIRE_SHELL_FN. ##
1113 ## --------------------------- ##
1115 # Hypothesis: M4sh expands nested AS_REQUIRE_SHELL_FN
1118 AT_SETUP([Nested AS@&t@_REQUIRE_SHELL_FN])
1121 AT_DATA_M4SH([script.as], [[dnl
1122 m4_define([INIT], [oops])dnl
1125 m4_defun([TEST_FUNC2_BODY], [
1129 m4_defun([TEST_FUNC1_BODY], [
1130 AS_REQUIRE_SHELL_FN([test_func2], [], [TEST_FUNC2_BODY])
1134 AS_REQUIRE_SHELL_FN([test_func1], [], [TEST_FUNC1_BODY])
1139 AT_CHECK([$CONFIG_SHELL ./script])
1144 ## ------------------- ##
1145 ## Nested AS_REQUIRE. ##
1146 ## ------------------- ##
1148 # Hypothesis: M4sh expands the requirements of AS_REQUIRE in the
1149 # requested diversion, even if other AS_REQUIREs are interleaved.
1151 AT_SETUP([Nested AS@&t@_REQUIRE])
1154 AT_DATA_M4SH([script.as], [[dnl
1157 m4_defun([in_fn_diversion], still_in_m4sh_init_fn=yes)
1158 m4_defun([not_in_fn_diversion], still_in_m4sh_init_fn=no)
1160 m4_defun([NESTED], [nested_require_in_fn_diversion=$still_in_m4sh_init_fn])
1162 m4_defun([OUTER], [AS_REQUIRE([NESTED])dnl
1163 outer_require_in_fn_diversion=$still_in_m4sh_init_fn])
1165 m4_defun([test_init], [
1166 AS_REQUIRE([in_fn_diversion], , [M4SH-INIT-FN])
1167 AS_REQUIRE([OUTER], , [M4SH-INIT-FN])
1168 AS_REQUIRE([not_in_fn_diversion], , [M4SH-INIT-FN])
1172 if test $outer_require_in_fn_diversion != yes; then AS_EXIT([1]); fi
1173 if test $nested_require_in_fn_diversion != no; then AS_EXIT([1]); fi
1177 AT_CHECK([$CONFIG_SHELL ./script])
1182 ## ------------------------------------ ##
1183 ## AS_REQUIRE_SHELL_FN and m4_require. ##
1184 ## ------------------------------------ ##
1186 # Hypothesis: M4sh expands the requirements of AS_REQUIRE_SHELL_FN
1187 # in M4SH-INIT-FN. This changed after Autoconf 2.63.
1189 AT_SETUP([AS@&t@_REQUIRE_SHELL_FN and m4@&t@_require])
1192 AT_DATA_M4SH([script.as], [[dnl
1195 m4_defun([in_m4_sh_init], still_in_m4sh_init=yes)
1196 m4_defun([not_in_m4_sh_init], still_in_m4sh_init=no)
1198 m4_defun([error_if_emitted_in_m4sh_init], [
1199 if test x$still_in_m4sh_init = xyes; then
1200 AS_ERROR([requirement emitted in M4SH-INIT])
1204 m4_defun([TEST_FUNC_BODY], [
1205 m4_require([error_if_emitted_in_m4sh_init])
1206 : echo in shell function, with parameter = [$]1
1210 m4_defun([test_init], [
1211 AS_REQUIRE([in_m4_sh_init], , [M4SH-INIT-FN])
1212 AS_REQUIRE_SHELL_FN([test_func], [], [TEST_FUNC_BODY])
1213 AS_REQUIRE([not_in_m4_sh_init])
1217 test_func parameter1
1221 AT_CHECK([$CONFIG_SHELL ./script])
1226 ## -------------- ##
1227 ## AS_HELP_STRING ##
1228 ## -------------- ##
1230 AT_SETUP([AS@&t@_HELP_STRING])
1231 AT_KEYWORDS([m4sh m4@&t@_text_wrap m4@&t@_expand])
1233 AT_DATA_M4SH([script.as],
1236 echo "AS_HELP_STRING([--an-option],[some text])"
1237 echo "AS_HELP_STRING([--another-much-longer-option],
1238 [some other text which should wrap at our default of 80 characters.])"
1239 echo "AS_HELP_STRING([--fooT=barT], [foo bar])"
1240 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@], [foo bar])"
1241 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@123456789], [foo bar])"
1242 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@1234567890], [foo bar])"
1243 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@12345678901], [foo bar])"
1244 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@123456789012], [foo bar])"
1245 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@1234567890123], [foo bar])"
1246 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@],
1247 [some other text which should wrap at our default of 80 characters.])"
1248 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@123456789],
1249 [some other text which should wrap at our default of 80 characters.])"
1250 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@1234567890],
1251 [some other text which should wrap at our default of 80 characters.])"
1252 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@12345678901],
1253 [some other text which should wrap at our default of 80 characters.])"
1254 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@123456789012],
1255 [some other text which should wrap at our default of 80 characters.])"
1256 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@1234567890123],
1257 [some other text which should wrap at our default of 80 characters.])"
1258 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@],
1259 [some other @<][:@ex@:][>@ which should wrap at our default of 80 characters.])"
1260 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@123456789],
1261 [some other @<][:@ex@:][>@ which should wrap at our default of 80 characters.])"
1262 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@1234567890],
1263 [some other @<][:@ex@:][>@ which should wrap at our default of 80 characters.])"
1264 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@12345678901],
1265 [some other @<][:@ex@:][>@ which should wrap at our default of 80 characters.])"
1266 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@123456789012],
1267 [some other @<][:@ex@:][>@ which should wrap at our default of 80 characters.])"
1268 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@1234567890123],
1269 [some other @<][:@ex@:][>@ which should wrap at our default of 80 characters.])"
1270 echo "AS_HELP_STRING([[--foo[=bar]]],
1271 [some other t[]t which should wrap at our default of 80 characters.])"
1272 echo "AS_HELP_STRING([[--foo[=bar]123456789]],
1273 [some other t[]t which should wrap at our default of 80 characters.])"
1274 echo "AS_HELP_STRING([[--foo[=bar]1234567890]],
1275 [some other t[]t which should wrap at our default of 80 characters.])"
1276 echo "AS_HELP_STRING([[--foo[=bar]12345678901]],
1277 [some other t[]t which should wrap at our default of 80 characters.])"
1278 echo "AS_HELP_STRING([[--foo[=bar]123456789012]],
1279 [some other t[]t which should wrap at our default of 80 characters.])"
1280 echo "AS_HELP_STRING([[--foo[=bar]1234567890123]],
1281 [some other t[]t which should wrap at our default of 80 characters.])"
1282 m4_define([mac], [MACRO])dnl
1283 echo "AS_HELP_STRING([--mac], [mac])"
1284 echo "AS_HELP_STRING([--o1, --o2], [two
1285 options, one description])"
1286 echo "AS_HELP_STRING([[[--o3, --o4]]], [comma inside literal quoting])"
1287 echo "AS_HELP_STRING([--tune1], [check out the tuned formatting],
1289 echo "AS_HELP_STRING([--tune2], [check out the tuned formatting],
1291 echo "AS_HELP_STRING([--tune3], [check out the tuned formatting],
1293 echo "AS_HELP_STRING([--tune4], [check out the tuned formatting],
1298 AT_CHECK([$CONFIG_SHELL ./script], [0],
1299 [[ --an-option some text
1300 --another-much-longer-option
1301 some other text which should wrap at our default of
1305 --foo[=bar]123456789 foo bar
1306 --foo[=bar]1234567890 foo bar
1307 --foo[=bar]12345678901 foo bar
1308 --foo[=bar]123456789012 foo bar
1309 --foo[=bar]1234567890123
1311 --foo[=bar] some other text which should wrap at our default of
1313 --foo[=bar]123456789 some other text which should wrap at our default of
1315 --foo[=bar]1234567890 some other text which should wrap at our default of
1317 --foo[=bar]12345678901 some other text which should wrap at our default of
1319 --foo[=bar]123456789012 some other text which should wrap at our default of
1321 --foo[=bar]1234567890123
1322 some other text which should wrap at our default of
1324 --foo[=bar] some other [ex] which should wrap at our default of
1326 --foo[=bar]123456789 some other [ex] which should wrap at our default of
1328 --foo[=bar]1234567890 some other [ex] which should wrap at our default of
1330 --foo[=bar]12345678901 some other [ex] which should wrap at our default of
1332 --foo[=bar]123456789012 some other [ex] which should wrap at our default of
1334 --foo[=bar]1234567890123
1335 some other [ex] which should wrap at our default of
1337 --foo[=bar] some other t[]t which should wrap at our default of
1339 --foo[=bar]123456789 some other t[]t which should wrap at our default of
1341 --foo[=bar]1234567890 some other t[]t which should wrap at our default of
1343 --foo[=bar]12345678901 some other t[]t which should wrap at our default of
1345 --foo[=bar]123456789012 some other t[]t which should wrap at our default of
1347 --foo[=bar]1234567890123
1348 some other t[]t which should wrap at our default of
1351 --o1, --o2 two options, one description
1352 [--o3, --o4] comma inside literal quoting
1353 --tune1 check out the tuned formatting
1354 --tune2 check out the tuned formatting
1355 --tune3 check out the
1358 --tune4 check out the tuned
1365 ## ------------------- ##
1366 ## AS_IF and AS_CASE. ##
1367 ## ------------------- ##
1369 AT_SETUP([AS@&t@_IF and AS@&t@_CASE])
1370 AT_KEYWORDS([m4sh m4@&t@_map_args_pair])
1372 AT_DATA_M4SH([script.as], [[dnl
1374 # Syntax checks: cope with empty arguments.
1375 AS_IF([:], [], [echo wrong])
1376 AS_IF([:], [echo one], [echo wrong])
1377 AS_IF([false], [echo wrong], [echo two])
1378 AS_IF([false], [echo wrong])
1380 AS_IF([false], [echo wrong],
1382 AS_IF([false], [echo wrong],
1385 AS_IF([false], [echo wrong],
1386 [false], [echo wrong])
1387 AS_IF([false], [echo wrong],
1388 [false], [echo wrong],
1390 AS_IF([false], [echo wrong],
1391 [false], [echo wrong],
1395 AS_CASE([foo], [echo seven])
1397 [foo], [echo eight],
1403 [bar], [echo wrong],
1407 # check for nesting, lists, and side effects, and quoting robustness
1409 AS_IF([AS_IF([$empty], [echo eleven])]) && AS_CASE([foo]) && echo twelve
1411 AS_IF([touch file; false]) && echo thirteen
1412 test -f file && echo fourteen
1414 AS_CASE([`touch file; false`]) && test -f file && echo fifteen
1415 dnl The next line is badly underquoted; don't intentionally copy this style.
1416 AS_CASE([foo], [foo], m4_do(AS_CASE([bar], [bar], [echo sixteen])))
1417 dnl Handle blank arguments.
1418 AS_IF([false], [:], [ ]) && AS_CASE([foo], [foo], []
1420 m4_define([empty])AS_IF([:], [empty]
1421 ) && AS_IF([false], [], [empty]
1422 ) || AS_CASE([foo], [foo], [empty]) && echo eighteen
1423 dnl Allow for users that don't know to avoid trailing whitespace
1427 AS_IF([false], [], [echo twenty])
1430 # check that require works correctly
1431 m4_for([n], 1, 9, [],
1432 [m4_defun([FOO]n, [foo]n[=]n)dnl
1434 [m4_require([FOO]]n[)dnl
1439 echo "foo1=$foo1 bar1=$bar1"
1440 AS_IF([:], [], [BAR2])
1441 echo "foo2=$foo2 bar2=$bar2"
1442 AS_IF([false], [BAR3])
1443 echo "foo3=$foo3 bar3=$bar3"
1444 AS_IF([false], [], [BAR4])
1445 echo "foo4=$foo4 bar4=$bar4"
1446 AS_CASE([x], [x], [BAR5])
1447 echo "foo5=$foo5 bar5=$bar5"
1448 AS_CASE([x], [y], [BAR6])
1449 echo "foo6=$foo6 bar6=$bar6"
1453 echo "foo7=$foo7 bar7=$bar7"
1457 echo "foo8=$foo8 bar8=$bar8"
1461 echo "foo9=$foo9 bar9=$bar9"
1465 AT_CHECK([$CONFIG_SHELL ./script], [0], [[one
1496 dnl stress test for large number of conditionals
1497 dnl too large, and we start tickling shell bugs
1498 m4_pushdef([limit], [1000])dnl
1499 AT_DATA_M4SH([script.as], [[dnl
1501 AS_IF(m4_shift(m4_for([i], [1], ]limit[, [], [, test $[1] = i, echo i])))
1502 AS_IF(m4_shift(m4_for([i], [1], ]limit[, [], [, test $[1] = i, echo i])),
1504 AS_CASE([$[1]]m4_for([i], [1], ]limit[, [], [, i, echo i]))
1505 AS_CASE([$[1]]m4_for([i], [1], ]limit[, [], [, i, echo i]), [echo default])
1508 dnl Add --force so autom4te doesn't think 'script' is still up to date.
1509 AT_CHECK_M4SH([--force])
1510 AT_CHECK([$CONFIG_SHELL ./script 1], [0], [[1
1515 AT_CHECK([$CONFIG_SHELL ./script limit], [0], [limit
1520 AT_CHECK([$CONFIG_SHELL ./script default], [0], [[default
1532 AT_SETUP([AS@&t@_FOR])
1535 AT_DATA_M4SH([script.as], [[dnl
1539 AS_FOR([m4var], [shvar], [a],
1540 [echo "m4var $shvar"])
1541 AS_FOR([m4var], [shvar], [b c],
1542 [echo "m4var $shvar"])
1544 AS_FOR([m4var], [shvar], [$list],
1545 [echo "m4var $shvar"])
1546 AS_FOR([m4var], [shvar], ["$list"],
1547 [echo "m4var $shvar"])
1548 AS_FOR([m4var], [shvar], ['$list'],
1549 [echo "m4var $shvar"])
1550 AS_FOR([m4var], [shvar], [\'],
1551 [echo "m4var $shvar"])
1553 # Syntax checks: cope with empty/blank arguments.
1555 AS_FOR([], [shvar], [],
1556 [echo "m4_defn([]) $shvar"])
1558 AS_FOR([], [shvar], [`touch file`])
1559 test -f file || exit 1
1560 AS_FOR([], [shvar], [], [ ])
1561 m4_define([empty])AS_FOR([], [shvar], [], [empty])
1563 # Check that break works.
1566 AS_FOR([m4var], [shvar], [h i],
1567 [echo "m4var"; break 2])
1572 AS_FOR([m4var], [shvar], [j],
1573 [echo "m4var"; break 2])
1579 AT_CHECK([$CONFIG_SHELL ./script], [0], [[a a
1596 ## --------------- ##
1597 ## AS_LITERAL_IF. ##
1598 ## --------------- ##
1600 AT_SETUP([AS@&t@_LITERAL_IF])
1601 AT_KEYWORDS([m4sh AS@&t@_LITERAL_WORD_IF AS@&t@_LITERAL_HEREDOC_IF])
1603 AT_DATA_M4SH([script.as], [[dnl
1605 echo AS_LITERAL_IF([lit], [ok], [ERR]) 1
1606 echo AS_LITERAL_IF([l-/.it], [ok], [ERR]) 2
1607 echo AS_LITERAL_IF([l''it], [ERR], [ok]) 3
1608 echo AS_LITERAL_IF([l$it], [ERR], [ok]) 4
1609 echo AS_LITERAL_IF([l$it], [ERR1], [ERR2], [ok]) 5
1610 echo AS_LITERAL_IF([l${it}], [ERR1], [ERR2], [ok]) 6
1611 echo AS_LITERAL_IF([l`case a in b) ;; esac`it], [ERR], [ok]) 7
1612 echo AS_LITERAL_IF([l`case a in b) ;; esac`it], [ERR1], [ok], [ERR2]) 8
1613 m4_define([mac], [l-/.it])
1614 echo AS_LITERAL_IF([mac], [ok], [ERR]) 9
1615 echo AS_LITERAL_IF([mac($, ``)], [ok], [ERR]) 10
1616 m4_define([mac], [l$it])
1617 echo AS_LITERAL_IF([mac], [ERR], [ok]) 11
1618 echo AS_LITERAL_IF([mac], [ERR1], [ERR2], [ok]) 12
1619 m4_define([mac], [l``it])
1620 echo AS_LITERAL_IF([mac], [ERR], [ok]) 13
1621 echo AS_LITERAL_IF([mac], [ERR1], [ok], [ERR2]) 14
1622 echo AS_LITERAL_IF([ a ][
1624 echo AS_LITERAL_WORD_IF([ a ][
1626 echo AS_LITERAL_HEREDOC_IF([ a ][
1628 echo AS_LITERAL_IF([(a)], [ERR], [ok]) 18
1629 echo AS_LITERAL_WORD_IF([(a)], [ERR], [ok]) 19
1630 echo AS_LITERAL_HEREDOC_IF([(a)], [ok], [ERR]) 20
1631 echo AS_LITERAL_IF([@S|@a], [ERR], [ok]) 21
1632 echo AS_LITERAL_WORD_IF([@S|@a], [ERR], [ok]) 22
1633 echo AS_LITERAL_HEREDOC_IF([@S|@a], [ERR], [ok]) 23
1634 echo AS_LITERAL_IF([${a+b}], [ERR1], [ok], [ERR2]) 24
1635 echo AS_LITERAL_IF([${a=b}], [ERR1], [ok], [ERR2]) 25
1636 echo AS_LITERAL_IF([a+b], [ok], [ERR1], [ERR2]) 26
1637 echo AS_LITERAL_IF([a=b], [ok], [ERR1], [ERR2]) 27
1641 AT_CHECK([$CONFIG_SHELL ./script], [],
1674 ## --------------------- ##
1675 ## AS_TR_SH, AS_TR_CPP. ##
1676 ## --------------------- ##
1678 AT_SETUP([AS@&t@_TR_SH and AS@&t@_TR_CPP])
1680 AT_DATA_M4SH([script.as], [[dnl
1682 m4_define([abc], [hI])m4_define([ABC], [Hi])
1683 m4_define([hi], [oops])m4_define([HI], [OOPS])
1684 echo AS_TR_SH(abc) AS_TR_SH(aBc) AS_TR_SH(ABC)
1685 echo AS_TR_SH([abc]) AS_TR_SH([aBc]) AS_TR_SH([ABC])
1686 echo AS_TR_SH([[abc]]) AS_TR_SH([[aBc]]) AS_TR_SH([[ABC]])
1687 echo AS_TR_CPP(abc) AS_TR_CPP(aBc) AS_TR_CPP(ABC)
1688 echo AS_TR_CPP([abc]) AS_TR_CPP([aBc]) AS_TR_CPP([ABC])
1689 echo AS_TR_CPP([[abc]]) AS_TR_CPP([[aBc]]) AS_TR_CPP([[ABC]])
1691 [var=abc vAr=aBc VAR=ABC]
1692 echo AS_TR_SH($var) AS_TR_SH($vAr) AS_TR_SH($VAR)
1693 echo AS_TR_SH([$var]) AS_TR_SH([$vAr]) AS_TR_SH([$VAR])
1694 echo AS_TR_SH([[$var]]) AS_TR_SH([[$vAr]]) AS_TR_SH([[$VAR]])
1695 echo AS_TR_CPP($var) AS_TR_CPP($vAr) AS_TR_CPP($VAR)
1696 echo AS_TR_CPP([$var]) AS_TR_CPP([$vAr]) AS_TR_CPP([$VAR])
1697 echo AS_TR_CPP([[$var]]) AS_TR_CPP([[$vAr]]) AS_TR_CPP([[$VAR]])
1699 echo AS_TR_SH(`echo abc`) AS_TR_SH(`echo aBc`) AS_TR_SH(`echo ABC`)
1700 echo AS_TR_SH([`echo abc`]) AS_TR_SH([`echo aBc`]) AS_TR_SH([`echo ABC`])
1701 echo AS_TR_SH([[`echo abc`]]) AS_TR_SH([[`echo aBc`]]) AS_TR_SH([[`echo ABC`]])
1702 echo AS_TR_CPP(`echo abc`) AS_TR_CPP(`echo aBc`) AS_TR_CPP(`echo ABC`)
1703 echo AS_TR_CPP([`echo abc`]) AS_TR_CPP([`echo aBc`]) AS_TR_CPP([`echo ABC`])
1704 echo AS_TR_CPP([[`echo abc`]]) AS_TR_CPP([[`echo aBc`]]) AS_TR_CPP([[`echo ABC`]])
1707 echo AS_TR_SH([a.b/c+*-=])
1708 echo AS_TR_CPP([a.b/c+*-=])
1710 echo AS_TR_SH([$var])
1711 echo AS_TR_CPP([$var])
1712 m4_define([macro], [a.b/c+*-=])
1713 echo AS_TR_SH([macro])
1714 echo AS_TR_CPP([macro])
1718 AT_CHECK([$CONFIG_SHELL ./script], [],
1748 dnl Check that of the last 6 macros, only 2 needed command substitution.
1749 dnl This test abuses our knowledge of m4sh internals a bit; oh well.
1750 AT_CHECK([tab=' ' # a single ASCII tab character
1751 sed -n '/start here/,$ {
1753 }' script | wc -l | sed "s/[[ $tab]]//g" ], [], [[2
1763 AT_SETUP([AS@&t@_VAR basics])
1764 AT_KEYWORDS([m4sh AS@&t@_VAR_COPY AS@&t@_VAR_SET AS@&t@_VAR_GET])
1765 AT_KEYWORDS([AS@&t@_VAR_TEST_SET AS@&t@_VAR_SET_IF AS@&t@_VAR_IF])
1766 AT_KEYWORDS([AS@&t@_VAR_PUSHDEF AS@&t@_VAR_POPDEF])
1768 AT_DATA_M4SH([script.as], [[dnl
1770 m4_define([with], [WITH])
1772 dnl AS_VAR_SET_IF also covers AS_VAR_TEST_SET
1773 AS_VAR_SET_IF([foo], [echo oops]) && echo ok
1774 AS_VAR_IF([foo], [], [echo ok], [echo oops])
1776 AS_VAR_SET_IF([foo], [echo ok])
1777 AS_VAR_SET([foo], ['\a "weird" `value` with; $fun '\''characters
1779 AS_VAR_COPY([bar], [foo])
1781 AS_ECHO(["AS_VAR_GET([foo])-"])
1782 AS_VAR_SET_IF([foo], [echo ok], [echo oops])
1783 AS_VAR_IF([foo], [string], [echo oops]) && echo ok
1784 AS_VAR_PUSHDEF([tmp], [foo])
1785 AS_VAR_IF([tmp], ['\a "weird" `value` with; $fun '\''characters
1786 '], [echo ok], [echo oops]) # 'font-lock
1787 AS_VAR_POPDEF([tmp])
1788 m4_ifdef([tmp], [echo oops])
1790 # Indirects via shell vars.
1793 AS_VAR_SET_IF([foo$num], [echo oops]) && echo ok
1794 AS_VAR_IF([foo$num], [], [echo ok], [echo oops])
1796 AS_VAR_SET_IF([foo$num], [echo ok])
1797 AS_VAR_SET([foo$num], ['\a "weird" `value` with; $fun '\''characters
1799 AS_VAR_COPY([bar], [foo$num])
1801 AS_VAR_COPY([foo$num], [bar])
1803 AS_ECHO(["AS_VAR_GET([foo$num])-"])
1804 AS_VAR_SET_IF([foo$num], [echo ok], [echo oops])
1805 AS_VAR_IF([foo$num], [string], [echo oops]) && echo ok
1806 AS_VAR_PUSHDEF([tmp], [foo$num])
1807 AS_VAR_IF([tmp], ['\a "weird" `value` with; $fun '\''characters
1808 '], [echo ok], [echo oops]) # 'font-lock
1809 AS_VAR_POPDEF([tmp])
1810 m4_ifdef([tmp], [echo oops])
1812 # Indirects via command substitution.
1814 AS_VAR_SET_IF([`echo foo3`], [echo oops]) && echo ok
1815 AS_VAR_IF([`echo foo3`], [], [echo ok], [echo oops])
1817 AS_VAR_SET_IF([`echo foo3`], [echo ok])
1818 AS_VAR_SET([`echo foo3`], ['\a "weird" `value` with; $fun '\''characters
1820 AS_VAR_COPY([bar], [`echo foo3`])
1822 AS_VAR_COPY([`echo foo4`], [bar])
1824 AS_ECHO(["AS_VAR_GET([`echo foo4`])-"])
1825 AS_VAR_SET_IF([`echo foo4`], [echo ok], [echo oops])
1826 AS_VAR_IF([`echo foo4`], [string], [echo oops]) && echo ok
1827 AS_VAR_PUSHDEF([tmp], [`echo foo4`])
1828 AS_VAR_IF([tmp], ['\a "weird" `value` with; $fun '\''characters
1829 '], [echo ok], [echo oops]) # 'font-lock
1830 AS_VAR_POPDEF([tmp])
1831 m4_ifdef([tmp], [echo oops])
1836 AT_CHECK([$CONFIG_SHELL ./script], [], [[ok
1839 \a "weird" `value` WITH; $fun 'characters
1841 \a "weird" `value` WITH; $fun 'characters
1850 \a "weird" `value` WITH; $fun 'characters
1852 \a "weird" `value` WITH; $fun 'characters-
1860 \a "weird" `value` WITH; $fun 'characters
1862 \a "weird" `value` WITH; $fun 'characters-
1871 ## --------------- ##
1872 ## AS_VAR_APPEND. ##
1873 ## --------------- ##
1875 AT_SETUP([AS@&t@_VAR_APPEND])
1876 AT_KEYWORDS([m4sh AS@&t@_VAR])
1878 AT_DATA_M4SH([script.as], [[dnl
1881 AS_VAR_APPEND([foo], ["hello, "])
1882 AS_VAR_APPEND([foo], [world])
1884 # Indirects via shell vars.
1886 AS_VAR_APPEND([foo$num], ['hello, '])
1887 AS_VAR_APPEND([foo$num], [`echo "world"`])
1889 # Indirects via command substitution.
1891 AS_VAR_APPEND([`echo foo2`], [${h}])
1892 AS_VAR_APPEND([`echo foo2`], ["$w"])
1897 AT_CHECK([$CONFIG_SHELL ./script], [],
1906 ## -------------- ##
1908 ## -------------- ##
1910 AT_SETUP([AS@&t@_VAR_ARITH])
1911 AT_KEYWORDS([m4sh AS@&t@_VAR])
1913 AT_DATA_M4SH([script.as], [[dnl
1916 AS_VAR_ARITH([foo], [1 + 1])
1918 # Indirects via shell vars.
1920 AS_VAR_ARITH([foo$num], [\( 2 + 3 \) \* 4])
1922 # Indirects via command substitution.
1923 AS_VAR_ARITH([`echo foo2`], [0 + -2 + $foo1 / 2])
1928 AT_CHECK([$CONFIG_SHELL ./script], [],
1937 ## ----------------- ##
1938 ## AS_INIT cleanup. ##
1939 ## ----------------- ##
1941 AT_SETUP([AS@&t@_INIT cleanup])
1942 AT_KEYWORDS([m4sh m4@&t@_wrap m4@&t@_wrap_lifo])
1944 AT_DATA_M4SH([script.as], [[dnl
1945 dnl Registered before AS_INIT's cleanups
1946 m4_wrap([echo cleanup 1
1948 m4_pushdef([_AS_SHELL_FN_SPY])dnl neutralize the spy, we don't care about it
1950 dnl Registered after AS_INIT's cleanups, thus goes to KILL diversion
1951 m4_wrap([echo cleanup 2
1952 dnl However, nested wraps and diversions can still be used
1953 dnl Also, test wrapping text that looks like parameter reference
1954 m4_wrap([echo cleanup 3
1955 m4_divert_text([M4SH-INIT], [m4_define([foo], [$1])dnl
1958 dnl Registered before AS_INIT's cleanups
1959 m4_wrap_lifo([echo cleanup 5
1965 AT_CHECK([$CONFIG_SHELL ./script], [], [[prep 4
1974 ## -------------------------- ##
1975 ## AS_INIT basename __file__. ##
1976 ## -------------------------- ##
1978 AT_SETUP([AS@&t@_INIT basename __@&t@file__])
1981 AT_CHECK([mkdir sub || exit 77])
1982 AT_DATA_M4SH([sub/script.as], [[dnl
1985 AT_CHECK_AUTOM4TE([--language=m4sh sub/script.as -o script])
1986 AT_CHECK([grep '^# Generated from' script], [0], [dnl
1987 # Generated from script.as by ]m4_PACKAGE_STRING[.
1993 ## ------------------- ##
1994 ## AS_INIT_GENERATED. ##
1995 ## ------------------- ##
1997 AT_SETUP([AS@&t@_INIT_GENERATED])
1998 AT_KEYWORDS([AS@&t@_MESSAGE AS@&t@_MESSAGE_LOG_FD])
2000 dnl First run, no logging, tests shell selection
2001 AT_DATA_M4SH([script.as], [[dnl
2003 AS_INIT_GENERATED([child], [echo hello from child])
2005 AS_ECHO(["SHELL=$SHELL"])
2007 echo hello from parent
2008 AS_ECHO(["SHELL=$SHELL"])
2012 AT_CHECK([$CONFIG_SHELL ./script], [0], [stdout])
2013 AT_CHECK([grep 'SHELL=.' stdout], [0], [ignore])
2014 sed s/parent/child/ <stdout >expout
2015 AT_CHECK([./child], [0], [expout])
2020 AT_CHECK([$CONFIG_SHELL ./script], [0], [expout])
2021 AT_CHECK([cmp child child.bak])
2022 AT_CHECK([grep 'SHELL=.' stdout], [0], [ignore])
2023 sed s/parent/child/ <stdout >expout
2024 AT_CHECK([./child], [0], [expout])
2027 dnl Second run, with logging from parent and child, tests fd handling
2028 AT_DATA_M4SH([script.as], [[dnl
2031 m4_define([AS_MESSAGE_LOG_FD], [5])
2032 exec AS_MESSAGE_LOG_FD>log
2033 AS_INIT_GENERATED([$child], [echo hello1 from $child]) || AS_EXIT([1])
2035 m4_pushdef([AS_MESSAGE_LOG_FD])
2036 AS_MESSAGE([hello2 from ${child}child])
2037 m4_popdef([AS_MESSAGE_LOG_FD])
2038 exec AS_MESSAGE_LOG_FD>>log
2039 AS_MESSAGE([hello3 from child])
2041 AS_MESSAGE([hello from parent])
2042 dnl close log in parent before spawning child, for mingw
2043 exec AS_MESSAGE_LOG_FD>&-
2049 AT_CHECK([$CONFIG_SHELL ./script], [0], [[script: hello from parent
2051 child: hello2 from child
2052 child: hello3 from child
2054 AT_CHECK([[sed 's,:[0-9][0-9]*:,:0:,' log]], [0],
2055 [[script:0: hello from parent
2056 child:0: hello3 from child
2059 # Force write error creating a file on stdout
2060 if test -w /dev/full && test -c /dev/full; then
2061 AT_CHECK([$CONFIG_SHELL ./script /dev/full], [1], [ignore], [ignore])
2067 ## --------------- ##
2068 ## AS_MESSAGE_FD. ##
2069 ## --------------- ##
2071 AT_SETUP([AS@&t@_MESSAGE_FD])
2072 AT_KEYWORDS([AS@&t@_MESSAGE AS@&t@_MESSAGE_LOG_FD AS@&t_ORIGINAL_STDIN_FD])
2073 AT_KEYWORDS([AS@&t@_LINENO_PUSH])
2075 AT_DATA_M4SH([script.as], [[dnl
2077 m4_define([AS_ORIGINAL_STDIN_FD], [5])
2078 m4_define([AS_MESSAGE_LOG_FD], [6])
2079 m4_define([AS_MESSAGE_FD], [7])
2080 exec AS_ORIGINAL_STDIN_FD<&0 </dev/null AS_MESSAGE_LOG_FD>log
2081 if test $[#] -gt 0; then
2082 exec AS_MESSAGE_FD>/dev/null
2084 exec AS_MESSAGE_FD>&1
2086 AS_LINENO_PUSH([100])
2087 cat # tests that stdin is neutralized
2088 AS_MESSAGE([hello world])
2089 cat <&AS_ORIGINAL_STDIN_FD
2093 AT_CHECK([echo goodbye | $CONFIG_SHELL ./script], [0],
2094 [[script: hello world
2097 AT_CHECK([cat log], [0],
2098 [[script:100: hello world
2101 AT_CHECK([echo goodbye | $CONFIG_SHELL ./script silent], [0],
2104 AT_CHECK([cat log], [0],
2105 [[script:100: hello world
2111 ## --------------- ##
2112 ## _AS_CLEAN_DIR. ##
2113 ## --------------- ##
2115 AT_SETUP([_AS@&t@_CLEAN_DIR])
2117 dnl ensure that we can erase all files in a directory. Note that
2118 dnl _AS_CLEAN_DIR needs three globs to catch all these files.
2119 AT_DATA_M4SH([script.as], [[dnl
2121 # Unwritable subdirectories are common during 'make distcheck'.
2122 mkdir sub sub/unwritable || AS_ERROR([failed to mkdir])
2123 touch sub/unwritable/file || AS_ERROR([failed to touch])
2124 chmod a-wx sub/unwritable || AS_ERROR([failed to chmod])
2125 # Cygwin 1.5 can't touch 'sub/...', so make that file optional.
2126 touch sub/a sub/aa sub/aaa sub/.a sub/..a sub/.aa \
2127 || AS_ERROR([failed to touch])
2128 touch sub/... 2>/dev/null
2129 _AS_CLEAN_DIR([sub]) || AS_ERROR([failed to clean])
2130 # rmdir instead of 'rm -fr' here proves that we emptied sub.
2131 rmdir sub || AS_ERROR([failed to rmdir])
2135 AT_CHECK([$CONFIG_SHELL ./script])
2146 AT_DATA_M4SH([script.as], [[dnl
2154 AT_CHECK([$CONFIG_SHELL ./script], [], [foobar