5 # Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
6 # 2009, 2010 Free Software Foundation, Inc.
8 # This program is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation, either version 3 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21 ## ---------------- ##
23 ## ---------------- ##
28 # We cannot unset LINENO with Zsh, yet this test case relies on
29 # unsetting LINENO to compare its result when (i) LINENO is supported
30 # and when (ii) it is not.
31 # So just skip if the shell is ZSH.
32 AT_CHECK([test -n "${ZSH_VERSION+set}" && exit 77], ignore)
34 # AT_DATA_LINENO(FILE-NAME,
35 # UNSET-LINENO = true | false, COUNTER, COUNTER-RE)
36 # ----------------------------------------------------------------
37 # Produce the FILE-NAME M4sh script which uses the COUNTER LINENO or
38 # _oline_, which we can recognized via COUNTER-RE. Unset LINENO is
41 # Use COUNTER, COUNTER-RE = [__LINENO__], [LINENO]
42 # or = [__OLINE__], [_oline__]
44 # instead of the obvious $LINENO and __oline__, because they would
45 # be replaced in the test suite itself, even before creating these
46 # scripts. For the same reason, grep for LINENO and _oline__ (sic).
48 # UNSET-LINENO is a shell condition to make sure the scripts have the
49 # same number of lines in the output, so that their outputs be identical.
50 m4_define([AT_DATA_LINENO],
53 m4@&t@_divert_text([], [
55 AS@&t@_UNSET([LINENO])
60 grep 'Line: .*$4' "$[0]" >/dev/null ||
61 AS@&t@_ERROR([cannot find original script])
64 # If occurrences of $LINENO or __@&t@oline__ were wanted, create them.
65 sed 's/__LINENO__/$''LINENO/g;s/__OLINE__/__''oline__/g' $1.tas >$1.as
66 AT_CHECK([autom4te -l m4sh $1.as -o $1])
69 # `_oline_', once processed and ran, produces our reference.
70 # We check that we find ourselves by looking at a string which is
71 # available only in the original script: `_oline_'.
72 AT_DATA_LINENO([reference], [false], [__OLINE__], [_oline__])
73 AT_CHECK([./reference], 0, [stdout])
78 # Now using a maybe-functioning LINENO, with different call conventions.
79 # Be sure to be out of the PATH.
80 AT_CHECK([mkdir test || exit 77])
82 AT_DATA_LINENO([test/test-1], [false], [__LINENO__], [LINENO])
83 AT_CHECK([./test/test-1], 0, [expout])
84 AT_CHECK([(PATH=test$PATH_SEPARATOR$PATH; export PATH; exec test-1)],
86 AT_CHECK([sh ./test/test-1], 0, [expout])
88 # Now using a disabled LINENO, with different call conventions.
89 AT_DATA_LINENO([test/test-2], [true], [__LINENO__], [LINENO])
90 AT_CHECK([./test/test-2], 0, [expout])
91 AT_CHECK([(PATH=test$PATH_SEPARATOR$PATH; export PATH; exec test-2)],
93 AT_CHECK([sh ./test/test-2], 0, [expout])
99 ## ---------------------- ##
100 ## LINENO stack support. ##
101 ## ---------------------- ##
103 AT_SETUP([LINENO stack])
106 AT_DATA_M4SH([script.as],
109 AS_LINENO_PUSH([9999])
110 test $as_lineno = 9999 || AS_ERROR([bad as_lineno at depth 1])
111 AS_LINENO_PUSH([8888])
112 test $as_lineno = 9999 || AS_ERROR([bad as_lineno at depth 2])
114 test $as_lineno = 9999 || AS_ERROR([bad as_lineno at depth 1])
116 test x${as_lineno+set} = xset && AS_ERROR([as_lineno set at depth 0])
122 AT_CHECK([$CONFIG_SHELL ./script])
131 # Strip path from file.
132 AT_SETUP([AS@&t@_BASENAME])
135 AT_DATA_M4SH([script.as],
138 m4_define([BASENAME_TEST],
139 [base=`AS_BASENAME([$1])`
140 test "$base" = "$2" ||
141 echo "basename($1) = $base instead of $2" >&2
143 base=`_AS_BASENAME_SED([$1])`
144 test "$base" = "$2" ||
145 echo "basename_sed($1) = $base instead of $2" >&2])
147 BASENAME_TEST([//1], [1])
148 BASENAME_TEST([/1], [1])
149 BASENAME_TEST([./1], [1])
150 BASENAME_TEST([../../2], [2])
151 BASENAME_TEST([//1/], [1])
152 BASENAME_TEST([/1/], [1])
153 BASENAME_TEST([./1/], [1])
154 BASENAME_TEST([../../2], [2])
155 BASENAME_TEST([//1/3], [3])
156 BASENAME_TEST([/1/3], [3])
157 BASENAME_TEST([./1/3], [3])
158 BASENAME_TEST([../../2/3], [3])
159 BASENAME_TEST([//1/3///], [3])
160 BASENAME_TEST([/1/3///], [3])
161 BASENAME_TEST([./1/3///], [3])
162 BASENAME_TEST([../../2/3///], [3])
163 BASENAME_TEST([//1//3/], [3])
164 BASENAME_TEST([/1//3/], [3])
165 BASENAME_TEST([./1//3/], [3])
166 BASENAME_TEST([a.c], [a.c])
167 BASENAME_TEST([a.c/], [a.c])
168 BASENAME_TEST([/a.c/], [a.c])
169 BASENAME_TEST([/1/a.c], [a.c])
170 BASENAME_TEST([/1/a.c/], [a.c])
171 BASENAME_TEST([/1/../a.c], [a.c])
172 BASENAME_TEST([/1/../a.c/], [a.c])
173 BASENAME_TEST([./1/a.c], [a.c])
174 BASENAME_TEST([./1/a.c/], [a.c])
179 AT_CHECK([$CONFIG_SHELL ./script])
188 # Strip filename component.
189 AT_SETUP([AS@&t@_DIRNAME])
192 AT_DATA_M4SH([script.as],
195 # The EXPR variant is allowed to fail if `expr' was considered as too
196 # weak for us, in which case `as_expr=false'.
197 m4_define([DIRNAME_TEST],
198 [dir=`AS_DIRNAME([$1])`
199 test "$dir" = "$2" || (test -n "$3" && test "$dir" = "$3") ||
200 echo "dirname($1) = $dir instead of $2" >&2
202 if test "$as_expr" != false; then
203 dir=`_AS_DIRNAME_EXPR([$1])`
204 test "$dir" = "$2" || (test -n "$3" && test "$dir" = "$3") ||
205 echo "dirname_expr($1) = $dir instead of $2" >&2
208 dir=`_AS_DIRNAME_SED([$1])`
209 test "$dir" = "$2" || (test -n "$3" && test "$dir" = "$3") ||
210 echo "dirname_sed($1) = $dir instead of $2" >&2])
212 DIRNAME_TEST([/], [/])
213 DIRNAME_TEST([//], [//], [/])
214 DIRNAME_TEST([///], [/])
215 DIRNAME_TEST([//1], [//], [/])
216 DIRNAME_TEST([/1], [/])
217 DIRNAME_TEST([./1], [.])
218 DIRNAME_TEST([../../2], [../..])
219 DIRNAME_TEST([//1/], [//], [/])
220 DIRNAME_TEST([/1/], [/])
221 DIRNAME_TEST([./1/], [.])
222 DIRNAME_TEST([../../2], [../..])
223 DIRNAME_TEST([//1/3], [//1])
224 DIRNAME_TEST([/1/3], [/1])
225 DIRNAME_TEST([./1/3], [./1])
226 DIRNAME_TEST([../../2/3], [../../2])
227 DIRNAME_TEST([//1/3///], [//1])
228 DIRNAME_TEST([/1/3///], [/1])
229 DIRNAME_TEST([./1/3///], [./1])
230 DIRNAME_TEST([../../2/3///], [../../2])
231 DIRNAME_TEST([//1//3/], [//1])
232 DIRNAME_TEST([/1//3/], [/1])
233 DIRNAME_TEST([./1//3/], [./1])
234 DIRNAME_TEST([../../2//3/], [../../2])
239 AT_CHECK([$CONFIG_SHELL ./script])
249 # Print literal strings, with/without newline.
250 AT_SETUP([AS@&t@_ECHO and AS@&t@_ECHO_N])
253 AT_DATA_M4SH([script.as],
256 m4_define([ECHO_TEST],
257 [echo=`AS_ECHO(['$1'])`
258 test "X$echo" = 'X$1' ||
259 echo "AS@&t@_ECHO('"'$1'"') outputs '$echo'" >&2
261 echo=`AS_ECHO_N(['$1'])`
262 test "X$echo" = 'X$1' ||
263 echo "AS@&t@_ECHO_N('"'$1'"') outputs '$echo'" >&2])
267 ECHO_TEST([---...---])
276 ECHO_TEST([\a\b\c\f\n\r\t\v\"\])
288 AT_CHECK([$CONFIG_SHELL ./script])
298 # Exit scripts with given status.
299 AT_SETUP([AS@&t@_EXIT])
300 AT_KEYWORDS([m4sh AS@&t@_SET_STATUS])
302 AT_DATA_M4SH([script.as],
304 test x${1} = xa && AS_EXIT
305 test x${1} = xb && AS_EXIT([${2}])
306 test x${1} = xc && { AS_SET_STATUS([${2}]); AS_EXIT; }
307 test x${1} = xd && trap 's=$?; echo $s; AS_EXIT([$s])' 0
308 test x${2} = xe && set -e
309 test $[#] -gt 0 || AS_EXIT
311 dnl Solaris /bin/sh 'set -e' doesn't react to failed function calls
313 && { echo 'skipping rest of test: set -e support is lousy'; exit 77; }
318 AT_CHECK([$CONFIG_SHELL ./script], [1])
319 AT_CHECK([$CONFIG_SHELL ./script ''], [4])
320 AT_CHECK([$CONFIG_SHELL ./script a], [0])
321 AT_CHECK([$CONFIG_SHELL ./script b], [0])
322 AT_CHECK([$CONFIG_SHELL ./script b 0], [0])
323 AT_CHECK([$CONFIG_SHELL ./script b 2], [2])
324 AT_CHECK([$CONFIG_SHELL ./script c 0], [0])
325 AT_CHECK([$CONFIG_SHELL ./script c 2], [2])
326 AT_CHECK([$CONFIG_SHELL ./script d], [4], [[4
328 dnl If we got to this point without a FAIL, then AS_EXIT at least works.
329 dnl The rest of this test relies on semi-decent 'set -e' support, even
330 dnl though m4sh in general should not try to rely on it because of
331 dnl portability nightmares on what constructs are considered errors across
332 dnl various shells; therefore, an overall SKIP result is desirable on
333 dnl broken shells like Solaris /bin/sh.
334 AT_CHECK([$CONFIG_SHELL ./script '' e], [3])
335 AT_CHECK([$CONFIG_SHELL ./script d e], [3], [stdout])
336 dnl NetBSD sh fails to output on stderr here.
337 AT_CHECK([grep 3 stdout || exit 77], [], [ignore])
348 AT_SETUP([AS@&t@_MKDIR_P])
351 AT_DATA_M4SH([script.as],
357 AS_MKDIR_P(["$pwd/1/2/3/4/5/6"])
358 test -d "$pwd/1/2/3/4/5/6" ||
359 AS_ERROR([$pwd/1/2/3/4/5/6 has not been properly created])
361 AS_MKDIR_P(["a/b/c/d/e/f"])
362 test -d a/b/c/d/e/f ||
363 AS_ERROR([a/b/c/d/e/f has not been properly created])
368 AT_CHECK([$CONFIG_SHELL ./script])
375 ## -------------------- ##
376 ## AS_VERSION_COMPARE. ##
377 ## -------------------- ##
379 # Three-way version comparison.
380 AT_SETUP([AS@&t@_VERSION_COMPARE])
383 AT_DATA_M4SH([script.as],
386 m4_define([VERSION_COMPARE_TEST],
387 [AS_VERSION_COMPARE([$1], [$3], [result='<'], [result='='], [result='>'])
388 test "X$result" = "X$2" ||
389 AS_ERROR([version $1 $result $3; should be $1 $2 $3])
391 [AS_VERSION_COMPARE([$3], [$1], [result='<'], [result='='], [result='>'])
392 test "X$result" = "X>" ||
393 AS_ERROR([version $3 $result $1; should be $3 > $1])])])
395 VERSION_COMPARE_TEST([], =, [])
396 VERSION_COMPARE_TEST([1.0], =, [1.0])
397 VERSION_COMPARE_TEST([alpha-1.0], =, [alpha-1.0])
399 # These tests are taken from libc/string/tst-svc.expect.
401 000 001 00 00a 01 01a 0 0a 2.8 2.8-0.4 20 21 22 212 CP037 CP345 CP1257
402 foo foo-0.4 foo-0.4a foo-0.4b foo-0.5 foo-0.10.5 foo-3.01 foo-3.0
403 foo-3.0.0 foo-3.0.1 foo-3.2 foo-3.10 foo00 foo0
406 for test2 in $tst_svc_expect; do
407 VERSION_COMPARE_TEST([$test1], <, [$test2])
415 AT_CHECK([$CONFIG_SHELL ./script])
429 AT_DATA_M4SH([script.as],
432 test "$as_me" = script || AS_ECHO([["incorrect value of \$as_me: $as_me"]])
436 AT_CHECK([$CONFIG_SHELL ./script])
443 ## ----------------------------- ##
444 ## Negated classes in globbing. ##
445 ## ----------------------------- ##
447 # It is known that `[^...]' is not universally supported, but it is
448 # unknown for `[!...]'.
450 AT_SETUP([Negated classes in globbing])
453 AT_DATA_M4SH([script.as],
456 case 'with!two!bangs' in
458 *) AS_ERROR([[`*[!a-z]*' didn't match `with!two!bangs']]);;
462 *[[!a-z]]*) AS_ERROR([[`*[!a-z]*' matched `without']]);;
467 AT_CHECK([$CONFIG_SHELL ./script])
474 ## ------------------- ##
475 ## Functions Support. ##
476 ## ------------------- ##
478 # Hypothesis: the shell we are running, after having checked for
479 # $LINENO support, supports functions.
481 AT_SETUP([Functions Support])
484 AT_DATA_M4SH([script.as],
500 if func_success; then
501 if func_failure; then
502 AS_ERROR([func_failure passed])
505 AS_ERROR([func_success failed])
510 AT_CHECK([$CONFIG_SHELL ./script])
517 ## ------------------------------ ##
518 ## Functions and return Support. ##
519 ## ------------------------------ ##
521 # Hypothesis: the shell we are running, after having checked for
522 # $LINENO support, supports functions, and the `return' keyword.
524 AT_SETUP([Functions and return Support])
527 AT_DATA_M4SH([script.as],
539 if func_success; then
540 if func_failure; then
541 AS_ERROR([func_failure passed])
544 AS_ERROR([func_success failed])
549 AT_CHECK([$CONFIG_SHELL ./script])
554 ## --------------------------- ##
555 ## Nested AS_REQUIRE_SHELL_FN. ##
556 ## --------------------------- ##
558 # Hypothesis: M4sh expands nested AS_REQUIRE_SHELL_FN
561 AT_SETUP([Nested AS@&t@_REQUIRE_SHELL_FN])
564 AT_DATA_M4SH([script.as], [[dnl
565 m4_define([INIT], [oops])dnl
568 m4_defun([TEST_FUNC2_BODY], [
572 m4_defun([TEST_FUNC1_BODY], [
573 AS_REQUIRE_SHELL_FN([test_func2], [], [TEST_FUNC2_BODY])
577 AS_REQUIRE_SHELL_FN([test_func1], [], [TEST_FUNC1_BODY])
582 AT_CHECK([$CONFIG_SHELL ./script])
587 ## ------------------- ##
588 ## Nested AS_REQUIRE. ##
589 ## ------------------- ##
591 # Hypothesis: M4sh expands the requirements of AS_REQUIRE in the
592 # requested diversion, even if other AS_REQUIREs are interleaved.
594 AT_SETUP([Nested AS@&t@_REQUIRE])
597 AT_DATA_M4SH([script.as], [[dnl
600 m4_defun([in_fn_diversion], still_in_m4sh_init_fn=yes)
601 m4_defun([not_in_fn_diversion], still_in_m4sh_init_fn=no)
603 m4_defun([NESTED], [nested_require_in_fn_diversion=$still_in_m4sh_init_fn])
605 m4_defun([OUTER], [AS_REQUIRE([NESTED])dnl
606 outer_require_in_fn_diversion=$still_in_m4sh_init_fn])
608 m4_defun([test_init], [
609 AS_REQUIRE([in_fn_diversion], , [M4SH-INIT-FN])
610 AS_REQUIRE([OUTER], , [M4SH-INIT-FN])
611 AS_REQUIRE([not_in_fn_diversion], , [M4SH-INIT-FN])
615 if test $outer_require_in_fn_diversion != yes; then AS_EXIT([1]); fi
616 if test $nested_require_in_fn_diversion != no; then AS_EXIT([1]); fi
620 AT_CHECK([$CONFIG_SHELL ./script])
625 ## ------------------------------------ ##
626 ## AS_REQUIRE_SHELL_FN and m4_require. ##
627 ## ------------------------------------ ##
629 # Hypothesis: M4sh expands the requirements of AS_REQUIRE_SHELL_FN
630 # in M4SH-INIT-FN. This changed after Autoconf 2.63.
632 AT_SETUP([AS@&t@_REQUIRE_SHELL_FN and m4@&t@_require])
635 AT_DATA_M4SH([script.as], [[dnl
638 m4_defun([in_m4_sh_init], still_in_m4sh_init=yes)
639 m4_defun([not_in_m4_sh_init], still_in_m4sh_init=no)
641 m4_defun([error_if_emitted_in_m4sh_init], [
642 if test x$still_in_m4sh_init = xyes; then
643 AS_ERROR([requirement emitted in M4SH-INIT])
647 m4_defun([TEST_FUNC_BODY], [
648 m4_require([error_if_emitted_in_m4sh_init])
649 : echo in shell function, with parameter = [$]1
653 m4_defun([test_init], [
654 AS_REQUIRE([in_m4_sh_init], , [M4SH-INIT-FN])
655 AS_REQUIRE_SHELL_FN([test_func], [], [TEST_FUNC_BODY])
656 AS_REQUIRE([not_in_m4_sh_init])
664 AT_CHECK([$CONFIG_SHELL ./script])
673 AT_SETUP([AS@&t@_HELP_STRING])
674 AT_KEYWORDS([m4sh m4@&t@_text_wrap m4@&t@_expand])
676 AT_DATA_M4SH([script.as],
679 echo "AS_HELP_STRING([--an-option],[some text])"
680 echo "AS_HELP_STRING([--another-much-longer-option],
681 [some other text which should wrap at our default of 80 characters.])"
682 echo "AS_HELP_STRING([--fooT=barT], [foo bar])"
683 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@], [foo bar])"
684 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@123456789], [foo bar])"
685 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@1234567890], [foo bar])"
686 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@12345678901], [foo bar])"
687 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@123456789012], [foo bar])"
688 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@1234567890123], [foo bar])"
689 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@],
690 [some other text which should wrap at our default of 80 characters.])"
691 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@123456789],
692 [some other text which should wrap at our default of 80 characters.])"
693 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@1234567890],
694 [some other text which should wrap at our default of 80 characters.])"
695 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@12345678901],
696 [some other text which should wrap at our default of 80 characters.])"
697 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@123456789012],
698 [some other text which should wrap at our default of 80 characters.])"
699 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@1234567890123],
700 [some other text which should wrap at our default of 80 characters.])"
701 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@],
702 [some other @<][:@ex@:][>@ which should wrap at our default of 80 characters.])"
703 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@123456789],
704 [some other @<][:@ex@:][>@ which should wrap at our default of 80 characters.])"
705 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@1234567890],
706 [some other @<][:@ex@:][>@ which should wrap at our default of 80 characters.])"
707 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@12345678901],
708 [some other @<][:@ex@:][>@ which should wrap at our default of 80 characters.])"
709 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@123456789012],
710 [some other @<][:@ex@:][>@ which should wrap at our default of 80 characters.])"
711 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@1234567890123],
712 [some other @<][:@ex@:][>@ which should wrap at our default of 80 characters.])"
713 echo "AS_HELP_STRING([[--foo[=bar]]],
714 [some other t[]t which should wrap at our default of 80 characters.])"
715 echo "AS_HELP_STRING([[--foo[=bar]123456789]],
716 [some other t[]t which should wrap at our default of 80 characters.])"
717 echo "AS_HELP_STRING([[--foo[=bar]1234567890]],
718 [some other t[]t which should wrap at our default of 80 characters.])"
719 echo "AS_HELP_STRING([[--foo[=bar]12345678901]],
720 [some other t[]t which should wrap at our default of 80 characters.])"
721 echo "AS_HELP_STRING([[--foo[=bar]123456789012]],
722 [some other t[]t which should wrap at our default of 80 characters.])"
723 echo "AS_HELP_STRING([[--foo[=bar]1234567890123]],
724 [some other t[]t which should wrap at our default of 80 characters.])"
725 m4_define([mac], [MACRO])dnl
726 echo "AS_HELP_STRING([--mac], [mac])"
727 echo "AS_HELP_STRING([--o1, --o2], [two
728 options, one description])"
729 echo "AS_HELP_STRING([[[--o3, --o4]]], [comma inside literal quoting])"
730 echo "AS_HELP_STRING([--tune1], [check out the tuned formatting],
732 echo "AS_HELP_STRING([--tune2], [check out the tuned formatting],
734 echo "AS_HELP_STRING([--tune3], [check out the tuned formatting],
736 echo "AS_HELP_STRING([--tune4], [check out the tuned formatting],
741 AT_CHECK([$CONFIG_SHELL ./script], [0],
742 [[ --an-option some text
743 --another-much-longer-option
744 some other text which should wrap at our default of
748 --foo[=bar]123456789 foo bar
749 --foo[=bar]1234567890 foo bar
750 --foo[=bar]12345678901 foo bar
751 --foo[=bar]123456789012 foo bar
752 --foo[=bar]1234567890123
754 --foo[=bar] some other text which should wrap at our default of
756 --foo[=bar]123456789 some other text which should wrap at our default of
758 --foo[=bar]1234567890 some other text which should wrap at our default of
760 --foo[=bar]12345678901 some other text which should wrap at our default of
762 --foo[=bar]123456789012 some other text which should wrap at our default of
764 --foo[=bar]1234567890123
765 some other text which should wrap at our default of
767 --foo[=bar] some other [ex] which should wrap at our default of
769 --foo[=bar]123456789 some other [ex] which should wrap at our default of
771 --foo[=bar]1234567890 some other [ex] which should wrap at our default of
773 --foo[=bar]12345678901 some other [ex] which should wrap at our default of
775 --foo[=bar]123456789012 some other [ex] which should wrap at our default of
777 --foo[=bar]1234567890123
778 some other [ex] which should wrap at our default of
780 --foo[=bar] some other t[]t which should wrap at our default of
782 --foo[=bar]123456789 some other t[]t which should wrap at our default of
784 --foo[=bar]1234567890 some other t[]t which should wrap at our default of
786 --foo[=bar]12345678901 some other t[]t which should wrap at our default of
788 --foo[=bar]123456789012 some other t[]t which should wrap at our default of
790 --foo[=bar]1234567890123
791 some other t[]t which should wrap at our default of
794 --o1, --o2 two options, one description
795 [--o3, --o4] comma inside literal quoting
796 --tune1 check out the tuned formatting
797 --tune2 check out the tuned formatting
798 --tune3 check out the
801 --tune4 check out the tuned
808 ## ------------------- ##
809 ## AS_IF and AS_CASE. ##
810 ## ------------------- ##
812 AT_SETUP([AS@&t@_IF and AS@&t@_CASE])
813 AT_KEYWORDS([m4sh m4@&t@_map_args_pair])
815 AT_DATA_M4SH([script.as], [[dnl
817 # Syntax checks: cope with empty arguments.
818 AS_IF([:], [], [echo wrong])
819 AS_IF([:], [echo one], [echo wrong])
820 AS_IF([false], [echo wrong], [echo two])
821 AS_IF([false], [echo wrong])
823 AS_IF([false], [echo wrong],
825 AS_IF([false], [echo wrong],
828 AS_IF([false], [echo wrong],
829 [false], [echo wrong])
830 AS_IF([false], [echo wrong],
831 [false], [echo wrong],
833 AS_IF([false], [echo wrong],
834 [false], [echo wrong],
838 AS_CASE([foo], [echo seven])
850 # check for nesting, lists, and side effects, and quoting robustness
852 AS_IF([AS_IF([$empty], [echo eleven])]) && AS_CASE([foo]) && echo twelve
854 AS_IF([touch file; false]) && echo thirteen
855 test -f file && echo fourteen
857 AS_CASE([`touch file; false`]) && test -f file && echo fifteen
858 dnl The next line is badly underquoted; don't intentionally copy this style.
859 AS_CASE([foo], [foo], m4_do(AS_CASE([bar], [bar], [echo sixteen])))
860 dnl Handle blank arguments.
861 AS_IF([false], [:], [ ]) && AS_CASE([foo], [foo], []
863 m4_define([empty])AS_IF([:], [empty]
864 ) && AS_CASE([foo], [foo], [empty]) && echo eighteen
865 dnl We can't handle AS_IF([false], [:], [empty]) unless m4_expand is
866 dnl taught how to handle m4_require. The user is responsible for
867 dnl avoiding the syntax error in that case.
869 # check that require works correctly
870 m4_for([n], 1, 9, [],
871 [m4_defun([FOO]n, [foo]n[=]n)dnl
873 [m4_require([FOO]]n[)dnl
878 echo "foo1=$foo1 bar1=$bar1"
879 AS_IF([:], [], [BAR2])
880 echo "foo2=$foo2 bar2=$bar2"
881 AS_IF([false], [BAR3])
882 echo "foo3=$foo3 bar3=$bar3"
883 AS_IF([false], [], [BAR4])
884 echo "foo4=$foo4 bar4=$bar4"
885 AS_CASE([x], [x], [BAR5])
886 echo "foo5=$foo5 bar5=$bar5"
887 AS_CASE([x], [y], [BAR6])
888 echo "foo6=$foo6 bar6=$bar6"
892 echo "foo7=$foo7 bar7=$bar7"
896 echo "foo8=$foo8 bar8=$bar8"
900 echo "foo9=$foo9 bar9=$bar9"
904 AT_CHECK([$CONFIG_SHELL ./script], [0], [[one
933 dnl stress test for large number of conditionals
934 dnl too large, and we start tickling shell bugs
935 m4_pushdef([limit], [1000])dnl
936 AT_DATA_M4SH([script.as], [[dnl
938 AS_IF(m4_shift(m4_for([i], [1], ]limit[, [], [, test $[1] = i, echo i])))
939 AS_IF(m4_shift(m4_for([i], [1], ]limit[, [], [, test $[1] = i, echo i])),
941 AS_CASE([$[1]]m4_for([i], [1], ]limit[, [], [, i, echo i]))
942 AS_CASE([$[1]]m4_for([i], [1], ]limit[, [], [, i, echo i]), [echo default])
945 dnl Add --force so autom4te doesn't think `script' is still up to date.
946 AT_CHECK_M4SH([--force])
947 AT_CHECK([$CONFIG_SHELL ./script 1], [0], [[1
952 AT_CHECK([$CONFIG_SHELL ./script limit], [0], [limit
957 AT_CHECK([$CONFIG_SHELL ./script default], [0], [[default
969 AT_SETUP([AS@&t@_FOR])
972 AT_DATA_M4SH([script.as], [[dnl
976 AS_FOR([m4var], [shvar], [a],
977 [echo "m4var $shvar"])
978 AS_FOR([m4var], [shvar], [b c],
979 [echo "m4var $shvar"])
981 AS_FOR([m4var], [shvar], [$list],
982 [echo "m4var $shvar"])
983 AS_FOR([m4var], [shvar], ["$list"],
984 [echo "m4var $shvar"])
985 AS_FOR([m4var], [shvar], ['$list'],
986 [echo "m4var $shvar"])
987 AS_FOR([m4var], [shvar], [\'],
988 [echo "m4var $shvar"])
990 # Syntax checks: cope with empty/blank arguments.
992 AS_FOR([], [shvar], [],
993 [echo "m4_defn([]) $shvar"])
995 AS_FOR([], [shvar], [`touch file`])
996 test -f file || exit 1
997 AS_FOR([], [shvar], [], [ ])
998 m4_define([empty])AS_FOR([], [shvar], [], [empty])
1000 # Check that break works.
1003 AS_FOR([m4var], [shvar], [h i],
1004 [echo "m4var"; break 2])
1009 AS_FOR([m4var], [shvar], [j],
1010 [echo "m4var"; break 2])
1016 AT_CHECK([$CONFIG_SHELL ./script], [0], [[a a
1033 ## --------------- ##
1034 ## AS_LITERAL_IF. ##
1035 ## --------------- ##
1037 AT_SETUP([AS@&t@_LITERAL_IF])
1040 AT_DATA_M4SH([script.as], [[dnl
1042 echo AS_LITERAL_IF([lit], [ok], [ERR]) 1
1043 echo AS_LITERAL_IF([l$it], [ERR], [ok]) 2
1044 echo AS_LITERAL_IF([l`case a in b) ;; esac`it], [ERR], [ok]) 3
1045 m4_define([mac], [lit])
1046 echo AS_LITERAL_IF([mac], [ok], [ERR]) 4
1047 echo AS_LITERAL_IF([mac($, ``)], [ok], [ERR]) 5
1048 m4_define([mac], [l$it])
1049 echo AS_LITERAL_IF([mac], [ERR], [ok]) 6
1050 m4_define([mac], [l``it])
1051 echo AS_LITERAL_IF([mac], [ERR], [ok]) 7
1055 AT_CHECK([$CONFIG_SHELL ./script], [],
1072 AT_SETUP([AS@&t@_VAR basics])
1073 AT_KEYWORDS([m4sh AS@&t@_VAR_COPY AS@&t@_VAR_SET AS@&t@_VAR_GET])
1074 AT_KEYWORDS([AS@&t@_VAR_TEST_SET AS@&t@_VAR_SET_IF AS@&t@_VAR_IF])
1075 AT_KEYWORDS([AS@&t@_VAR_PUSHDEF AS@&t@_VAR_POPDEF])
1077 AT_DATA_M4SH([script.as], [[dnl
1079 m4_define([with], [WITH])
1081 dnl AS_VAR_SET_IF also covers AS_VAR_TEST_SET
1082 AS_VAR_SET_IF([foo], [echo oops]) && echo ok
1083 AS_VAR_SET([foo], ['\a "weird" `value` with; $fun '\''characters
1085 AS_VAR_COPY([bar], [foo])
1087 AS_ECHO(["AS_VAR_GET([foo])-"])
1088 AS_VAR_SET_IF([foo], [echo ok], [echo oops])
1089 AS_VAR_IF([foo], [string], [echo oops]) && echo ok
1090 AS_VAR_PUSHDEF([tmp], [foo])
1091 AS_VAR_IF([tmp], ['\a "weird" `value` with; $fun '\''characters
1092 '], [echo ok], [echo oops]) # 'font-lock
1093 AS_VAR_POPDEF([tmp])
1094 m4_ifdef([tmp], [echo oops])
1096 # Indirects via shell vars.
1099 AS_VAR_SET_IF([foo$num], [echo oops]) && echo ok
1100 AS_VAR_SET([foo$num], ['\a "weird" `value` with; $fun '\''characters
1102 AS_VAR_COPY([bar], [foo$num])
1104 AS_VAR_COPY([foo$num], [bar])
1106 AS_ECHO(["AS_VAR_GET([foo$num])-"])
1107 AS_VAR_SET_IF([foo$num], [echo ok], [echo oops])
1108 AS_VAR_IF([foo$num], [string], [echo oops]) && echo ok
1109 AS_VAR_PUSHDEF([tmp], [foo$num])
1110 AS_VAR_IF([tmp], ['\a "weird" `value` with; $fun '\''characters
1111 '], [echo ok], [echo oops]) # 'font-lock
1112 AS_VAR_POPDEF([tmp])
1113 m4_ifdef([tmp], [echo oops])
1115 # Indirects via command substitution.
1117 AS_VAR_SET_IF([`echo foo3`], [echo oops]) && echo ok
1118 AS_VAR_SET([`echo foo3`], ['\a "weird" `value` with; $fun '\''characters
1120 AS_VAR_COPY([bar], [`echo foo3`])
1122 AS_VAR_COPY([`echo foo4`], [bar])
1124 AS_ECHO(["AS_VAR_GET([`echo foo4`])-"])
1125 AS_VAR_SET_IF([`echo foo4`], [echo ok], [echo oops])
1126 AS_VAR_IF([`echo foo4`], [string], [echo oops]) && echo ok
1127 AS_VAR_PUSHDEF([tmp], [`echo foo4`])
1128 AS_VAR_IF([tmp], ['\a "weird" `value` with; $fun '\''characters
1129 '], [echo ok], [echo oops]) # 'font-lock
1130 AS_VAR_POPDEF([tmp])
1131 m4_ifdef([tmp], [echo oops])
1136 AT_CHECK([$CONFIG_SHELL ./script], [], [[ok
1137 \a "weird" `value` WITH; $fun 'characters
1139 \a "weird" `value` WITH; $fun 'characters
1146 \a "weird" `value` WITH; $fun 'characters
1148 \a "weird" `value` WITH; $fun 'characters-
1154 \a "weird" `value` WITH; $fun 'characters
1156 \a "weird" `value` WITH; $fun 'characters-
1165 ## --------------- ##
1166 ## AS_VAR_APPEND. ##
1167 ## --------------- ##
1169 AT_SETUP([AS@&t@_VAR_APPEND])
1170 AT_KEYWORDS([m4sh AS@&t@_VAR])
1172 AT_DATA_M4SH([script.as], [[dnl
1175 AS_VAR_APPEND([foo], ["hello, "])
1176 AS_VAR_APPEND([foo], [world])
1178 # Indirects via shell vars.
1180 AS_VAR_APPEND([foo$num], ['hello, '])
1181 AS_VAR_APPEND([foo$num], [`echo "world"`])
1183 # Indirects via command substitution.
1185 AS_VAR_APPEND([`echo foo2`], [${h}])
1186 AS_VAR_APPEND([`echo foo2`], ["$w"])
1191 AT_CHECK([$CONFIG_SHELL ./script], [],
1200 ## -------------- ##
1202 ## -------------- ##
1204 AT_SETUP([AS@&t@_VAR_ARITH])
1205 AT_KEYWORDS([m4sh AS@&t@_VAR])
1207 AT_DATA_M4SH([script.as], [[dnl
1210 AS_VAR_ARITH([foo], [1 + 1])
1212 # Indirects via shell vars.
1214 AS_VAR_ARITH([foo$num], [\( 2 + 3 \) \* 4])
1216 # Indirects via command substitution.
1217 AS_VAR_ARITH([`echo foo2`], [0 + -2 + $foo1 / 2])
1222 AT_CHECK([$CONFIG_SHELL ./script], [],
1231 ## ----------------- ##
1232 ## AS_INIT cleanup. ##
1233 ## ----------------- ##
1235 AT_SETUP([AS@&t@_INIT cleanup])
1236 AT_KEYWORDS([m4sh m4@&t@_wrap m4@&t@_wrap_lifo])
1238 AT_DATA_M4SH([script.as], [[dnl
1239 dnl Registered before AS_INIT's cleanups
1240 m4_wrap([echo cleanup 1
1242 m4_pushdef([_AS_SHELL_FN_SPY])dnl neutralize the spy, we don't care about it
1244 dnl Registered after AS_INIT's cleanups, thus goes to KILL diversion
1245 m4_wrap([echo cleanup 2
1246 dnl However, nested wraps and diversions can still be used
1247 dnl Also, test wrapping text that looks like parameter reference
1248 m4_wrap([echo cleanup 3
1249 m4_divert_text([M4SH-INIT], [m4_define([foo], [$1])dnl
1252 dnl Registered before AS_INIT's cleanups
1253 m4_wrap_lifo([echo cleanup 5
1259 AT_CHECK([$CONFIG_SHELL ./script], [], [[prep 4
1268 ## ------------------- ##
1269 ## AS_INIT_GENERATED. ##
1270 ## ------------------- ##
1272 AT_SETUP([AS@&t@_INIT_GENERATED])
1273 AT_KEYWORDS([AS@&t@_MESSAGE AS@&t@_MESSAGE_LOG_FD])
1275 dnl First run, no logging, tests shell selection
1276 AT_DATA_M4SH([script.as], [[dnl
1278 AS_INIT_GENERATED([child], [echo hello from child])
1280 AS_ECHO(["SHELL=$SHELL"])
1282 echo hello from parent
1283 AS_ECHO(["SHELL=$SHELL"])
1287 AT_CHECK([$CONFIG_SHELL ./script], [0], [stdout])
1288 AT_CHECK([grep 'SHELL=.' stdout], [0], [ignore])
1289 sed s/parent/child/ <stdout >expout
1290 AT_CHECK([./child], [0], [expout])
1295 AT_CHECK([$CONFIG_SHELL ./script], [0], [expout])
1296 AT_CHECK([cmp child child.bak])
1297 AT_CHECK([grep 'SHELL=.' stdout], [0], [ignore])
1298 sed s/parent/child/ <stdout >expout
1299 AT_CHECK([./child], [0], [expout])
1302 dnl Second run, with logging from parent and child, tests fd handling
1303 AT_DATA_M4SH([script.as], [[dnl
1306 m4_define([AS_MESSAGE_LOG_FD], [5])
1307 exec AS_MESSAGE_LOG_FD>log
1308 AS_INIT_GENERATED([$child], [echo hello1 from $child]) || AS_EXIT([1])
1310 m4_pushdef([AS_MESSAGE_LOG_FD])
1311 AS_MESSAGE([hello2 from ${child}child])
1312 m4_popdef([AS_MESSAGE_LOG_FD])
1313 exec AS_MESSAGE_LOG_FD>>log
1314 AS_MESSAGE([hello3 from child])
1316 AS_MESSAGE([hello from parent])
1317 dnl close log in parent before spawning child, for mingw
1318 exec AS_MESSAGE_LOG_FD>&-
1324 AT_CHECK([$CONFIG_SHELL ./script], [0], [[script: hello from parent
1326 child: hello2 from child
1327 child: hello3 from child
1329 AT_CHECK([[sed 's,:[0-9][0-9]*:,:0:,' log]], [0],
1330 [[script:0: hello from parent
1331 child:0: hello3 from child
1334 # Force write error creating a file on stdout
1335 if test -w /dev/full && test -c /dev/full; then
1336 AT_CHECK([$CONFIG_SHELL ./script /dev/full], [1], [ignore], [ignore])
1342 ## --------------- ##
1343 ## AS_MESSAGE_FD. ##
1344 ## --------------- ##
1346 AT_SETUP([AS@&t@_MESSAGE_FD])
1347 AT_KEYWORDS([AS@&t@_MESSAGE AS@&t@_MESSAGE_LOG_FD AS@&t_ORIGINAL_STDIN_FD])
1348 AT_KEYWORDS([AS@&t@_LINENO_PUSH])
1350 AT_DATA_M4SH([script.as], [[dnl
1352 m4_define([AS_ORIGINAL_STDIN_FD], [5])
1353 m4_define([AS_MESSAGE_LOG_FD], [6])
1354 m4_define([AS_MESSAGE_FD], [7])
1355 exec AS_ORIGINAL_STDIN_FD<&0 </dev/null AS_MESSAGE_LOG_FD>log
1356 if test $[#] -gt 0; then
1357 exec AS_MESSAGE_FD>/dev/null
1359 exec AS_MESSAGE_FD>&1
1361 AS_LINENO_PUSH([100])
1362 cat # tests that stdin is neutralized
1363 AS_MESSAGE([hello world])
1364 cat <&AS_ORIGINAL_STDIN_FD
1368 AT_CHECK([echo goodbye | $CONFIG_SHELL ./script], [0],
1369 [[script: hello world
1372 AT_CHECK([cat log], [0],
1373 [[script:100: hello world
1376 AT_CHECK([echo goodbye | $CONFIG_SHELL ./script silent], [0],
1379 AT_CHECK([cat log], [0],
1380 [[script:100: hello world
1386 ## --------------- ##
1387 ## _AS_CLEAN_DIR. ##
1388 ## --------------- ##
1390 AT_SETUP([_AS@&t@_CLEAN_DIR])
1392 dnl ensure that we can erase all files in a directory. Note that
1393 dnl _AS_CLEAN_DIR needs three globs to catch all these files.
1394 AT_DATA_M4SH([script.as], [[dnl
1396 # Unwritable subdirectories are common during 'make distcheck'.
1397 mkdir sub sub/unwritable || AS_ERROR([failed to mkdir])
1398 touch sub/unwritable/file || AS_ERROR([failed to touch])
1399 chmod a-wx sub/unwritable || AS_ERROR([failed to chmod])
1400 # Cygwin 1.5 can't touch 'sub/...', so make that file optional.
1401 touch sub/a sub/aa sub/aaa sub/.a sub/..a sub/.aa \
1402 || AS_ERROR([failed to touch])
1403 touch sub/... 2>/dev/null
1404 _AS_CLEAN_DIR([sub]) || AS_ERROR([failed to clean])
1405 # rmdir instead of 'rm -fr' here proves that we emptied sub.
1406 rmdir sub || AS_ERROR([failed to rmdir])
1410 AT_CHECK([$CONFIG_SHELL ./script])
1421 AT_DATA_M4SH([script.as], [[dnl
1429 AT_CHECK([$CONFIG_SHELL ./script], [], [foobar