Allow absolute names in AT_TESTED.
[autoconf.git] / tests / m4sh.at
blob5ff9fe8f5f753060a4b6c1bdacdfd726aaa0966b
1 #                                                       -*- Autotest -*-
3 AT_BANNER([M4sh.])
5 # Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
6 # 2009 Free Software Foundation, Inc.
8 # This program is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation, either version 3 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
21 ## ---------------- ##
22 ## LINENO support.  ##
23 ## ---------------- ##
25 AT_SETUP([LINENO])
26 AT_KEYWORDS([m4sh])
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
39 # UNSET-LINENO.
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],
51 [AT_DATA([$1.tas],
52 [[AS@&t@_INIT
53 m4@&t@_divert_text([0], [
54 if $2; then
55   AS@&t@_UNSET([LINENO])
58 AS@&t@_LINENO_PREPARE
59 echo "Line: $3"
60 grep 'Line: .*$4' "$[0]" >/dev/null ||
61   AS@&t@_ERROR([cannot find original script])
62 exit 0
63 ]])
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])
67 ])# AT_DATA_LINENO
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])
75 # The reference:
76 mv stdout expout
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)],
85                                                    0, [expout])
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)],
92                                                    0, [expout])
93 AT_CHECK([sh ./test/test-2],                       0, [expout])
95 AT_CLEANUP
99 ## ---------------------- ##
100 ## LINENO stack support.  ##
101 ## ---------------------- ##
103 AT_SETUP([LINENO stack])
104 AT_KEYWORDS([m4sh])
106 AT_DATA_M4SH([script.as],
107 [[AS_INIT
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])
113 AS_LINENO_POP
114 test $as_lineno = 9999 || AS_ERROR([bad as_lineno at depth 1])
115 AS_LINENO_POP
116 test x${as_lineno+set} = xset && AS_ERROR([as_lineno set at depth 0])
118 AS_EXIT([0])
121 AT_CHECK_M4SH
122 AT_CHECK([$CONFIG_SHELL ./script])
124 AT_CLEANUP
127 ## ------------- ##
128 ## AS_BASENAME.  ##
129 ## ------------- ##
131 # Strip path from file.
132 AT_SETUP([AS@&t@_BASENAME])
133 AT_KEYWORDS([m4sh])
135 AT_DATA_M4SH([script.as],
136 [[AS_INIT
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])
175 AS_EXIT(0)
178 AT_CHECK_M4SH
179 AT_CHECK([$CONFIG_SHELL ./script])
181 AT_CLEANUP
184 ## ------------ ##
185 ## AS_DIRNAME.  ##
186 ## ------------ ##
188 # Strip filename component.
189 AT_SETUP([AS@&t@_DIRNAME])
190 AT_KEYWORDS([m4sh])
192 AT_DATA_M4SH([script.as],
193 [[AS_INIT
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])
235 AS_EXIT(0)
238 AT_CHECK_M4SH
239 AT_CHECK([$CONFIG_SHELL ./script])
241 AT_CLEANUP
245 ## --------- ##
246 ## AS_ECHO.  ##
247 ## --------- ##
249 # Print literal strings, with/without newline.
250 AT_SETUP([AS@&t@_ECHO and AS@&t@_ECHO_N])
251 AT_KEYWORDS([m4sh])
253 AT_DATA_M4SH([script.as],
254 [[AS_INIT
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])
265 ECHO_TEST([-])
266 ECHO_TEST([--])
267 ECHO_TEST([---...---])
268 ECHO_TEST([      ])
269 ECHO_TEST([-e])
270 ECHO_TEST([-E])
271 ECHO_TEST([-n])
272 ECHO_TEST([-n -n])
273 ECHO_TEST([-e -n])
274 ECHO_TEST([ab\ncd])
275 ECHO_TEST([abcd\c])
276 ECHO_TEST([\a\b\c\f\n\r\t\v\"\])
277 ECHO_TEST([ab
280 ECHO_TEST([
281  ])
282 ECHO_TEST([
283 \c])
284 AS_EXIT(0)
287 AT_CHECK_M4SH
288 AT_CHECK([$CONFIG_SHELL ./script])
290 AT_CLEANUP
294 ## --------- ##
295 ## AS_EXIT.  ##
296 ## --------- ##
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],
303 [[AS_INIT
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
310 AS_SET_STATUS([3])
311 dnl Solaris /bin/sh 'set -e' doesn't react to failed function calls
312 test x${2} = xe \
313   && { echo 'skipping rest of test: set -e support is lousy'; exit 77; }
314 AS_SET_STATUS([4])
317 AT_CHECK_M4SH
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])
339 AT_CLEANUP
343 ## ------------ ##
344 ## AS_MKDIR_P.  ##
345 ## ------------ ##
347 # Build nested dirs.
348 AT_SETUP([AS@&t@_MKDIR_P])
349 AT_KEYWORDS([m4sh])
351 AT_DATA_M4SH([script.as],
352 [[AS_INIT
354 pwd=`pwd`
355 set -e
356 # Absolute
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])
360 # Relative
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])
364 AS_EXIT(0)
367 AT_CHECK_M4SH
368 AT_CHECK([$CONFIG_SHELL ./script])
370 AT_CLEANUP
375 ## -------------------- ##
376 ## AS_VERSION_COMPARE.  ##
377 ## -------------------- ##
379 # Three-way version comparison.
380 AT_SETUP([AS@&t@_VERSION_COMPARE])
381 AT_KEYWORDS([m4sh])
383 AT_DATA_M4SH([script.as],
384 [[AS_INIT
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])
390 m4_if([$1], <,
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.
400 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
405 test1=''
406 for test2 in $tst_svc_expect; do
407   VERSION_COMPARE_TEST([$test1], <, [$test2])
408   test1=$test2
409 done
411 AS_EXIT(0)
414 AT_CHECK_M4SH
415 AT_CHECK([$CONFIG_SHELL ./script])
417 AT_CLEANUP
422 ## ------- ##
423 ## as_me.  ##
424 ## ------- ##
426 AT_SETUP([as_me])
427 AT_KEYWORDS([m4sh])
429 AT_DATA_M4SH([script.as],
430 [[AS_INIT
431 AS_ME_PREPARE
432 test "$as_me" = script || AS_ECHO([["incorrect value of \$as_me: $as_me"]])
435 AT_CHECK_M4SH
436 AT_CHECK([$CONFIG_SHELL ./script])
438 AT_CLEANUP
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])
451 AT_KEYWORDS([m4sh])
453 AT_DATA_M4SH([script.as],
454 [[AS_INIT
456 case 'with!two!bangs' in
457   *[[!a-z]]*) ;;
458            *) AS_ERROR([[`*[!a-z]*' didn't match `with!two!bangs']]);;
459 esac
461 case without in
462   *[[!a-z]]*) AS_ERROR([[`*[!a-z]*' matched `without']]);;
463 esac
466 AT_CHECK_M4SH
467 AT_CHECK([$CONFIG_SHELL ./script])
469 AT_CLEANUP
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])
482 AT_KEYWORDS([m4sh])
484 AT_DATA_M4SH([script.as],
485 [[AS_INIT
486 AS_LINENO_PREPARE
488 func_return () {
489   (exit $1)
492 func_success () {
493   func_return 0
496 func_failure () {
497   func_return 1
500 if func_success; then
501   if func_failure; then
502     AS_ERROR([func_failure passed])
503   fi
504 else
505   AS_ERROR([func_success failed])
509 AT_CHECK_M4SH
510 AT_CHECK([$CONFIG_SHELL ./script])
512 AT_CLEANUP
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])
525 AT_KEYWORDS([m4sh])
527 AT_DATA_M4SH([script.as],
528 [[AS_INIT
529 AS_LINENO_PREPARE
531 func_success () {
532   return 0
535 func_failure () {
536   return 1
539 if func_success; then
540   if func_failure; then
541     AS_ERROR([func_failure passed])
542   fi
543 else
544   AS_ERROR([func_success failed])
548 AT_CHECK_M4SH
549 AT_CHECK([$CONFIG_SHELL ./script])
551 AT_CLEANUP
554 ## --------------------------- ##
555 ## Nested AS_REQUIRE_SHELL_FN ##
556 ## --------------------------- ##
558 # Hypothesis: M4sh expands nested AS_REQUIRE_SHELL_FN
559 # separately.
561 AT_SETUP([Nested AS@&t@_REQUIRE_SHELL_FN])
562 AT_KEYWORDS([m4sh])
564 AT_DATA_M4SH([script.as], [[dnl
565 m4_define([INIT], [oops])dnl
566 AS_INIT
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])
578 test_func2
581 AT_CHECK_M4SH
582 AT_CHECK([$CONFIG_SHELL ./script])
584 AT_CLEANUP
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])
595 AT_KEYWORDS([m4sh])
597 AT_DATA_M4SH([script.as], [[dnl
598 AS_INIT
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])
614 test_init
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
619 AT_CHECK_M4SH
620 AT_CHECK([$CONFIG_SHELL ./script])
622 AT_CLEANUP
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])
633 AT_KEYWORDS([m4sh])
635 AT_DATA_M4SH([script.as], [[dnl
636 AS_INIT
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])
644   fi
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])
659 test_init
660 test_func parameter1
663 AT_CHECK_M4SH
664 AT_CHECK([$CONFIG_SHELL ./script])
666 AT_CLEANUP
669 ## -------------- ##
670 ## AS_HELP_STRING ##
671 ## -------------- ##
673 AT_SETUP([AS@&t@_HELP_STRING])
674 AT_KEYWORDS([m4sh m4@&t@_text_wrap m4@&t@_expand])
676 AT_DATA_M4SH([script.as],
677 [[AS_INIT
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],
731 [            ])"
732 echo "AS_HELP_STRING([--tune2], [check out the tuned formatting],
733 [12])"
734 echo "AS_HELP_STRING([--tune3], [check out the tuned formatting],
735 [], [40])"
736 echo "AS_HELP_STRING([--tune4], [check out the tuned formatting],
737 [12], [40])"
740 AT_CHECK_M4SH
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
745                           80 characters.
746   --fooT=barT             foo bar
747   --foo[=bar]             foo bar
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
753                           foo bar
754   --foo[=bar]             some other text which should wrap at our default of
755                           80 characters.
756   --foo[=bar]123456789    some other text which should wrap at our default of
757                           80 characters.
758   --foo[=bar]1234567890   some other text which should wrap at our default of
759                           80 characters.
760   --foo[=bar]12345678901  some other text which should wrap at our default of
761                           80 characters.
762   --foo[=bar]123456789012 some other text which should wrap at our default of
763                           80 characters.
764   --foo[=bar]1234567890123
765                           some other text which should wrap at our default of
766                           80 characters.
767   --foo[=bar]             some other [ex] which should wrap at our default of
768                           80 characters.
769   --foo[=bar]123456789    some other [ex] which should wrap at our default of
770                           80 characters.
771   --foo[=bar]1234567890   some other [ex] which should wrap at our default of
772                           80 characters.
773   --foo[=bar]12345678901  some other [ex] which should wrap at our default of
774                           80 characters.
775   --foo[=bar]123456789012 some other [ex] which should wrap at our default of
776                           80 characters.
777   --foo[=bar]1234567890123
778                           some other [ex] which should wrap at our default of
779                           80 characters.
780   --foo[=bar]             some other t[]t which should wrap at our default of
781                           80 characters.
782   --foo[=bar]123456789    some other t[]t which should wrap at our default of
783                           80 characters.
784   --foo[=bar]1234567890   some other t[]t which should wrap at our default of
785                           80 characters.
786   --foo[=bar]12345678901  some other t[]t which should wrap at our default of
787                           80 characters.
788   --foo[=bar]123456789012 some other t[]t which should wrap at our default of
789                           80 characters.
790   --foo[=bar]1234567890123
791                           some other t[]t which should wrap at our default of
792                           80 characters.
793   --MACRO                 mac
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
799                           tuned
800                           formatting
801   --tune4   check out the tuned
802             formatting
805 AT_CLEANUP
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
816 AS_INIT
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])
822 # n-ary version
823 AS_IF([false], [echo wrong],
824       [:], [echo three])
825 AS_IF([false], [echo wrong],
826       [:], [echo four],
827       [echo wrong])
828 AS_IF([false], [echo wrong],
829       [false], [echo wrong])
830 AS_IF([false], [echo wrong],
831       [false], [echo wrong],
832       [echo five])
833 AS_IF([false], [echo wrong],
834       [false], [echo wrong],
835       [:], [echo six],
836       [echo wrong])
837 AS_CASE([foo])
838 AS_CASE([foo], [echo seven])
839 AS_CASE([foo],
840         [foo], [echo eight],
841         [echo wrong])
842 AS_CASE([foo],
843         [foo], [echo nine],
844         [*],   [echo wrong])
845 AS_CASE([foo],
846         [bar], [echo wrong],
847         [foo], [echo ten],
848         [*],   [echo wrong])
850 # check for nesting, lists, and side effects, and quoting robustness
851 empty=
852 AS_IF([AS_IF([$empty], [echo eleven])]) && AS_CASE([foo]) && echo twelve
853 rm -f file
854 AS_IF([touch file; false]) && echo thirteen
855 test -f file && echo fourteen
856 rm -f file
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], []
862 ) && echo seventeen
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
872 m4_defun([BAR]n,
873          [m4_require([FOO]]n[)dnl
874 bar]n[=]n)[]dnl
877 AS_IF([:], [BAR1])
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"
889 AS_CASE([x],
890         [x], [:],
891         [BAR7])
892 echo "foo7=$foo7 bar7=$bar7"
893 AS_CASE([x],
894         [y], [:],
895         [BAR8])
896 echo "foo8=$foo8 bar8=$bar8"
897 AS_CASE([x],
898         [y], [:],
899         [x], [BAR9])
900 echo "foo9=$foo9 bar9=$bar9"
903 AT_CHECK_M4SH
904 AT_CHECK([$CONFIG_SHELL ./script], [0], [[one
906 three
907 four
908 five
910 seven
911 eight
912 nine
914 eleven
915 twelve
916 thirteen
917 fourteen
918 fifteen
919 sixteen
920 seventeen
921 eighteen
922 foo1=1 bar1=1
923 foo2=2 bar2=
924 foo3=3 bar3=
925 foo4=4 bar4=4
926 foo5=5 bar5=5
927 foo6=6 bar6=
928 foo7=7 bar7=
929 foo8=8 bar8=8
930 foo9=9 bar9=9
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
937 AS_INIT
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])),
940       [echo default])
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
953 limit
954 limit
955 limit
957 AT_CHECK([$CONFIG_SHELL ./script default], [0], [[default
958 default
960 m4_popdef([limit])
962 AT_CLEANUP
965 ## -------- ##
966 ## AS_FOR.  ##
967 ## -------- ##
969 AT_SETUP([AS@&t@_FOR])
970 AT_KEYWORDS([m4sh])
972 AT_DATA_M4SH([script.as], [[dnl
973 AS_INIT
975 # Simple checks.
976 AS_FOR([m4var], [shvar], [a],
977 [echo "m4var $shvar"])
978 AS_FOR([m4var], [shvar], [b c],
979 [echo "m4var $shvar"])
980 list='d e'
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.
991 set f g
992 AS_FOR([], [shvar], [],
993 [echo "m4_defn([]) $shvar"])
994 rm -f file
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.
1001 while :
1003   AS_FOR([m4var], [shvar], [h i],
1004     [echo "m4var"; break 2])
1005   exit 1
1006 done
1007 while :
1009   AS_FOR([m4var], [shvar], [j],
1010     [echo "m4var"; break 2])
1011   exit 1
1012 done
1015 AT_CHECK_M4SH
1016 AT_CHECK([$CONFIG_SHELL ./script], [0], [[a a
1017 b b
1018 c c
1019 d d
1020 e e
1021 d e d e
1022 $list $list
1023 ' '
1024 f f
1025 g g
1030 AT_CLEANUP
1033 ## --------------- ##
1034 ## AS_LITERAL_IF.  ##
1035 ## --------------- ##
1037 AT_SETUP([AS@&t@_LITERAL_IF])
1038 AT_KEYWORDS([m4sh])
1040 AT_DATA_M4SH([script.as], [[dnl
1041 AS_INIT
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
1054 AT_CHECK_M4SH
1055 AT_CHECK([$CONFIG_SHELL ./script], [],
1056 [[ok 1
1057 ok 2
1058 ok 3
1059 ok 4
1060 ok 5
1061 ok 6
1062 ok 7
1065 AT_CLEANUP
1068 ## ---------- ##
1069 ## AS_VAR_*.  ##
1070 ## ---------- ##
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
1078 AS_INIT
1079  m4_define([with], [WITH])
1080 # Literals.
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
1084 ']) # 'font-lock
1085 AS_VAR_COPY([bar], [foo])
1086 AS_ECHO(["$bar-"])
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.
1097 echo '===='
1098 num=1
1099 AS_VAR_SET_IF([foo$num], [echo oops]) && echo ok
1100 AS_VAR_SET([foo$num], ['\a  "weird" `value` with; $fun '\''characters
1101 ']) # 'font-lock
1102 AS_VAR_COPY([bar], [foo$num])
1103 num=2
1104 AS_VAR_COPY([foo$num], [bar])
1105 AS_ECHO(["$foo2-"])
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.
1116 echo '===='
1117 AS_VAR_SET_IF([`echo foo3`], [echo oops]) && echo ok
1118 AS_VAR_SET([`echo foo3`], ['\a  "weird" `value` with; $fun '\''characters
1119 ']) # 'font-lock
1120 AS_VAR_COPY([bar], [`echo foo3`])
1121 num=2
1122 AS_VAR_COPY([`echo foo4`], [bar])
1123 AS_ECHO(["$foo4-"])
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])
1135 AT_CHECK_M4SH
1136 AT_CHECK([$CONFIG_SHELL ./script], [], [[ok
1137 \a  "weird" `value` WITH; $fun 'characters
1139 \a  "weird" `value` WITH; $fun 'characters
1144 ====
1146 \a  "weird" `value` WITH; $fun 'characters
1148 \a  "weird" `value` WITH; $fun 'characters-
1152 ====
1154 \a  "weird" `value` WITH; $fun 'characters
1156 \a  "weird" `value` WITH; $fun 'characters-
1162 AT_CLEANUP
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
1173 AS_INIT
1174 # Literals.
1175 AS_VAR_APPEND([foo], ["hello,  "])
1176 AS_VAR_APPEND([foo], [world])
1177 echo "$foo"
1178 # Indirects via shell vars.
1179 num=1
1180 AS_VAR_APPEND([foo$num], ['hello,  '])
1181 AS_VAR_APPEND([foo$num], [`echo "world"`])
1182 echo "$foo1"
1183 # Indirects via command substitution.
1184 h=hello w=',  world'
1185 AS_VAR_APPEND([`echo foo2`], [${h}])
1186 AS_VAR_APPEND([`echo foo2`], ["$w"])
1187 echo "$foo2"
1190 AT_CHECK_M4SH
1191 AT_CHECK([$CONFIG_SHELL ./script], [],
1192 [[hello,  world
1193 hello,  world
1194 hello,  world
1197 AT_CLEANUP
1200 ## -------------- ##
1201 ## AS_VAR_ARITH.  ##
1202 ## -------------- ##
1204 AT_SETUP([AS@&t@_VAR_ARITH])
1205 AT_KEYWORDS([m4sh AS@&t@_VAR])
1207 AT_DATA_M4SH([script.as], [[dnl
1208 AS_INIT
1209 # Literals.
1210 AS_VAR_ARITH([foo], [1 + 1])
1211 echo "$foo"
1212 # Indirects via shell vars.
1213 num=1
1214 AS_VAR_ARITH([foo$num], [\( 2 + 3 \) \* 4])
1215 echo "$foo1"
1216 # Indirects via command substitution.
1217 AS_VAR_ARITH([`echo foo2`], [0 + -2 + $foo1 / 2])
1218 echo "$foo2"
1221 AT_CHECK_M4SH
1222 AT_CHECK([$CONFIG_SHELL ./script], [],
1228 AT_CLEANUP
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
1243 AS_INIT
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
1250 echo prep foo([4])
1251 ])])])
1252 dnl Registered before AS_INIT's cleanups
1253 m4_wrap_lifo([echo cleanup 5
1255 echo body
1258 AT_CHECK_M4SH
1259 AT_CHECK([$CONFIG_SHELL ./script], [], [[prep 4
1260 body
1261 cleanup 5
1262 cleanup 1
1265 AT_CLEANUP
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
1277 AS_INIT
1278 AS_INIT_GENERATED([child], [echo hello from child])
1279 cat >>child <<\EOF
1280 AS_ECHO(["SHELL=$SHELL"])
1282 echo hello from parent
1283 AS_ECHO(["SHELL=$SHELL"])
1286 AT_CHECK_M4SH
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])
1291 SHELL=/bogus
1292 export SHELL
1293 cp stdout expout
1294 mv child child.bak
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
1304 AS_INIT
1305 child=${1-child}
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])
1309 cat >>$child <<\EOF
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>&-
1319 ./$child
1322 rm -f script
1323 AT_CHECK_M4SH
1324 AT_CHECK([$CONFIG_SHELL ./script], [0], [[script: hello from parent
1325 hello1 from child
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])
1339 AT_CLEANUP
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
1351 AS_INIT
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
1358 else
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
1367 AT_CHECK_M4SH
1368 AT_CHECK([echo goodbye | $CONFIG_SHELL ./script], [0],
1369 [[script: hello world
1370 goodbye
1372 AT_CHECK([cat log], [0],
1373 [[script:100: hello world
1375 rm log
1376 AT_CHECK([echo goodbye | $CONFIG_SHELL ./script silent], [0],
1377 [[goodbye
1379 AT_CHECK([cat log], [0],
1380 [[script:100: hello world
1383 AT_CLEANUP
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
1395 AS_INIT
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])
1409 AT_CHECK_M4SH
1410 AT_CHECK([$CONFIG_SHELL ./script])
1412 AT_CLEANUP
1415 ## -------- ##
1416 ## ECHO_C.  ##
1417 ## -------- ##
1419 AT_SETUP([ECHO_C])
1421 AT_DATA_M4SH([script.as], [[dnl
1422 AS_INIT
1423 _AS_PREPARE
1424 foo=`echo foobar`
1425 echo "$foo"
1428 AT_CHECK_M4SH
1429 AT_CHECK([$CONFIG_SHELL ./script], [], [foobar
1432 AT_CLEANUP