tests: improve some shell assumption testing
[autoconf.git] / tests / m4sh.at
blobde2bdc9620e045ab687ef2b437ef39e857988272
1 #                                                       -*- Autotest -*-
3 AT_BANNER([M4sh.])
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 ## ---------------- ##
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([], [
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_BOX.  ##
129 ## -------- ##
131 # Output a framed one-line message.
132 AT_SETUP([AS@&t@_BOX])
133 AT_KEYWORDS([m4sh])
135 AT_DATA_M4SH([script.as],
136 [[AS_INIT
137 echo
138 AS_BOX([Send a simple message, to foobar@example.com])
139 AS_BOX([Send a simple message, to foobar@example.com], [$])
140 m4_define([msg], [$complex])
141 complex='Not quite as simple |$[1]'
142 AS_BOX([msg])
143 AS_BOX([msg], [,])
144 AS_EXIT(0)
147 AT_CHECK_M4SH
148 AT_CHECK([sed -n '/ -\{44\} /,/ -\{44\} /p' script ]dnl
149 [| sed '1 s/.*## -/## -/; 3 s/- ##.*/- ##/'], [],
150 [[## -------------------------------------------- ##
151 ## Send a simple message, to foobar@example.com ##
152 ## -------------------------------------------- ##
155 AT_CHECK([$CONFIG_SHELL ./script], [], [[
156 ## -------------------------------------------- ##
157 ## Send a simple message, to foobar@example.com ##
158 ## -------------------------------------------- ##
159 ## $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ ##
160 ## Send a simple message, to foobar@example.com ##
161 ## $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ ##
162 ## ----------------------- ##
163 ## Not quite as simple |$1 ##
164 ## ----------------------- ##
165 ## ,,,,,,,,,,,,,,,,,,,,,,, ##
166 ## Not quite as simple |$1 ##
167 ## ,,,,,,,,,,,,,,,,,,,,,,, ##
170 AT_CLEANUP
173 # Strip path from file.
174 AT_SETUP([AS@&t@_BASENAME])
175 AT_KEYWORDS([m4sh])
177 AT_DATA_M4SH([script.as],
178 [[AS_INIT
180 m4_define([BASENAME_TEST],
181 [base=`AS_BASENAME([$1])`
182 test "$base" = "$2" ||
183   echo "basename($1) = $base instead of $2" >&2
185 base=`_AS_BASENAME_SED([$1])`
186 test "$base" = "$2" ||
187   echo "basename_sed($1) = $base instead of $2" >&2])
189 BASENAME_TEST([//1],             [1])
190 BASENAME_TEST([/1],              [1])
191 BASENAME_TEST([./1],             [1])
192 BASENAME_TEST([../../2],         [2])
193 BASENAME_TEST([//1/],            [1])
194 BASENAME_TEST([/1/],             [1])
195 BASENAME_TEST([./1/],            [1])
196 BASENAME_TEST([../../2],         [2])
197 BASENAME_TEST([//1/3],           [3])
198 BASENAME_TEST([/1/3],            [3])
199 BASENAME_TEST([./1/3],           [3])
200 BASENAME_TEST([../../2/3],       [3])
201 BASENAME_TEST([//1/3///],        [3])
202 BASENAME_TEST([/1/3///],         [3])
203 BASENAME_TEST([./1/3///],        [3])
204 BASENAME_TEST([../../2/3///],    [3])
205 BASENAME_TEST([//1//3/],         [3])
206 BASENAME_TEST([/1//3/],          [3])
207 BASENAME_TEST([./1//3/],         [3])
208 BASENAME_TEST([a.c],             [a.c])
209 BASENAME_TEST([a.c/],            [a.c])
210 BASENAME_TEST([/a.c/],           [a.c])
211 BASENAME_TEST([/1/a.c],          [a.c])
212 BASENAME_TEST([/1/a.c/],         [a.c])
213 BASENAME_TEST([/1/../a.c],       [a.c])
214 BASENAME_TEST([/1/../a.c/],      [a.c])
215 BASENAME_TEST([./1/a.c],         [a.c])
216 BASENAME_TEST([./1/a.c/],        [a.c])
217 AS_EXIT(0)
220 AT_CHECK_M4SH
221 AT_CHECK([$CONFIG_SHELL ./script])
223 AT_CLEANUP
226 ## ------------ ##
227 ## AS_DIRNAME.  ##
228 ## ------------ ##
230 # Strip filename component.
231 AT_SETUP([AS@&t@_DIRNAME])
232 AT_KEYWORDS([m4sh])
234 AT_DATA_M4SH([script.as],
235 [[AS_INIT
237 # The EXPR variant is allowed to fail if `expr' was considered as too
238 # weak for us, in which case `as_expr=false'.
239 m4_define([DIRNAME_TEST],
240 [dir=`AS_DIRNAME([$1])`
241 test "$dir" = "$2" || (test -n "$3" && test "$dir" = "$3") ||
242   echo "dirname($1) = $dir instead of $2" >&2
244 if test "$as_expr" != false; then
245   dir=`_AS_DIRNAME_EXPR([$1])`
246   test "$dir" = "$2" || (test -n "$3" && test "$dir" = "$3") ||
247     echo "dirname_expr($1) = $dir instead of $2" >&2
250 dir=`_AS_DIRNAME_SED([$1])`
251 test "$dir" = "$2" || (test -n "$3" && test "$dir" = "$3") ||
252   echo "dirname_sed($1) = $dir instead of $2" >&2])
254 DIRNAME_TEST([/],               [/])
255 DIRNAME_TEST([//],              [//],   [/])
256 DIRNAME_TEST([///],             [/])
257 DIRNAME_TEST([//1],             [//],   [/])
258 DIRNAME_TEST([/1],              [/])
259 DIRNAME_TEST([./1],             [.])
260 DIRNAME_TEST([../../2],         [../..])
261 DIRNAME_TEST([//1/],            [//],   [/])
262 DIRNAME_TEST([/1/],             [/])
263 DIRNAME_TEST([./1/],            [.])
264 DIRNAME_TEST([../../2],         [../..])
265 DIRNAME_TEST([//1/3],           [//1])
266 DIRNAME_TEST([/1/3],            [/1])
267 DIRNAME_TEST([./1/3],           [./1])
268 DIRNAME_TEST([../../2/3],       [../../2])
269 DIRNAME_TEST([//1/3///],        [//1])
270 DIRNAME_TEST([/1/3///],         [/1])
271 DIRNAME_TEST([./1/3///],        [./1])
272 DIRNAME_TEST([../../2/3///],    [../../2])
273 DIRNAME_TEST([//1//3/],         [//1])
274 DIRNAME_TEST([/1//3/],          [/1])
275 DIRNAME_TEST([./1//3/],         [./1])
276 DIRNAME_TEST([../../2//3/],     [../../2])
277 AS_EXIT(0)
280 AT_CHECK_M4SH
281 AT_CHECK([$CONFIG_SHELL ./script])
283 AT_CLEANUP
286 ## ---------------- ##
287 ## AS_SET_CATFILE.  ##
288 ## ---------------- ##
290 AT_SETUP([AS@&t@_SET_CATFILE])
291 AT_KEYWORDS([m4sh])
293 AT_DATA_M4SH([script.as],
294 [[AS_INIT
296 # CATFILE_TEST(DIR, FILE, EXPECTED)
297 m4_define([CATFILE_TEST],
298 [# AS_SET_CATFILE works and can be used in a compound list.
299 if AS_SET_CATFILE([var], [$1], [$2]) \
300    && test "$var" = $3; then :; else
301   echo "catfile($1, $2) = $var != $3" >&2
303 # AS_SET_CATFILE can use non-literals in its arguments.
304 varname=var2
305 dirpart=$1
306 filepart=$2
307 if AS_SET_CATFILE([$varname], [$dirpart], [$filepart]) \
308    && test "$var2" = $3; then :; else
309   echo "catfile($dirpart, $filepart) = $var2 != $3" >&2
313 CATFILE_TEST([dir], [file], [dir/file])
314 CATFILE_TEST([.], [file], [file])
315 CATFILE_TEST([dir], [.], [dir])
316 CATFILE_TEST([dir], [/abs/file], [/abs/file])
317 CATFILE_TEST([dir], [C:/abs/file], [C:/abs/file])
318 CATFILE_TEST(["dir  name"], ['file  name'], ['dir  name/file  name'])
320 AS_EXIT(0)
323 AT_CHECK_M4SH
324 AT_CHECK([$CONFIG_SHELL ./script])
326 AT_CLEANUP
329 ## --------- ##
330 ## AS_ECHO.  ##
331 ## --------- ##
333 # Print literal strings, with/without newline.
334 AT_SETUP([AS@&t@_ECHO and AS@&t@_ECHO_N])
335 AT_KEYWORDS([m4sh])
337 AT_DATA_M4SH([script.as],
338 [[AS_INIT
340 m4_define([ECHO_TEST],
341 [echo=`AS_ECHO(['$1'])`
342 test "X$echo" = 'X$1' ||
343   echo "AS@&t@_ECHO('"'$1'"') outputs '$echo'" >&2
345 echo=`AS_ECHO_N(['$1'])`
346 test "X$echo" = 'X$1' ||
347   echo "AS@&t@_ECHO_N('"'$1'"') outputs '$echo'" >&2])
349 ECHO_TEST([-])
350 ECHO_TEST([--])
351 ECHO_TEST([---...---])
352 ECHO_TEST([      ])
353 ECHO_TEST([-e])
354 ECHO_TEST([-E])
355 ECHO_TEST([-n])
356 ECHO_TEST([-n -n])
357 ECHO_TEST([-e -n])
358 ECHO_TEST([ab\ncd])
359 ECHO_TEST([abcd\c])
360 ECHO_TEST([\a\b\c\f\n\r\t\v\"\])
361 ECHO_TEST([ab
364 ECHO_TEST([
365  ])
366 ECHO_TEST([
367 \c])
368 AS_EXIT(0)
371 AT_CHECK_M4SH
372 AT_CHECK([$CONFIG_SHELL ./script])
374 AT_CLEANUP
378 ## --------- ##
379 ## AS_EXIT.  ##
380 ## --------- ##
382 # Exit scripts with given status.
383 AT_SETUP([AS@&t@_EXIT])
384 AT_KEYWORDS([m4sh AS@&t@_SET_STATUS])
386 AT_DATA_M4SH([script.as],
387 [[AS_INIT
388 test x${1} = xa && AS_EXIT
389 test x${1} = xb && AS_EXIT([${2}])
390 test x${1} = xc && { AS_SET_STATUS([${2}]); AS_EXIT; }
391 test x${1} = xd && trap 's=$?; echo $s; AS_EXIT([$s])' 0
392 test x${2} = xe && set -e
393 test $[#] -gt 0 || AS_EXIT
394 AS_SET_STATUS([3])
395 dnl Solaris /bin/sh 'set -e' doesn't react to failed function calls
396 test x${2} = xe \
397   && { echo 'skipping rest of test: set -e support is lousy'; exit 77; }
398 AS_SET_STATUS([4])
401 AT_CHECK_M4SH
402 AT_CHECK([$CONFIG_SHELL ./script], [1])
403 AT_CHECK([$CONFIG_SHELL ./script ''], [4])
404 AT_CHECK([$CONFIG_SHELL ./script a], [0])
405 AT_CHECK([$CONFIG_SHELL ./script b], [0])
406 AT_CHECK([$CONFIG_SHELL ./script b 0], [0])
407 AT_CHECK([$CONFIG_SHELL ./script b 2], [2])
408 AT_CHECK([$CONFIG_SHELL ./script c 0], [0])
409 AT_CHECK([$CONFIG_SHELL ./script c 2], [2])
410 AT_CHECK([$CONFIG_SHELL ./script d], [4], [[4
412 dnl If we got to this point without a FAIL, then AS_EXIT at least works.
413 dnl The rest of this test relies on semi-decent 'set -e' support, even
414 dnl though m4sh in general should not try to rely on it because of
415 dnl portability nightmares on what constructs are considered errors across
416 dnl various shells; therefore, an overall SKIP result is desirable on
417 dnl broken shells like Solaris /bin/sh.
418 AT_CHECK([$CONFIG_SHELL ./script '' e], [3])
419 AT_CHECK([$CONFIG_SHELL ./script d e], [3], [stdout])
420 dnl NetBSD sh fails to output on stderr here.
421 AT_CHECK([grep 3 stdout || exit 77], [], [ignore])
423 AT_CLEANUP
427 ## ------------ ##
428 ## AS_MKDIR_P.  ##
429 ## ------------ ##
431 # Build nested dirs.
432 AT_SETUP([AS@&t@_MKDIR_P])
433 AT_KEYWORDS([m4sh])
435 AT_DATA_M4SH([script.as],
436 [[AS_INIT
438 pwd=`pwd`
439 set -e
440 # Absolute
441 AS_MKDIR_P(["$pwd/1/2/3/4/5/6"])
442 test -d "$pwd/1/2/3/4/5/6" ||
443   AS_ERROR([$pwd/1/2/3/4/5/6 has not been properly created])
444 # Relative
445 AS_MKDIR_P(["a/b/c/d/e/f"])
446 test -d a/b/c/d/e/f ||
447   AS_ERROR([a/b/c/d/e/f has not been properly created])
448 AS_EXIT(0)
451 AT_CHECK_M4SH
452 AT_CHECK([$CONFIG_SHELL ./script])
454 AT_CLEANUP
459 ## -------------------- ##
460 ## AS_VERSION_COMPARE.  ##
461 ## -------------------- ##
463 # Three-way version comparison.
464 AT_SETUP([AS@&t@_VERSION_COMPARE])
465 AT_KEYWORDS([m4sh])
467 AT_DATA_M4SH([script.as],
468 [[AS_INIT
470 m4_define([VERSION_COMPARE_TEST],
471 [AS_VERSION_COMPARE([$1], [$3], [result='<'], [result='='], [result='>'])
472 test "X$result" = "X$2" ||
473   AS_ERROR([version $1 $result $3; should be $1 $2 $3])
474 m4_if([$1], <,
475 [AS_VERSION_COMPARE([$3], [$1], [result='<'], [result='='], [result='>'])
476 test "X$result" = "X>" ||
477   AS_ERROR([version $3 $result $1; should be $3 > $1])])])
479 VERSION_COMPARE_TEST([], =, [])
480 VERSION_COMPARE_TEST([1.0], =, [1.0])
481 VERSION_COMPARE_TEST([alpha-1.0], =, [alpha-1.0])
483 # These tests are taken from libc/string/tst-svc.expect.
484 tst_svc_expect='
485   000 001 00 00a 01 01a 0 0a 2.8 2.8-0.4 20 21 22 212 CP037 CP345 CP1257
486   foo foo-0.4 foo-0.4a foo-0.4b foo-0.5 foo-0.10.5 foo-3.01 foo-3.0
487   foo-3.0.0 foo-3.0.1 foo-3.2 foo-3.10 foo00 foo0
489 test1=''
490 for test2 in $tst_svc_expect; do
491   VERSION_COMPARE_TEST([$test1], <, [$test2])
492   test1=$test2
493 done
495 AS_EXIT(0)
498 AT_CHECK_M4SH
499 AT_CHECK([$CONFIG_SHELL ./script])
501 AT_CLEANUP
506 ## ------- ##
507 ## as_me.  ##
508 ## ------- ##
510 AT_SETUP([as_me])
511 AT_KEYWORDS([m4sh])
513 AT_DATA_M4SH([script.as],
514 [[AS_INIT
515 AS_ME_PREPARE
516 test "$as_me" = script || AS_ECHO([["incorrect value of \$as_me: $as_me"]])
519 AT_CHECK_M4SH
520 AT_CHECK([$CONFIG_SHELL ./script])
522 AT_CLEANUP
527 ## ----------------------------- ##
528 ## Negated classes in globbing.  ##
529 ## ----------------------------- ##
531 # According to http://www.in-ulm.de/~mascheck/bourne/, all shells with
532 # functions also support `[!...]'.  But `[^...]' is not universally supported.
534 AT_SETUP([Negated classes in globbing])
535 AT_KEYWORDS([m4sh])
537 AT_DATA_M4SH([script.as],
538 [[AS_INIT
540 case 'with!two!bangs' in
541   *[[!a-z]]*) ;;
542            *) AS_ERROR([[`*[!a-z]*' didn't match `with!two!bangs']]);;
543 esac
545 case without in
546   *[[!a-z]]*) AS_ERROR([[`*[!a-z]*' matched `without']]);;
547 esac
550 AT_CHECK_M4SH
551 AT_CHECK([$CONFIG_SHELL ./script])
553 AT_CLEANUP
558 ## ------------------- ##
559 ## Functions Support.  ##
560 ## ------------------- ##
562 # All m4sh scripts require function support.
564 AT_SETUP([Functions Support])
565 AT_KEYWORDS([m4sh])
567 AT_DATA_M4SH([script.as],
568 [[AS_INIT
569 AS_LINENO_PREPARE
571 func_return () {
572   (exit $1)
575 func_success () {
576   func_return 0
579 func_failure () {
580   func_return 1
583 if func_success; then
584   if func_failure; then
585     AS_ERROR([func_failure passed])
586   fi
587 else
588   AS_ERROR([func_success failed])
592 AT_CHECK_M4SH
593 AT_CHECK([$CONFIG_SHELL ./script])
595 AT_CLEANUP
600 ## ------------------------------ ##
601 ## Functions and return Support.  ##
602 ## ------------------------------ ##
604 # All m4sh scripts require working return within functions.
606 AT_SETUP([Functions and return Support])
607 AT_KEYWORDS([m4sh])
609 AT_DATA_M4SH([script.as],
610 [[AS_INIT
611 AS_LINENO_PREPARE
613 func_success () {
614   return 0
617 func_failure () {
618   return 1
621 if func_success; then
622   if func_failure; then
623     AS_ERROR([func_failure passed])
624   fi
625 else
626   AS_ERROR([func_success failed])
630 AT_CHECK_M4SH
631 AT_CHECK([$CONFIG_SHELL ./script])
633 AT_CLEANUP
636 ## --------------------------- ##
637 ## Nested AS_REQUIRE_SHELL_FN. ##
638 ## --------------------------- ##
640 # Hypothesis: M4sh expands nested AS_REQUIRE_SHELL_FN
641 # separately.
643 AT_SETUP([Nested AS@&t@_REQUIRE_SHELL_FN])
644 AT_KEYWORDS([m4sh])
646 AT_DATA_M4SH([script.as], [[dnl
647 m4_define([INIT], [oops])dnl
648 AS_INIT
650 m4_defun([TEST_FUNC2_BODY], [
654 m4_defun([TEST_FUNC1_BODY], [
655 AS_REQUIRE_SHELL_FN([test_func2], [], [TEST_FUNC2_BODY])
659 AS_REQUIRE_SHELL_FN([test_func1], [], [TEST_FUNC1_BODY])
660 test_func2
663 AT_CHECK_M4SH
664 AT_CHECK([$CONFIG_SHELL ./script])
666 AT_CLEANUP
669 ## ------------------- ##
670 ## Nested AS_REQUIRE.  ##
671 ## ------------------- ##
673 # Hypothesis: M4sh expands the requirements of AS_REQUIRE in the
674 # requested diversion, even if other AS_REQUIREs are interleaved.
676 AT_SETUP([Nested AS@&t@_REQUIRE])
677 AT_KEYWORDS([m4sh])
679 AT_DATA_M4SH([script.as], [[dnl
680 AS_INIT
682 m4_defun([in_fn_diversion], still_in_m4sh_init_fn=yes)
683 m4_defun([not_in_fn_diversion], still_in_m4sh_init_fn=no)
685 m4_defun([NESTED], [nested_require_in_fn_diversion=$still_in_m4sh_init_fn])
687 m4_defun([OUTER], [AS_REQUIRE([NESTED])dnl
688 outer_require_in_fn_diversion=$still_in_m4sh_init_fn])
690 m4_defun([test_init], [
691 AS_REQUIRE([in_fn_diversion], , [M4SH-INIT-FN])
692 AS_REQUIRE([OUTER], , [M4SH-INIT-FN])
693 AS_REQUIRE([not_in_fn_diversion], , [M4SH-INIT-FN])
696 test_init
697 if test $outer_require_in_fn_diversion != yes; then AS_EXIT([1]); fi
698 if test $nested_require_in_fn_diversion != no; then AS_EXIT([1]); fi
701 AT_CHECK_M4SH
702 AT_CHECK([$CONFIG_SHELL ./script])
704 AT_CLEANUP
707 ## ------------------------------------ ##
708 ## AS_REQUIRE_SHELL_FN and m4_require.  ##
709 ## ------------------------------------ ##
711 # Hypothesis: M4sh expands the requirements of AS_REQUIRE_SHELL_FN
712 # in M4SH-INIT-FN.  This changed after Autoconf 2.63.
714 AT_SETUP([AS@&t@_REQUIRE_SHELL_FN and m4@&t@_require])
715 AT_KEYWORDS([m4sh])
717 AT_DATA_M4SH([script.as], [[dnl
718 AS_INIT
720 m4_defun([in_m4_sh_init], still_in_m4sh_init=yes)
721 m4_defun([not_in_m4_sh_init], still_in_m4sh_init=no)
723 m4_defun([error_if_emitted_in_m4sh_init], [
724   if test x$still_in_m4sh_init = xyes; then
725     AS_ERROR([requirement emitted in M4SH-INIT])
726   fi
729 m4_defun([TEST_FUNC_BODY], [
730 m4_require([error_if_emitted_in_m4sh_init])
731 : echo in shell function, with parameter = [$]1
735 m4_defun([test_init], [
736 AS_REQUIRE([in_m4_sh_init], , [M4SH-INIT-FN])
737 AS_REQUIRE_SHELL_FN([test_func], [], [TEST_FUNC_BODY])
738 AS_REQUIRE([not_in_m4_sh_init])
741 test_init
742 test_func parameter1
745 AT_CHECK_M4SH
746 AT_CHECK([$CONFIG_SHELL ./script])
748 AT_CLEANUP
751 ## -------------- ##
752 ## AS_HELP_STRING ##
753 ## -------------- ##
755 AT_SETUP([AS@&t@_HELP_STRING])
756 AT_KEYWORDS([m4sh m4@&t@_text_wrap m4@&t@_expand])
758 AT_DATA_M4SH([script.as],
759 [[AS_INIT
761 echo "AS_HELP_STRING([--an-option],[some text])"
762 echo "AS_HELP_STRING([--another-much-longer-option],
763 [some other text which should wrap at our default of 80 characters.])"
764 echo "AS_HELP_STRING([--fooT=barT], [foo bar])"
765 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@], [foo bar])"
766 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@123456789], [foo bar])"
767 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@1234567890], [foo bar])"
768 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@12345678901], [foo bar])"
769 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@123456789012], [foo bar])"
770 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@1234567890123], [foo bar])"
771 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@],
772 [some other text which should wrap at our default of 80 characters.])"
773 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@123456789],
774 [some other text which should wrap at our default of 80 characters.])"
775 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@1234567890],
776 [some other text which should wrap at our default of 80 characters.])"
777 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@12345678901],
778 [some other text which should wrap at our default of 80 characters.])"
779 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@123456789012],
780 [some other text which should wrap at our default of 80 characters.])"
781 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@1234567890123],
782 [some other text which should wrap at our default of 80 characters.])"
783 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@],
784 [some other @<][:@ex@:][>@ which should wrap at our default of 80 characters.])"
785 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@123456789],
786 [some other @<][:@ex@:][>@ which should wrap at our default of 80 characters.])"
787 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@1234567890],
788 [some other @<][:@ex@:][>@ which should wrap at our default of 80 characters.])"
789 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@12345678901],
790 [some other @<][:@ex@:][>@ which should wrap at our default of 80 characters.])"
791 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@123456789012],
792 [some other @<][:@ex@:][>@ which should wrap at our default of 80 characters.])"
793 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@1234567890123],
794 [some other @<][:@ex@:][>@ which should wrap at our default of 80 characters.])"
795 echo "AS_HELP_STRING([[--foo[=bar]]],
796 [some other t[]t which should wrap at our default of 80 characters.])"
797 echo "AS_HELP_STRING([[--foo[=bar]123456789]],
798 [some other t[]t which should wrap at our default of 80 characters.])"
799 echo "AS_HELP_STRING([[--foo[=bar]1234567890]],
800 [some other t[]t which should wrap at our default of 80 characters.])"
801 echo "AS_HELP_STRING([[--foo[=bar]12345678901]],
802 [some other t[]t which should wrap at our default of 80 characters.])"
803 echo "AS_HELP_STRING([[--foo[=bar]123456789012]],
804 [some other t[]t which should wrap at our default of 80 characters.])"
805 echo "AS_HELP_STRING([[--foo[=bar]1234567890123]],
806 [some other t[]t which should wrap at our default of 80 characters.])"
807 m4_define([mac], [MACRO])dnl
808 echo "AS_HELP_STRING([--mac], [mac])"
809 echo "AS_HELP_STRING([--o1, --o2], [two
810 options,        one  description])"
811 echo "AS_HELP_STRING([[[--o3, --o4]]], [comma inside literal quoting])"
812 echo "AS_HELP_STRING([--tune1], [check out the tuned formatting],
813 [            ])"
814 echo "AS_HELP_STRING([--tune2], [check out the tuned formatting],
815 [12])"
816 echo "AS_HELP_STRING([--tune3], [check out the tuned formatting],
817 [], [40])"
818 echo "AS_HELP_STRING([--tune4], [check out the tuned formatting],
819 [12], [40])"
822 AT_CHECK_M4SH
823 AT_CHECK([$CONFIG_SHELL ./script], [0],
824 [[  --an-option             some text
825   --another-much-longer-option
826                           some other text which should wrap at our default of
827                           80 characters.
828   --fooT=barT             foo bar
829   --foo[=bar]             foo bar
830   --foo[=bar]123456789    foo bar
831   --foo[=bar]1234567890   foo bar
832   --foo[=bar]12345678901  foo bar
833   --foo[=bar]123456789012 foo bar
834   --foo[=bar]1234567890123
835                           foo bar
836   --foo[=bar]             some other text which should wrap at our default of
837                           80 characters.
838   --foo[=bar]123456789    some other text which should wrap at our default of
839                           80 characters.
840   --foo[=bar]1234567890   some other text which should wrap at our default of
841                           80 characters.
842   --foo[=bar]12345678901  some other text which should wrap at our default of
843                           80 characters.
844   --foo[=bar]123456789012 some other text which should wrap at our default of
845                           80 characters.
846   --foo[=bar]1234567890123
847                           some other text which should wrap at our default of
848                           80 characters.
849   --foo[=bar]             some other [ex] which should wrap at our default of
850                           80 characters.
851   --foo[=bar]123456789    some other [ex] which should wrap at our default of
852                           80 characters.
853   --foo[=bar]1234567890   some other [ex] which should wrap at our default of
854                           80 characters.
855   --foo[=bar]12345678901  some other [ex] which should wrap at our default of
856                           80 characters.
857   --foo[=bar]123456789012 some other [ex] which should wrap at our default of
858                           80 characters.
859   --foo[=bar]1234567890123
860                           some other [ex] which should wrap at our default of
861                           80 characters.
862   --foo[=bar]             some other t[]t which should wrap at our default of
863                           80 characters.
864   --foo[=bar]123456789    some other t[]t which should wrap at our default of
865                           80 characters.
866   --foo[=bar]1234567890   some other t[]t which should wrap at our default of
867                           80 characters.
868   --foo[=bar]12345678901  some other t[]t which should wrap at our default of
869                           80 characters.
870   --foo[=bar]123456789012 some other t[]t which should wrap at our default of
871                           80 characters.
872   --foo[=bar]1234567890123
873                           some other t[]t which should wrap at our default of
874                           80 characters.
875   --MACRO                 mac
876   --o1, --o2              two options, one description
877   [--o3, --o4]            comma inside literal quoting
878   --tune1   check out the tuned formatting
879   --tune2   check out the tuned formatting
880   --tune3                 check out the
881                           tuned
882                           formatting
883   --tune4   check out the tuned
884             formatting
887 AT_CLEANUP
890 ## ------------------- ##
891 ## AS_IF and AS_CASE.  ##
892 ## ------------------- ##
894 AT_SETUP([AS@&t@_IF and AS@&t@_CASE])
895 AT_KEYWORDS([m4sh m4@&t@_map_args_pair])
897 AT_DATA_M4SH([script.as], [[dnl
898 AS_INIT
899 # Syntax checks: cope with empty arguments.
900 AS_IF([:], [], [echo wrong])
901 AS_IF([:], [echo one], [echo wrong])
902 AS_IF([false], [echo wrong], [echo two])
903 AS_IF([false], [echo wrong])
904 # n-ary version
905 AS_IF([false], [echo wrong],
906       [:], [echo three])
907 AS_IF([false], [echo wrong],
908       [:], [echo four],
909       [echo wrong])
910 AS_IF([false], [echo wrong],
911       [false], [echo wrong])
912 AS_IF([false], [echo wrong],
913       [false], [echo wrong],
914       [echo five])
915 AS_IF([false], [echo wrong],
916       [false], [echo wrong],
917       [:], [echo six],
918       [echo wrong])
919 AS_CASE([foo])
920 AS_CASE([foo], [echo seven])
921 AS_CASE([foo],
922         [foo], [echo eight],
923         [echo wrong])
924 AS_CASE([foo],
925         [foo], [echo nine],
926         [*],   [echo wrong])
927 AS_CASE([foo],
928         [bar], [echo wrong],
929         [foo], [echo ten],
930         [*],   [echo wrong])
932 # check for nesting, lists, and side effects, and quoting robustness
933 empty=
934 AS_IF([AS_IF([$empty], [echo eleven])]) && AS_CASE([foo]) && echo twelve
935 rm -f file
936 AS_IF([touch file; false]) && echo thirteen
937 test -f file && echo fourteen
938 rm -f file
939 AS_CASE([`touch file; false`]) && test -f file && echo fifteen
940 dnl The next line is badly underquoted; don't intentionally copy this style.
941 AS_CASE([foo], [foo], m4_do(AS_CASE([bar], [bar], [echo sixteen])))
942 dnl Handle blank arguments.
943 AS_IF([false], [:], [ ]) && AS_CASE([foo], [foo], []
944 ) && echo seventeen
945 m4_define([empty])AS_IF([:], [empty]
946 ) && AS_CASE([foo], [foo], [empty]) && echo eighteen
947 dnl We can't handle AS_IF([false], [:], [empty]) unless m4_expand is
948 dnl taught how to handle m4_require.  The user is responsible for
949 dnl avoiding the syntax error in that case.
951 # check that require works correctly
952 m4_for([n], 1, 9, [],
953 [m4_defun([FOO]n, [foo]n[=]n)dnl
954 m4_defun([BAR]n,
955          [m4_require([FOO]]n[)dnl
956 bar]n[=]n)[]dnl
959 AS_IF([:], [BAR1])
960 echo "foo1=$foo1 bar1=$bar1"
961 AS_IF([:], [], [BAR2])
962 echo "foo2=$foo2 bar2=$bar2"
963 AS_IF([false], [BAR3])
964 echo "foo3=$foo3 bar3=$bar3"
965 AS_IF([false], [], [BAR4])
966 echo "foo4=$foo4 bar4=$bar4"
967 AS_CASE([x], [x], [BAR5])
968 echo "foo5=$foo5 bar5=$bar5"
969 AS_CASE([x], [y], [BAR6])
970 echo "foo6=$foo6 bar6=$bar6"
971 AS_CASE([x],
972         [x], [:],
973         [BAR7])
974 echo "foo7=$foo7 bar7=$bar7"
975 AS_CASE([x],
976         [y], [:],
977         [BAR8])
978 echo "foo8=$foo8 bar8=$bar8"
979 AS_CASE([x],
980         [y], [:],
981         [x], [BAR9])
982 echo "foo9=$foo9 bar9=$bar9"
985 AT_CHECK_M4SH
986 AT_CHECK([$CONFIG_SHELL ./script], [0], [[one
988 three
989 four
990 five
992 seven
993 eight
994 nine
996 eleven
997 twelve
998 thirteen
999 fourteen
1000 fifteen
1001 sixteen
1002 seventeen
1003 eighteen
1004 foo1=1 bar1=1
1005 foo2=2 bar2=
1006 foo3=3 bar3=
1007 foo4=4 bar4=4
1008 foo5=5 bar5=5
1009 foo6=6 bar6=
1010 foo7=7 bar7=
1011 foo8=8 bar8=8
1012 foo9=9 bar9=9
1015 dnl stress test for large number of conditionals
1016 dnl too large, and we start tickling shell bugs
1017 m4_pushdef([limit], [1000])dnl
1018 AT_DATA_M4SH([script.as], [[dnl
1019 AS_INIT
1020 AS_IF(m4_shift(m4_for([i], [1], ]limit[, [], [, test $[1] = i, echo i])))
1021 AS_IF(m4_shift(m4_for([i], [1], ]limit[, [], [, test $[1] = i, echo i])),
1022       [echo default])
1023 AS_CASE([$[1]]m4_for([i], [1], ]limit[, [], [, i, echo i]))
1024 AS_CASE([$[1]]m4_for([i], [1], ]limit[, [], [, i, echo i]), [echo default])
1027 dnl Add --force so autom4te doesn't think `script' is still up to date.
1028 AT_CHECK_M4SH([--force])
1029 AT_CHECK([$CONFIG_SHELL ./script 1], [0], [[1
1034 AT_CHECK([$CONFIG_SHELL ./script limit], [0], [limit
1035 limit
1036 limit
1037 limit
1039 AT_CHECK([$CONFIG_SHELL ./script default], [0], [[default
1040 default
1042 m4_popdef([limit])
1044 AT_CLEANUP
1047 ## -------- ##
1048 ## AS_FOR.  ##
1049 ## -------- ##
1051 AT_SETUP([AS@&t@_FOR])
1052 AT_KEYWORDS([m4sh])
1054 AT_DATA_M4SH([script.as], [[dnl
1055 AS_INIT
1057 # Simple checks.
1058 AS_FOR([m4var], [shvar], [a],
1059 [echo "m4var $shvar"])
1060 AS_FOR([m4var], [shvar], [b c],
1061 [echo "m4var $shvar"])
1062 list='d e'
1063 AS_FOR([m4var], [shvar], [$list],
1064 [echo "m4var $shvar"])
1065 AS_FOR([m4var], [shvar], ["$list"],
1066 [echo "m4var $shvar"])
1067 AS_FOR([m4var], [shvar], ['$list'],
1068 [echo "m4var $shvar"])
1069 AS_FOR([m4var], [shvar], [\'],
1070 [echo "m4var $shvar"])
1072 # Syntax checks: cope with empty/blank arguments.
1073 set f g
1074 AS_FOR([], [shvar], [],
1075 [echo "m4_defn([]) $shvar"])
1076 rm -f file
1077 AS_FOR([], [shvar], [`touch file`])
1078 test -f file || exit 1
1079 AS_FOR([], [shvar], [], [ ])
1080 m4_define([empty])AS_FOR([], [shvar], [], [empty])
1082 # Check that break works.
1083 while :
1085   AS_FOR([m4var], [shvar], [h i],
1086     [echo "m4var"; break 2])
1087   exit 1
1088 done
1089 while :
1091   AS_FOR([m4var], [shvar], [j],
1092     [echo "m4var"; break 2])
1093   exit 1
1094 done
1097 AT_CHECK_M4SH
1098 AT_CHECK([$CONFIG_SHELL ./script], [0], [[a a
1099 b b
1100 c c
1101 d d
1102 e e
1103 d e d e
1104 $list $list
1105 ' '
1106 f f
1107 g g
1112 AT_CLEANUP
1115 ## --------------- ##
1116 ## AS_LITERAL_IF.  ##
1117 ## --------------- ##
1119 AT_SETUP([AS@&t@_LITERAL_IF])
1120 AT_KEYWORDS([m4sh AS@&t@_LITERAL_WORD_IF AS@&t@_LITERAL_HEREDOC_IF])
1122 AT_DATA_M4SH([script.as], [[dnl
1123 AS_INIT
1124 echo AS_LITERAL_IF([lit], [ok], [ERR]) 1
1125 echo AS_LITERAL_IF([l-/.it], [ok], [ERR]) 2
1126 echo AS_LITERAL_IF([l''it], [ERR], [ok]) 3
1127 echo AS_LITERAL_IF([l$it], [ERR], [ok]) 4
1128 echo AS_LITERAL_IF([l$it], [ERR1], [ERR2], [ok]) 5
1129 echo AS_LITERAL_IF([l${it}], [ERR1], [ERR2], [ok]) 6
1130 echo AS_LITERAL_IF([l`case a in b) ;; esac`it], [ERR], [ok]) 7
1131 echo AS_LITERAL_IF([l`case a in b) ;; esac`it], [ERR1], [ok], [ERR2]) 8
1132 m4_define([mac], [l-/.it])
1133 echo AS_LITERAL_IF([mac], [ok], [ERR]) 9
1134 echo AS_LITERAL_IF([mac($, ``)], [ok], [ERR]) 10
1135 m4_define([mac], [l$it])
1136 echo AS_LITERAL_IF([mac], [ERR], [ok]) 11
1137 echo AS_LITERAL_IF([mac], [ERR1], [ERR2], [ok]) 12
1138 m4_define([mac], [l``it])
1139 echo AS_LITERAL_IF([mac], [ERR], [ok]) 13
1140 echo AS_LITERAL_IF([mac], [ERR1], [ok], [ERR2]) 14
1141 echo AS_LITERAL_IF([    a ][
1142 b], [ok], [ERR]) 15
1143 echo AS_LITERAL_WORD_IF([       a ][
1144 b], [ERR], [ok]) 16
1145 echo AS_LITERAL_HEREDOC_IF([    a ][
1146 b], [ok], [ERR]) 17
1147 echo AS_LITERAL_IF([(a)], [ERR], [ok]) 18
1148 echo AS_LITERAL_WORD_IF([(a)], [ERR], [ok]) 19
1149 echo AS_LITERAL_HEREDOC_IF([(a)], [ok], [ERR]) 20
1150 echo AS_LITERAL_IF([@S|@a], [ERR], [ok]) 21
1151 echo AS_LITERAL_WORD_IF([@S|@a], [ERR], [ok]) 22
1152 echo AS_LITERAL_HEREDOC_IF([@S|@a], [ERR], [ok]) 23
1155 AT_CHECK_M4SH
1156 AT_CHECK([$CONFIG_SHELL ./script], [],
1157 [[ok 1
1158 ok 2
1159 ok 3
1160 ok 4
1161 ok 5
1162 ok 6
1163 ok 7
1164 ok 8
1165 ok 9
1166 ok 10
1167 ok 11
1168 ok 12
1169 ok 13
1170 ok 14
1171 ok 15
1172 ok 16
1173 ok 17
1174 ok 18
1175 ok 19
1176 ok 20
1177 ok 21
1178 ok 22
1179 ok 23
1182 AT_CLEANUP
1185 ## --------------------- ##
1186 ## AS_TR_SH, AS_TR_CPP.  ##
1187 ## --------------------- ##
1189 AT_SETUP([AS@&t@_TR_SH and AS@&t@_TR_CPP])
1191 AT_DATA_M4SH([script.as], [[dnl
1192 AS_INIT
1193 m4_define([abc], [hI])m4_define([ABC], [Hi])
1194 m4_define([hi], [oops])m4_define([HI], [OOPS])
1195 echo AS_TR_SH(abc) AS_TR_SH(aBc) AS_TR_SH(ABC)
1196 echo AS_TR_SH([abc]) AS_TR_SH([aBc]) AS_TR_SH([ABC])
1197 echo AS_TR_SH([[abc]]) AS_TR_SH([[aBc]]) AS_TR_SH([[ABC]])
1198 echo AS_TR_CPP(abc) AS_TR_CPP(aBc) AS_TR_CPP(ABC)
1199 echo AS_TR_CPP([abc]) AS_TR_CPP([aBc]) AS_TR_CPP([ABC])
1200 echo AS_TR_CPP([[abc]]) AS_TR_CPP([[aBc]]) AS_TR_CPP([[ABC]])
1201 echo ===
1202 [var=abc vAr=aBc VAR=ABC]
1203 echo AS_TR_SH($var) AS_TR_SH($vAr) AS_TR_SH($VAR)
1204 echo AS_TR_SH([$var]) AS_TR_SH([$vAr]) AS_TR_SH([$VAR])
1205 echo AS_TR_SH([[$var]]) AS_TR_SH([[$vAr]]) AS_TR_SH([[$VAR]])
1206 echo AS_TR_CPP($var) AS_TR_CPP($vAr) AS_TR_CPP($VAR)
1207 echo AS_TR_CPP([$var]) AS_TR_CPP([$vAr]) AS_TR_CPP([$VAR])
1208 echo AS_TR_CPP([[$var]]) AS_TR_CPP([[$vAr]]) AS_TR_CPP([[$VAR]])
1209 echo ===
1210 echo AS_TR_SH(`echo abc`) AS_TR_SH(`echo aBc`) AS_TR_SH(`echo ABC`)
1211 echo AS_TR_SH([`echo abc`]) AS_TR_SH([`echo aBc`]) AS_TR_SH([`echo ABC`])
1212 echo AS_TR_SH([[`echo abc`]]) AS_TR_SH([[`echo aBc`]]) AS_TR_SH([[`echo ABC`]])
1213 echo AS_TR_CPP(`echo abc`) AS_TR_CPP(`echo aBc`) AS_TR_CPP(`echo ABC`)
1214 echo AS_TR_CPP([`echo abc`]) AS_TR_CPP([`echo aBc`]) AS_TR_CPP([`echo ABC`])
1215 echo AS_TR_CPP([[`echo abc`]]) AS_TR_CPP([[`echo aBc`]]) AS_TR_CPP([[`echo ABC`]])
1216 echo ===
1217 echo AS_TR_SH([a.b/c+*-])
1218 echo AS_TR_CPP([a.b/c+*-])
1219 var=a.b/c+*-
1220 echo AS_TR_SH([$var])
1221 echo AS_TR_CPP([$var])
1222 m4_define([macro], [a.b/c+*-])
1223 echo AS_TR_SH([macro])
1224 echo AS_TR_CPP([macro])
1227 AT_CHECK_M4SH
1228 AT_CHECK([$CONFIG_SHELL ./script], [],
1229 [[hI aBc Hi
1230 hI aBc Hi
1231 abc aBc ABC
1232 HI ABC HI
1233 HI ABC HI
1234 ABC ABC ABC
1236 abc aBc ABC
1237 abc aBc ABC
1238 abc aBc ABC
1239 ABC ABC ABC
1240 ABC ABC ABC
1241 ABC ABC ABC
1243 hI aBc Hi
1244 hI aBc Hi
1245 abc aBc ABC
1246 HI ABC HI
1247 HI ABC HI
1248 ABC ABC ABC
1250 a_b_cpp_
1251 A_B_C_P_
1252 a_b_cpp_
1253 A_B_C_P_
1254 a_b_cpp_
1255 A_B_C_P_
1258 AT_CLEANUP
1261 ## ---------- ##
1262 ## AS_VAR_*.  ##
1263 ## ---------- ##
1265 AT_SETUP([AS@&t@_VAR basics])
1266 AT_KEYWORDS([m4sh AS@&t@_VAR_COPY AS@&t@_VAR_SET AS@&t@_VAR_GET])
1267 AT_KEYWORDS([AS@&t@_VAR_TEST_SET AS@&t@_VAR_SET_IF AS@&t@_VAR_IF])
1268 AT_KEYWORDS([AS@&t@_VAR_PUSHDEF AS@&t@_VAR_POPDEF])
1270 AT_DATA_M4SH([script.as], [[dnl
1271 AS_INIT
1272  m4_define([with], [WITH])
1273 # Literals.
1274 dnl AS_VAR_SET_IF also covers AS_VAR_TEST_SET
1275 AS_VAR_SET_IF([foo], [echo oops]) && echo ok
1276 AS_VAR_IF([foo], [], [echo ok], [echo oops])
1277 foo=
1278 AS_VAR_SET_IF([foo], [echo ok])
1279 AS_VAR_SET([foo], ['\a  "weird" `value` with; $fun '\''characters
1280 ']) # 'font-lock
1281 AS_VAR_COPY([bar], [foo])
1282 AS_ECHO(["$bar-"])
1283 AS_ECHO(["AS_VAR_GET([foo])-"])
1284 AS_VAR_SET_IF([foo], [echo ok], [echo oops])
1285 AS_VAR_IF([foo], [string], [echo oops]) && echo ok
1286 AS_VAR_PUSHDEF([tmp], [foo])
1287 AS_VAR_IF([tmp], ['\a  "weird" `value` with; $fun '\''characters
1288 '], [echo ok], [echo oops]) # 'font-lock
1289 AS_VAR_POPDEF([tmp])
1290 m4_ifdef([tmp], [echo oops])
1292 # Indirects via shell vars.
1293 echo '===='
1294 num=1
1295 AS_VAR_SET_IF([foo$num], [echo oops]) && echo ok
1296 AS_VAR_IF([foo$num], [], [echo ok], [echo oops])
1297 foo1=
1298 AS_VAR_SET_IF([foo$num], [echo ok])
1299 AS_VAR_SET([foo$num], ['\a  "weird" `value` with; $fun '\''characters
1300 ']) # 'font-lock
1301 AS_VAR_COPY([bar], [foo$num])
1302 num=2
1303 AS_VAR_COPY([foo$num], [bar])
1304 AS_ECHO(["$foo2-"])
1305 AS_ECHO(["AS_VAR_GET([foo$num])-"])
1306 AS_VAR_SET_IF([foo$num], [echo ok], [echo oops])
1307 AS_VAR_IF([foo$num], [string], [echo oops]) && echo ok
1308 AS_VAR_PUSHDEF([tmp], [foo$num])
1309 AS_VAR_IF([tmp], ['\a  "weird" `value` with; $fun '\''characters
1310 '], [echo ok], [echo oops]) # 'font-lock
1311 AS_VAR_POPDEF([tmp])
1312 m4_ifdef([tmp], [echo oops])
1314 # Indirects via command substitution.
1315 echo '===='
1316 AS_VAR_SET_IF([`echo foo3`], [echo oops]) && echo ok
1317 AS_VAR_IF([`echo foo3`], [], [echo ok], [echo oops])
1318 foo3=
1319 AS_VAR_SET_IF([`echo foo3`], [echo ok])
1320 AS_VAR_SET([`echo foo3`], ['\a  "weird" `value` with; $fun '\''characters
1321 ']) # 'font-lock
1322 AS_VAR_COPY([bar], [`echo foo3`])
1323 num=2
1324 AS_VAR_COPY([`echo foo4`], [bar])
1325 AS_ECHO(["$foo4-"])
1326 AS_ECHO(["AS_VAR_GET([`echo foo4`])-"])
1327 AS_VAR_SET_IF([`echo foo4`], [echo ok], [echo oops])
1328 AS_VAR_IF([`echo foo4`], [string], [echo oops]) && echo ok
1329 AS_VAR_PUSHDEF([tmp], [`echo foo4`])
1330 AS_VAR_IF([tmp], ['\a  "weird" `value` with; $fun '\''characters
1331 '], [echo ok], [echo oops]) # 'font-lock
1332 AS_VAR_POPDEF([tmp])
1333 m4_ifdef([tmp], [echo oops])
1337 AT_CHECK_M4SH
1338 AT_CHECK([$CONFIG_SHELL ./script], [], [[ok
1341 \a  "weird" `value` WITH; $fun 'characters
1343 \a  "weird" `value` WITH; $fun 'characters
1348 ====
1352 \a  "weird" `value` WITH; $fun 'characters
1354 \a  "weird" `value` WITH; $fun 'characters-
1358 ====
1362 \a  "weird" `value` WITH; $fun 'characters
1364 \a  "weird" `value` WITH; $fun 'characters-
1370 AT_CLEANUP
1373 ## --------------- ##
1374 ## AS_VAR_APPEND.  ##
1375 ## --------------- ##
1377 AT_SETUP([AS@&t@_VAR_APPEND])
1378 AT_KEYWORDS([m4sh AS@&t@_VAR])
1380 AT_DATA_M4SH([script.as], [[dnl
1381 AS_INIT
1382 # Literals.
1383 AS_VAR_APPEND([foo], ["hello,  "])
1384 AS_VAR_APPEND([foo], [world])
1385 echo "$foo"
1386 # Indirects via shell vars.
1387 num=1
1388 AS_VAR_APPEND([foo$num], ['hello,  '])
1389 AS_VAR_APPEND([foo$num], [`echo "world"`])
1390 echo "$foo1"
1391 # Indirects via command substitution.
1392 h=hello w=',  world'
1393 AS_VAR_APPEND([`echo foo2`], [${h}])
1394 AS_VAR_APPEND([`echo foo2`], ["$w"])
1395 echo "$foo2"
1398 AT_CHECK_M4SH
1399 AT_CHECK([$CONFIG_SHELL ./script], [],
1400 [[hello,  world
1401 hello,  world
1402 hello,  world
1405 AT_CLEANUP
1408 ## -------------- ##
1409 ## AS_VAR_ARITH.  ##
1410 ## -------------- ##
1412 AT_SETUP([AS@&t@_VAR_ARITH])
1413 AT_KEYWORDS([m4sh AS@&t@_VAR])
1415 AT_DATA_M4SH([script.as], [[dnl
1416 AS_INIT
1417 # Literals.
1418 AS_VAR_ARITH([foo], [1 + 1])
1419 echo "$foo"
1420 # Indirects via shell vars.
1421 num=1
1422 AS_VAR_ARITH([foo$num], [\( 2 + 3 \) \* 4])
1423 echo "$foo1"
1424 # Indirects via command substitution.
1425 AS_VAR_ARITH([`echo foo2`], [0 + -2 + $foo1 / 2])
1426 echo "$foo2"
1429 AT_CHECK_M4SH
1430 AT_CHECK([$CONFIG_SHELL ./script], [],
1436 AT_CLEANUP
1439 ## ----------------- ##
1440 ## AS_INIT cleanup.  ##
1441 ## ----------------- ##
1443 AT_SETUP([AS@&t@_INIT cleanup])
1444 AT_KEYWORDS([m4sh m4@&t@_wrap m4@&t@_wrap_lifo])
1446 AT_DATA_M4SH([script.as], [[dnl
1447 dnl Registered before AS_INIT's cleanups
1448 m4_wrap([echo cleanup 1
1450 m4_pushdef([_AS_SHELL_FN_SPY])dnl neutralize the spy, we don't care about it
1451 AS_INIT
1452 dnl Registered after AS_INIT's cleanups, thus goes to KILL diversion
1453 m4_wrap([echo cleanup 2
1454 dnl However, nested wraps and diversions can still be used
1455 dnl Also, test wrapping text that looks like parameter reference
1456 m4_wrap([echo cleanup 3
1457 m4_divert_text([M4SH-INIT], [m4_define([foo], [$1])dnl
1458 echo prep foo([4])
1459 ])])])
1460 dnl Registered before AS_INIT's cleanups
1461 m4_wrap_lifo([echo cleanup 5
1463 echo body
1466 AT_CHECK_M4SH
1467 AT_CHECK([$CONFIG_SHELL ./script], [], [[prep 4
1468 body
1469 cleanup 5
1470 cleanup 1
1473 AT_CLEANUP
1476 ## ------------------- ##
1477 ## AS_INIT_GENERATED.  ##
1478 ## ------------------- ##
1480 AT_SETUP([AS@&t@_INIT_GENERATED])
1481 AT_KEYWORDS([AS@&t@_MESSAGE AS@&t@_MESSAGE_LOG_FD])
1483 dnl First run, no logging, tests shell selection
1484 AT_DATA_M4SH([script.as], [[dnl
1485 AS_INIT
1486 AS_INIT_GENERATED([child], [echo hello from child])
1487 cat >>child <<\EOF
1488 AS_ECHO(["SHELL=$SHELL"])
1490 echo hello from parent
1491 AS_ECHO(["SHELL=$SHELL"])
1494 AT_CHECK_M4SH
1495 AT_CHECK([$CONFIG_SHELL ./script], [0], [stdout])
1496 AT_CHECK([grep 'SHELL=.' stdout], [0], [ignore])
1497 sed s/parent/child/ <stdout >expout
1498 AT_CHECK([./child], [0], [expout])
1499 SHELL=/bogus
1500 export SHELL
1501 cp stdout expout
1502 mv child child.bak
1503 AT_CHECK([$CONFIG_SHELL ./script], [0], [expout])
1504 AT_CHECK([cmp child child.bak])
1505 AT_CHECK([grep 'SHELL=.' stdout], [0], [ignore])
1506 sed s/parent/child/ <stdout >expout
1507 AT_CHECK([./child], [0], [expout])
1510 dnl Second run, with logging from parent and child, tests fd handling
1511 AT_DATA_M4SH([script.as], [[dnl
1512 AS_INIT
1513 child=${1-child}
1514 m4_define([AS_MESSAGE_LOG_FD], [5])
1515 exec AS_MESSAGE_LOG_FD>log
1516 AS_INIT_GENERATED([$child], [echo hello1 from $child]) || AS_EXIT([1])
1517 cat >>$child <<\EOF
1518 m4_pushdef([AS_MESSAGE_LOG_FD])
1519 AS_MESSAGE([hello2 from ${child}child])
1520 m4_popdef([AS_MESSAGE_LOG_FD])
1521 exec AS_MESSAGE_LOG_FD>>log
1522 AS_MESSAGE([hello3 from child])
1524 AS_MESSAGE([hello from parent])
1525 dnl close log in parent before spawning child, for mingw
1526 exec AS_MESSAGE_LOG_FD>&-
1527 ./$child
1530 rm -f script
1531 AT_CHECK_M4SH
1532 AT_CHECK([$CONFIG_SHELL ./script], [0], [[script: hello from parent
1533 hello1 from child
1534 child: hello2 from child
1535 child: hello3 from child
1537 AT_CHECK([[sed 's,:[0-9][0-9]*:,:0:,' log]], [0],
1538 [[script:0: hello from parent
1539 child:0: hello3 from child
1542 # Force write error creating a file on stdout
1543 if test -w /dev/full && test -c /dev/full; then
1544   AT_CHECK([$CONFIG_SHELL ./script /dev/full], [1], [ignore], [ignore])
1547 AT_CLEANUP
1550 ## --------------- ##
1551 ## AS_MESSAGE_FD.  ##
1552 ## --------------- ##
1554 AT_SETUP([AS@&t@_MESSAGE_FD])
1555 AT_KEYWORDS([AS@&t@_MESSAGE AS@&t@_MESSAGE_LOG_FD AS@&t_ORIGINAL_STDIN_FD])
1556 AT_KEYWORDS([AS@&t@_LINENO_PUSH])
1558 AT_DATA_M4SH([script.as], [[dnl
1559 AS_INIT
1560 m4_define([AS_ORIGINAL_STDIN_FD], [5])
1561 m4_define([AS_MESSAGE_LOG_FD], [6])
1562 m4_define([AS_MESSAGE_FD], [7])
1563 exec AS_ORIGINAL_STDIN_FD<&0 </dev/null AS_MESSAGE_LOG_FD>log
1564 if test $[#] -gt 0; then
1565   exec AS_MESSAGE_FD>/dev/null
1566 else
1567   exec AS_MESSAGE_FD>&1
1569 AS_LINENO_PUSH([100])
1570 cat # tests that stdin is neutralized
1571 AS_MESSAGE([hello world])
1572 cat <&AS_ORIGINAL_STDIN_FD
1575 AT_CHECK_M4SH
1576 AT_CHECK([echo goodbye | $CONFIG_SHELL ./script], [0],
1577 [[script: hello world
1578 goodbye
1580 AT_CHECK([cat log], [0],
1581 [[script:100: hello world
1583 rm log
1584 AT_CHECK([echo goodbye | $CONFIG_SHELL ./script silent], [0],
1585 [[goodbye
1587 AT_CHECK([cat log], [0],
1588 [[script:100: hello world
1591 AT_CLEANUP
1594 ## --------------- ##
1595 ## _AS_CLEAN_DIR.  ##
1596 ## --------------- ##
1598 AT_SETUP([_AS@&t@_CLEAN_DIR])
1600 dnl ensure that we can erase all files in a directory.  Note that
1601 dnl _AS_CLEAN_DIR needs three globs to catch all these files.
1602 AT_DATA_M4SH([script.as], [[dnl
1603 AS_INIT
1604 # Unwritable subdirectories are common during 'make distcheck'.
1605 mkdir sub sub/unwritable || AS_ERROR([failed to mkdir])
1606 touch sub/unwritable/file || AS_ERROR([failed to touch])
1607 chmod a-wx sub/unwritable || AS_ERROR([failed to chmod])
1608 # Cygwin 1.5 can't touch 'sub/...', so make that file optional.
1609 touch sub/a sub/aa sub/aaa sub/.a sub/..a sub/.aa \
1610   || AS_ERROR([failed to touch])
1611 touch sub/... 2>/dev/null
1612 _AS_CLEAN_DIR([sub]) || AS_ERROR([failed to clean])
1613 # rmdir instead of 'rm -fr' here proves that we emptied sub.
1614 rmdir sub || AS_ERROR([failed to rmdir])
1617 AT_CHECK_M4SH
1618 AT_CHECK([$CONFIG_SHELL ./script])
1620 AT_CLEANUP
1623 ## -------- ##
1624 ## ECHO_C.  ##
1625 ## -------- ##
1627 AT_SETUP([ECHO_C])
1629 AT_DATA_M4SH([script.as], [[dnl
1630 AS_INIT
1631 _AS_PREPARE
1632 foo=`echo foobar`
1633 echo "$foo"
1636 AT_CHECK_M4SH
1637 AT_CHECK([$CONFIG_SHELL ./script], [], [foobar
1640 AT_CLEANUP