AC_INIT: allow bugreport to contain '?'
[autoconf.git] / tests / m4sh.at
blob52ab4ee822481866cffb28507a55a2dd0b9bf1a4
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 # It is known that `[^...]' is not universally supported, but it is
532 # unknown for `[!...]'.
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 # Hypothesis: the shell we are running, after having checked for
563 # $LINENO support, supports functions.
565 AT_SETUP([Functions Support])
566 AT_KEYWORDS([m4sh])
568 AT_DATA_M4SH([script.as],
569 [[AS_INIT
570 AS_LINENO_PREPARE
572 func_return () {
573   (exit $1)
576 func_success () {
577   func_return 0
580 func_failure () {
581   func_return 1
584 if func_success; then
585   if func_failure; then
586     AS_ERROR([func_failure passed])
587   fi
588 else
589   AS_ERROR([func_success failed])
593 AT_CHECK_M4SH
594 AT_CHECK([$CONFIG_SHELL ./script])
596 AT_CLEANUP
601 ## ------------------------------ ##
602 ## Functions and return Support.  ##
603 ## ------------------------------ ##
605 # Hypothesis: the shell we are running, after having checked for
606 # $LINENO support, supports functions, and the `return' keyword.
608 AT_SETUP([Functions and return Support])
609 AT_KEYWORDS([m4sh])
611 AT_DATA_M4SH([script.as],
612 [[AS_INIT
613 AS_LINENO_PREPARE
615 func_success () {
616   return 0
619 func_failure () {
620   return 1
623 if func_success; then
624   if func_failure; then
625     AS_ERROR([func_failure passed])
626   fi
627 else
628   AS_ERROR([func_success failed])
632 AT_CHECK_M4SH
633 AT_CHECK([$CONFIG_SHELL ./script])
635 AT_CLEANUP
638 ## --------------------------- ##
639 ## Nested AS_REQUIRE_SHELL_FN. ##
640 ## --------------------------- ##
642 # Hypothesis: M4sh expands nested AS_REQUIRE_SHELL_FN
643 # separately.
645 AT_SETUP([Nested AS@&t@_REQUIRE_SHELL_FN])
646 AT_KEYWORDS([m4sh])
648 AT_DATA_M4SH([script.as], [[dnl
649 m4_define([INIT], [oops])dnl
650 AS_INIT
652 m4_defun([TEST_FUNC2_BODY], [
656 m4_defun([TEST_FUNC1_BODY], [
657 AS_REQUIRE_SHELL_FN([test_func2], [], [TEST_FUNC2_BODY])
661 AS_REQUIRE_SHELL_FN([test_func1], [], [TEST_FUNC1_BODY])
662 test_func2
665 AT_CHECK_M4SH
666 AT_CHECK([$CONFIG_SHELL ./script])
668 AT_CLEANUP
671 ## ------------------- ##
672 ## Nested AS_REQUIRE.  ##
673 ## ------------------- ##
675 # Hypothesis: M4sh expands the requirements of AS_REQUIRE in the
676 # requested diversion, even if other AS_REQUIREs are interleaved.
678 AT_SETUP([Nested AS@&t@_REQUIRE])
679 AT_KEYWORDS([m4sh])
681 AT_DATA_M4SH([script.as], [[dnl
682 AS_INIT
684 m4_defun([in_fn_diversion], still_in_m4sh_init_fn=yes)
685 m4_defun([not_in_fn_diversion], still_in_m4sh_init_fn=no)
687 m4_defun([NESTED], [nested_require_in_fn_diversion=$still_in_m4sh_init_fn])
689 m4_defun([OUTER], [AS_REQUIRE([NESTED])dnl
690 outer_require_in_fn_diversion=$still_in_m4sh_init_fn])
692 m4_defun([test_init], [
693 AS_REQUIRE([in_fn_diversion], , [M4SH-INIT-FN])
694 AS_REQUIRE([OUTER], , [M4SH-INIT-FN])
695 AS_REQUIRE([not_in_fn_diversion], , [M4SH-INIT-FN])
698 test_init
699 if test $outer_require_in_fn_diversion != yes; then AS_EXIT([1]); fi
700 if test $nested_require_in_fn_diversion != no; then AS_EXIT([1]); fi
703 AT_CHECK_M4SH
704 AT_CHECK([$CONFIG_SHELL ./script])
706 AT_CLEANUP
709 ## ------------------------------------ ##
710 ## AS_REQUIRE_SHELL_FN and m4_require.  ##
711 ## ------------------------------------ ##
713 # Hypothesis: M4sh expands the requirements of AS_REQUIRE_SHELL_FN
714 # in M4SH-INIT-FN.  This changed after Autoconf 2.63.
716 AT_SETUP([AS@&t@_REQUIRE_SHELL_FN and m4@&t@_require])
717 AT_KEYWORDS([m4sh])
719 AT_DATA_M4SH([script.as], [[dnl
720 AS_INIT
722 m4_defun([in_m4_sh_init], still_in_m4sh_init=yes)
723 m4_defun([not_in_m4_sh_init], still_in_m4sh_init=no)
725 m4_defun([error_if_emitted_in_m4sh_init], [
726   if test x$still_in_m4sh_init = xyes; then
727     AS_ERROR([requirement emitted in M4SH-INIT])
728   fi
731 m4_defun([TEST_FUNC_BODY], [
732 m4_require([error_if_emitted_in_m4sh_init])
733 : echo in shell function, with parameter = [$]1
737 m4_defun([test_init], [
738 AS_REQUIRE([in_m4_sh_init], , [M4SH-INIT-FN])
739 AS_REQUIRE_SHELL_FN([test_func], [], [TEST_FUNC_BODY])
740 AS_REQUIRE([not_in_m4_sh_init])
743 test_init
744 test_func parameter1
747 AT_CHECK_M4SH
748 AT_CHECK([$CONFIG_SHELL ./script])
750 AT_CLEANUP
753 ## -------------- ##
754 ## AS_HELP_STRING ##
755 ## -------------- ##
757 AT_SETUP([AS@&t@_HELP_STRING])
758 AT_KEYWORDS([m4sh m4@&t@_text_wrap m4@&t@_expand])
760 AT_DATA_M4SH([script.as],
761 [[AS_INIT
763 echo "AS_HELP_STRING([--an-option],[some text])"
764 echo "AS_HELP_STRING([--another-much-longer-option],
765 [some other text which should wrap at our default of 80 characters.])"
766 echo "AS_HELP_STRING([--fooT=barT], [foo bar])"
767 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@], [foo bar])"
768 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@123456789], [foo bar])"
769 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@1234567890], [foo bar])"
770 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@12345678901], [foo bar])"
771 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@123456789012], [foo bar])"
772 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@1234567890123], [foo bar])"
773 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@],
774 [some other text which should wrap at our default of 80 characters.])"
775 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@123456789],
776 [some other text which should wrap at our default of 80 characters.])"
777 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@1234567890],
778 [some other text which should wrap at our default of 80 characters.])"
779 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@12345678901],
780 [some other text which should wrap at our default of 80 characters.])"
781 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@123456789012],
782 [some other text which should wrap at our default of 80 characters.])"
783 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@1234567890123],
784 [some other text which should wrap at our default of 80 characters.])"
785 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@],
786 [some other @<][:@ex@:][>@ which should wrap at our default of 80 characters.])"
787 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@123456789],
788 [some other @<][:@ex@:][>@ which should wrap at our default of 80 characters.])"
789 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@1234567890],
790 [some other @<][:@ex@:][>@ which should wrap at our default of 80 characters.])"
791 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@12345678901],
792 [some other @<][:@ex@:][>@ which should wrap at our default of 80 characters.])"
793 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@123456789012],
794 [some other @<][:@ex@:][>@ which should wrap at our default of 80 characters.])"
795 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@1234567890123],
796 [some other @<][:@ex@:][>@ which should wrap at our default of 80 characters.])"
797 echo "AS_HELP_STRING([[--foo[=bar]]],
798 [some other t[]t which should wrap at our default of 80 characters.])"
799 echo "AS_HELP_STRING([[--foo[=bar]123456789]],
800 [some other t[]t which should wrap at our default of 80 characters.])"
801 echo "AS_HELP_STRING([[--foo[=bar]1234567890]],
802 [some other t[]t which should wrap at our default of 80 characters.])"
803 echo "AS_HELP_STRING([[--foo[=bar]12345678901]],
804 [some other t[]t which should wrap at our default of 80 characters.])"
805 echo "AS_HELP_STRING([[--foo[=bar]123456789012]],
806 [some other t[]t which should wrap at our default of 80 characters.])"
807 echo "AS_HELP_STRING([[--foo[=bar]1234567890123]],
808 [some other t[]t which should wrap at our default of 80 characters.])"
809 m4_define([mac], [MACRO])dnl
810 echo "AS_HELP_STRING([--mac], [mac])"
811 echo "AS_HELP_STRING([--o1, --o2], [two
812 options,        one  description])"
813 echo "AS_HELP_STRING([[[--o3, --o4]]], [comma inside literal quoting])"
814 echo "AS_HELP_STRING([--tune1], [check out the tuned formatting],
815 [            ])"
816 echo "AS_HELP_STRING([--tune2], [check out the tuned formatting],
817 [12])"
818 echo "AS_HELP_STRING([--tune3], [check out the tuned formatting],
819 [], [40])"
820 echo "AS_HELP_STRING([--tune4], [check out the tuned formatting],
821 [12], [40])"
824 AT_CHECK_M4SH
825 AT_CHECK([$CONFIG_SHELL ./script], [0],
826 [[  --an-option             some text
827   --another-much-longer-option
828                           some other text which should wrap at our default of
829                           80 characters.
830   --fooT=barT             foo bar
831   --foo[=bar]             foo bar
832   --foo[=bar]123456789    foo bar
833   --foo[=bar]1234567890   foo bar
834   --foo[=bar]12345678901  foo bar
835   --foo[=bar]123456789012 foo bar
836   --foo[=bar]1234567890123
837                           foo bar
838   --foo[=bar]             some other text which should wrap at our default of
839                           80 characters.
840   --foo[=bar]123456789    some other text which should wrap at our default of
841                           80 characters.
842   --foo[=bar]1234567890   some other text which should wrap at our default of
843                           80 characters.
844   --foo[=bar]12345678901  some other text which should wrap at our default of
845                           80 characters.
846   --foo[=bar]123456789012 some other text which should wrap at our default of
847                           80 characters.
848   --foo[=bar]1234567890123
849                           some other text which should wrap at our default of
850                           80 characters.
851   --foo[=bar]             some other [ex] which should wrap at our default of
852                           80 characters.
853   --foo[=bar]123456789    some other [ex] which should wrap at our default of
854                           80 characters.
855   --foo[=bar]1234567890   some other [ex] which should wrap at our default of
856                           80 characters.
857   --foo[=bar]12345678901  some other [ex] which should wrap at our default of
858                           80 characters.
859   --foo[=bar]123456789012 some other [ex] which should wrap at our default of
860                           80 characters.
861   --foo[=bar]1234567890123
862                           some other [ex] which should wrap at our default of
863                           80 characters.
864   --foo[=bar]             some other t[]t which should wrap at our default of
865                           80 characters.
866   --foo[=bar]123456789    some other t[]t which should wrap at our default of
867                           80 characters.
868   --foo[=bar]1234567890   some other t[]t which should wrap at our default of
869                           80 characters.
870   --foo[=bar]12345678901  some other t[]t which should wrap at our default of
871                           80 characters.
872   --foo[=bar]123456789012 some other t[]t which should wrap at our default of
873                           80 characters.
874   --foo[=bar]1234567890123
875                           some other t[]t which should wrap at our default of
876                           80 characters.
877   --MACRO                 mac
878   --o1, --o2              two options, one description
879   [--o3, --o4]            comma inside literal quoting
880   --tune1   check out the tuned formatting
881   --tune2   check out the tuned formatting
882   --tune3                 check out the
883                           tuned
884                           formatting
885   --tune4   check out the tuned
886             formatting
889 AT_CLEANUP
892 ## ------------------- ##
893 ## AS_IF and AS_CASE.  ##
894 ## ------------------- ##
896 AT_SETUP([AS@&t@_IF and AS@&t@_CASE])
897 AT_KEYWORDS([m4sh m4@&t@_map_args_pair])
899 AT_DATA_M4SH([script.as], [[dnl
900 AS_INIT
901 # Syntax checks: cope with empty arguments.
902 AS_IF([:], [], [echo wrong])
903 AS_IF([:], [echo one], [echo wrong])
904 AS_IF([false], [echo wrong], [echo two])
905 AS_IF([false], [echo wrong])
906 # n-ary version
907 AS_IF([false], [echo wrong],
908       [:], [echo three])
909 AS_IF([false], [echo wrong],
910       [:], [echo four],
911       [echo wrong])
912 AS_IF([false], [echo wrong],
913       [false], [echo wrong])
914 AS_IF([false], [echo wrong],
915       [false], [echo wrong],
916       [echo five])
917 AS_IF([false], [echo wrong],
918       [false], [echo wrong],
919       [:], [echo six],
920       [echo wrong])
921 AS_CASE([foo])
922 AS_CASE([foo], [echo seven])
923 AS_CASE([foo],
924         [foo], [echo eight],
925         [echo wrong])
926 AS_CASE([foo],
927         [foo], [echo nine],
928         [*],   [echo wrong])
929 AS_CASE([foo],
930         [bar], [echo wrong],
931         [foo], [echo ten],
932         [*],   [echo wrong])
934 # check for nesting, lists, and side effects, and quoting robustness
935 empty=
936 AS_IF([AS_IF([$empty], [echo eleven])]) && AS_CASE([foo]) && echo twelve
937 rm -f file
938 AS_IF([touch file; false]) && echo thirteen
939 test -f file && echo fourteen
940 rm -f file
941 AS_CASE([`touch file; false`]) && test -f file && echo fifteen
942 dnl The next line is badly underquoted; don't intentionally copy this style.
943 AS_CASE([foo], [foo], m4_do(AS_CASE([bar], [bar], [echo sixteen])))
944 dnl Handle blank arguments.
945 AS_IF([false], [:], [ ]) && AS_CASE([foo], [foo], []
946 ) && echo seventeen
947 m4_define([empty])AS_IF([:], [empty]
948 ) && AS_CASE([foo], [foo], [empty]) && echo eighteen
949 dnl We can't handle AS_IF([false], [:], [empty]) unless m4_expand is
950 dnl taught how to handle m4_require.  The user is responsible for
951 dnl avoiding the syntax error in that case.
953 # check that require works correctly
954 m4_for([n], 1, 9, [],
955 [m4_defun([FOO]n, [foo]n[=]n)dnl
956 m4_defun([BAR]n,
957          [m4_require([FOO]]n[)dnl
958 bar]n[=]n)[]dnl
961 AS_IF([:], [BAR1])
962 echo "foo1=$foo1 bar1=$bar1"
963 AS_IF([:], [], [BAR2])
964 echo "foo2=$foo2 bar2=$bar2"
965 AS_IF([false], [BAR3])
966 echo "foo3=$foo3 bar3=$bar3"
967 AS_IF([false], [], [BAR4])
968 echo "foo4=$foo4 bar4=$bar4"
969 AS_CASE([x], [x], [BAR5])
970 echo "foo5=$foo5 bar5=$bar5"
971 AS_CASE([x], [y], [BAR6])
972 echo "foo6=$foo6 bar6=$bar6"
973 AS_CASE([x],
974         [x], [:],
975         [BAR7])
976 echo "foo7=$foo7 bar7=$bar7"
977 AS_CASE([x],
978         [y], [:],
979         [BAR8])
980 echo "foo8=$foo8 bar8=$bar8"
981 AS_CASE([x],
982         [y], [:],
983         [x], [BAR9])
984 echo "foo9=$foo9 bar9=$bar9"
987 AT_CHECK_M4SH
988 AT_CHECK([$CONFIG_SHELL ./script], [0], [[one
990 three
991 four
992 five
994 seven
995 eight
996 nine
998 eleven
999 twelve
1000 thirteen
1001 fourteen
1002 fifteen
1003 sixteen
1004 seventeen
1005 eighteen
1006 foo1=1 bar1=1
1007 foo2=2 bar2=
1008 foo3=3 bar3=
1009 foo4=4 bar4=4
1010 foo5=5 bar5=5
1011 foo6=6 bar6=
1012 foo7=7 bar7=
1013 foo8=8 bar8=8
1014 foo9=9 bar9=9
1017 dnl stress test for large number of conditionals
1018 dnl too large, and we start tickling shell bugs
1019 m4_pushdef([limit], [1000])dnl
1020 AT_DATA_M4SH([script.as], [[dnl
1021 AS_INIT
1022 AS_IF(m4_shift(m4_for([i], [1], ]limit[, [], [, test $[1] = i, echo i])))
1023 AS_IF(m4_shift(m4_for([i], [1], ]limit[, [], [, test $[1] = i, echo i])),
1024       [echo default])
1025 AS_CASE([$[1]]m4_for([i], [1], ]limit[, [], [, i, echo i]))
1026 AS_CASE([$[1]]m4_for([i], [1], ]limit[, [], [, i, echo i]), [echo default])
1029 dnl Add --force so autom4te doesn't think `script' is still up to date.
1030 AT_CHECK_M4SH([--force])
1031 AT_CHECK([$CONFIG_SHELL ./script 1], [0], [[1
1036 AT_CHECK([$CONFIG_SHELL ./script limit], [0], [limit
1037 limit
1038 limit
1039 limit
1041 AT_CHECK([$CONFIG_SHELL ./script default], [0], [[default
1042 default
1044 m4_popdef([limit])
1046 AT_CLEANUP
1049 ## -------- ##
1050 ## AS_FOR.  ##
1051 ## -------- ##
1053 AT_SETUP([AS@&t@_FOR])
1054 AT_KEYWORDS([m4sh])
1056 AT_DATA_M4SH([script.as], [[dnl
1057 AS_INIT
1059 # Simple checks.
1060 AS_FOR([m4var], [shvar], [a],
1061 [echo "m4var $shvar"])
1062 AS_FOR([m4var], [shvar], [b c],
1063 [echo "m4var $shvar"])
1064 list='d e'
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], ['$list'],
1070 [echo "m4var $shvar"])
1071 AS_FOR([m4var], [shvar], [\'],
1072 [echo "m4var $shvar"])
1074 # Syntax checks: cope with empty/blank arguments.
1075 set f g
1076 AS_FOR([], [shvar], [],
1077 [echo "m4_defn([]) $shvar"])
1078 rm -f file
1079 AS_FOR([], [shvar], [`touch file`])
1080 test -f file || exit 1
1081 AS_FOR([], [shvar], [], [ ])
1082 m4_define([empty])AS_FOR([], [shvar], [], [empty])
1084 # Check that break works.
1085 while :
1087   AS_FOR([m4var], [shvar], [h i],
1088     [echo "m4var"; break 2])
1089   exit 1
1090 done
1091 while :
1093   AS_FOR([m4var], [shvar], [j],
1094     [echo "m4var"; break 2])
1095   exit 1
1096 done
1099 AT_CHECK_M4SH
1100 AT_CHECK([$CONFIG_SHELL ./script], [0], [[a a
1101 b b
1102 c c
1103 d d
1104 e e
1105 d e d e
1106 $list $list
1107 ' '
1108 f f
1109 g g
1114 AT_CLEANUP
1117 ## --------------- ##
1118 ## AS_LITERAL_IF.  ##
1119 ## --------------- ##
1121 AT_SETUP([AS@&t@_LITERAL_IF])
1122 AT_KEYWORDS([m4sh AS@&t@_LITERAL_WORD_IF AS@&t@_LITERAL_HEREDOC_IF])
1124 AT_DATA_M4SH([script.as], [[dnl
1125 AS_INIT
1126 echo AS_LITERAL_IF([lit], [ok], [ERR]) 1
1127 echo AS_LITERAL_IF([l-/.it], [ok], [ERR]) 2
1128 echo AS_LITERAL_IF([l''it], [ERR], [ok]) 3
1129 echo AS_LITERAL_IF([l$it], [ERR], [ok]) 4
1130 echo AS_LITERAL_IF([l$it], [ERR1], [ERR2], [ok]) 5
1131 echo AS_LITERAL_IF([l${it}], [ERR1], [ERR2], [ok]) 6
1132 echo AS_LITERAL_IF([l`case a in b) ;; esac`it], [ERR], [ok]) 7
1133 echo AS_LITERAL_IF([l`case a in b) ;; esac`it], [ERR1], [ok], [ERR2]) 8
1134 m4_define([mac], [l-/.it])
1135 echo AS_LITERAL_IF([mac], [ok], [ERR]) 9
1136 echo AS_LITERAL_IF([mac($, ``)], [ok], [ERR]) 10
1137 m4_define([mac], [l$it])
1138 echo AS_LITERAL_IF([mac], [ERR], [ok]) 11
1139 echo AS_LITERAL_IF([mac], [ERR1], [ERR2], [ok]) 12
1140 m4_define([mac], [l``it])
1141 echo AS_LITERAL_IF([mac], [ERR], [ok]) 13
1142 echo AS_LITERAL_IF([mac], [ERR1], [ok], [ERR2]) 14
1143 echo AS_LITERAL_IF([    a ][
1144 b], [ok], [ERR]) 15
1145 echo AS_LITERAL_WORD_IF([       a ][
1146 b], [ERR], [ok]) 16
1147 echo AS_LITERAL_HEREDOC_IF([    a ][
1148 b], [ok], [ERR]) 17
1149 echo AS_LITERAL_IF([(a)], [ERR], [ok]) 18
1150 echo AS_LITERAL_WORD_IF([(a)], [ERR], [ok]) 19
1151 echo AS_LITERAL_HEREDOC_IF([(a)], [ok], [ERR]) 20
1152 echo AS_LITERAL_IF([@S|@a], [ERR], [ok]) 21
1153 echo AS_LITERAL_WORD_IF([@S|@a], [ERR], [ok]) 22
1154 echo AS_LITERAL_HEREDOC_IF([@S|@a], [ERR], [ok]) 23
1157 AT_CHECK_M4SH
1158 AT_CHECK([$CONFIG_SHELL ./script], [],
1159 [[ok 1
1160 ok 2
1161 ok 3
1162 ok 4
1163 ok 5
1164 ok 6
1165 ok 7
1166 ok 8
1167 ok 9
1168 ok 10
1169 ok 11
1170 ok 12
1171 ok 13
1172 ok 14
1173 ok 15
1174 ok 16
1175 ok 17
1176 ok 18
1177 ok 19
1178 ok 20
1179 ok 21
1180 ok 22
1181 ok 23
1184 AT_CLEANUP
1187 ## --------------------- ##
1188 ## AS_TR_SH, AS_TR_CPP.  ##
1189 ## --------------------- ##
1191 AT_SETUP([AS@&t@_TR_SH and AS@&t@_TR_CPP])
1193 AT_DATA_M4SH([script.as], [[dnl
1194 AS_INIT
1195 m4_define([abc], [hI])m4_define([ABC], [Hi])
1196 m4_define([hi], [oops])m4_define([HI], [OOPS])
1197 echo AS_TR_SH(abc) AS_TR_SH(aBc) AS_TR_SH(ABC)
1198 echo AS_TR_SH([abc]) AS_TR_SH([aBc]) AS_TR_SH([ABC])
1199 echo AS_TR_SH([[abc]]) AS_TR_SH([[aBc]]) AS_TR_SH([[ABC]])
1200 echo AS_TR_CPP(abc) AS_TR_CPP(aBc) AS_TR_CPP(ABC)
1201 echo AS_TR_CPP([abc]) AS_TR_CPP([aBc]) AS_TR_CPP([ABC])
1202 echo AS_TR_CPP([[abc]]) AS_TR_CPP([[aBc]]) AS_TR_CPP([[ABC]])
1203 echo ===
1204 [var=abc vAr=aBc VAR=ABC]
1205 echo AS_TR_SH($var) AS_TR_SH($vAr) AS_TR_SH($VAR)
1206 echo AS_TR_SH([$var]) AS_TR_SH([$vAr]) AS_TR_SH([$VAR])
1207 echo AS_TR_SH([[$var]]) AS_TR_SH([[$vAr]]) AS_TR_SH([[$VAR]])
1208 echo AS_TR_CPP($var) AS_TR_CPP($vAr) AS_TR_CPP($VAR)
1209 echo AS_TR_CPP([$var]) AS_TR_CPP([$vAr]) AS_TR_CPP([$VAR])
1210 echo AS_TR_CPP([[$var]]) AS_TR_CPP([[$vAr]]) AS_TR_CPP([[$VAR]])
1211 echo ===
1212 echo AS_TR_SH(`echo abc`) AS_TR_SH(`echo aBc`) AS_TR_SH(`echo ABC`)
1213 echo AS_TR_SH([`echo abc`]) AS_TR_SH([`echo aBc`]) AS_TR_SH([`echo ABC`])
1214 echo AS_TR_SH([[`echo abc`]]) AS_TR_SH([[`echo aBc`]]) AS_TR_SH([[`echo ABC`]])
1215 echo AS_TR_CPP(`echo abc`) AS_TR_CPP(`echo aBc`) AS_TR_CPP(`echo ABC`)
1216 echo AS_TR_CPP([`echo abc`]) AS_TR_CPP([`echo aBc`]) AS_TR_CPP([`echo ABC`])
1217 echo AS_TR_CPP([[`echo abc`]]) AS_TR_CPP([[`echo aBc`]]) AS_TR_CPP([[`echo ABC`]])
1218 echo ===
1219 echo AS_TR_SH([a.b/c+*-])
1220 echo AS_TR_CPP([a.b/c+*-])
1221 var=a.b/c+*-
1222 echo AS_TR_SH([$var])
1223 echo AS_TR_CPP([$var])
1224 m4_define([macro], [a.b/c+*-])
1225 echo AS_TR_SH([macro])
1226 echo AS_TR_CPP([macro])
1229 AT_CHECK_M4SH
1230 AT_CHECK([$CONFIG_SHELL ./script], [],
1231 [[hI aBc Hi
1232 hI aBc Hi
1233 abc aBc ABC
1234 HI ABC HI
1235 HI ABC HI
1236 ABC ABC ABC
1238 abc aBc ABC
1239 abc aBc ABC
1240 abc aBc ABC
1241 ABC ABC ABC
1242 ABC ABC ABC
1243 ABC ABC ABC
1245 hI aBc Hi
1246 hI aBc Hi
1247 abc aBc ABC
1248 HI ABC HI
1249 HI ABC HI
1250 ABC ABC ABC
1252 a_b_cpp_
1253 A_B_C_P_
1254 a_b_cpp_
1255 A_B_C_P_
1256 a_b_cpp_
1257 A_B_C_P_
1260 AT_CLEANUP
1263 ## ---------- ##
1264 ## AS_VAR_*.  ##
1265 ## ---------- ##
1267 AT_SETUP([AS@&t@_VAR basics])
1268 AT_KEYWORDS([m4sh AS@&t@_VAR_COPY AS@&t@_VAR_SET AS@&t@_VAR_GET])
1269 AT_KEYWORDS([AS@&t@_VAR_TEST_SET AS@&t@_VAR_SET_IF AS@&t@_VAR_IF])
1270 AT_KEYWORDS([AS@&t@_VAR_PUSHDEF AS@&t@_VAR_POPDEF])
1272 AT_DATA_M4SH([script.as], [[dnl
1273 AS_INIT
1274  m4_define([with], [WITH])
1275 # Literals.
1276 dnl AS_VAR_SET_IF also covers AS_VAR_TEST_SET
1277 AS_VAR_SET_IF([foo], [echo oops]) && echo ok
1278 AS_VAR_SET([foo], ['\a  "weird" `value` with; $fun '\''characters
1279 ']) # 'font-lock
1280 AS_VAR_COPY([bar], [foo])
1281 AS_ECHO(["$bar-"])
1282 AS_ECHO(["AS_VAR_GET([foo])-"])
1283 AS_VAR_SET_IF([foo], [echo ok], [echo oops])
1284 AS_VAR_IF([foo], [string], [echo oops]) && echo ok
1285 AS_VAR_PUSHDEF([tmp], [foo])
1286 AS_VAR_IF([tmp], ['\a  "weird" `value` with; $fun '\''characters
1287 '], [echo ok], [echo oops]) # 'font-lock
1288 AS_VAR_POPDEF([tmp])
1289 m4_ifdef([tmp], [echo oops])
1291 # Indirects via shell vars.
1292 echo '===='
1293 num=1
1294 AS_VAR_SET_IF([foo$num], [echo oops]) && echo ok
1295 AS_VAR_SET([foo$num], ['\a  "weird" `value` with; $fun '\''characters
1296 ']) # 'font-lock
1297 AS_VAR_COPY([bar], [foo$num])
1298 num=2
1299 AS_VAR_COPY([foo$num], [bar])
1300 AS_ECHO(["$foo2-"])
1301 AS_ECHO(["AS_VAR_GET([foo$num])-"])
1302 AS_VAR_SET_IF([foo$num], [echo ok], [echo oops])
1303 AS_VAR_IF([foo$num], [string], [echo oops]) && echo ok
1304 AS_VAR_PUSHDEF([tmp], [foo$num])
1305 AS_VAR_IF([tmp], ['\a  "weird" `value` with; $fun '\''characters
1306 '], [echo ok], [echo oops]) # 'font-lock
1307 AS_VAR_POPDEF([tmp])
1308 m4_ifdef([tmp], [echo oops])
1310 # Indirects via command substitution.
1311 echo '===='
1312 AS_VAR_SET_IF([`echo foo3`], [echo oops]) && echo ok
1313 AS_VAR_SET([`echo foo3`], ['\a  "weird" `value` with; $fun '\''characters
1314 ']) # 'font-lock
1315 AS_VAR_COPY([bar], [`echo foo3`])
1316 num=2
1317 AS_VAR_COPY([`echo foo4`], [bar])
1318 AS_ECHO(["$foo4-"])
1319 AS_ECHO(["AS_VAR_GET([`echo foo4`])-"])
1320 AS_VAR_SET_IF([`echo foo4`], [echo ok], [echo oops])
1321 AS_VAR_IF([`echo foo4`], [string], [echo oops]) && echo ok
1322 AS_VAR_PUSHDEF([tmp], [`echo foo4`])
1323 AS_VAR_IF([tmp], ['\a  "weird" `value` with; $fun '\''characters
1324 '], [echo ok], [echo oops]) # 'font-lock
1325 AS_VAR_POPDEF([tmp])
1326 m4_ifdef([tmp], [echo oops])
1330 AT_CHECK_M4SH
1331 AT_CHECK([$CONFIG_SHELL ./script], [], [[ok
1332 \a  "weird" `value` WITH; $fun 'characters
1334 \a  "weird" `value` WITH; $fun 'characters
1339 ====
1341 \a  "weird" `value` WITH; $fun 'characters
1343 \a  "weird" `value` WITH; $fun 'characters-
1347 ====
1349 \a  "weird" `value` WITH; $fun 'characters
1351 \a  "weird" `value` WITH; $fun 'characters-
1357 AT_CLEANUP
1360 ## --------------- ##
1361 ## AS_VAR_APPEND.  ##
1362 ## --------------- ##
1364 AT_SETUP([AS@&t@_VAR_APPEND])
1365 AT_KEYWORDS([m4sh AS@&t@_VAR])
1367 AT_DATA_M4SH([script.as], [[dnl
1368 AS_INIT
1369 # Literals.
1370 AS_VAR_APPEND([foo], ["hello,  "])
1371 AS_VAR_APPEND([foo], [world])
1372 echo "$foo"
1373 # Indirects via shell vars.
1374 num=1
1375 AS_VAR_APPEND([foo$num], ['hello,  '])
1376 AS_VAR_APPEND([foo$num], [`echo "world"`])
1377 echo "$foo1"
1378 # Indirects via command substitution.
1379 h=hello w=',  world'
1380 AS_VAR_APPEND([`echo foo2`], [${h}])
1381 AS_VAR_APPEND([`echo foo2`], ["$w"])
1382 echo "$foo2"
1385 AT_CHECK_M4SH
1386 AT_CHECK([$CONFIG_SHELL ./script], [],
1387 [[hello,  world
1388 hello,  world
1389 hello,  world
1392 AT_CLEANUP
1395 ## -------------- ##
1396 ## AS_VAR_ARITH.  ##
1397 ## -------------- ##
1399 AT_SETUP([AS@&t@_VAR_ARITH])
1400 AT_KEYWORDS([m4sh AS@&t@_VAR])
1402 AT_DATA_M4SH([script.as], [[dnl
1403 AS_INIT
1404 # Literals.
1405 AS_VAR_ARITH([foo], [1 + 1])
1406 echo "$foo"
1407 # Indirects via shell vars.
1408 num=1
1409 AS_VAR_ARITH([foo$num], [\( 2 + 3 \) \* 4])
1410 echo "$foo1"
1411 # Indirects via command substitution.
1412 AS_VAR_ARITH([`echo foo2`], [0 + -2 + $foo1 / 2])
1413 echo "$foo2"
1416 AT_CHECK_M4SH
1417 AT_CHECK([$CONFIG_SHELL ./script], [],
1423 AT_CLEANUP
1426 ## ----------------- ##
1427 ## AS_INIT cleanup.  ##
1428 ## ----------------- ##
1430 AT_SETUP([AS@&t@_INIT cleanup])
1431 AT_KEYWORDS([m4sh m4@&t@_wrap m4@&t@_wrap_lifo])
1433 AT_DATA_M4SH([script.as], [[dnl
1434 dnl Registered before AS_INIT's cleanups
1435 m4_wrap([echo cleanup 1
1437 m4_pushdef([_AS_SHELL_FN_SPY])dnl neutralize the spy, we don't care about it
1438 AS_INIT
1439 dnl Registered after AS_INIT's cleanups, thus goes to KILL diversion
1440 m4_wrap([echo cleanup 2
1441 dnl However, nested wraps and diversions can still be used
1442 dnl Also, test wrapping text that looks like parameter reference
1443 m4_wrap([echo cleanup 3
1444 m4_divert_text([M4SH-INIT], [m4_define([foo], [$1])dnl
1445 echo prep foo([4])
1446 ])])])
1447 dnl Registered before AS_INIT's cleanups
1448 m4_wrap_lifo([echo cleanup 5
1450 echo body
1453 AT_CHECK_M4SH
1454 AT_CHECK([$CONFIG_SHELL ./script], [], [[prep 4
1455 body
1456 cleanup 5
1457 cleanup 1
1460 AT_CLEANUP
1463 ## ------------------- ##
1464 ## AS_INIT_GENERATED.  ##
1465 ## ------------------- ##
1467 AT_SETUP([AS@&t@_INIT_GENERATED])
1468 AT_KEYWORDS([AS@&t@_MESSAGE AS@&t@_MESSAGE_LOG_FD])
1470 dnl First run, no logging, tests shell selection
1471 AT_DATA_M4SH([script.as], [[dnl
1472 AS_INIT
1473 AS_INIT_GENERATED([child], [echo hello from child])
1474 cat >>child <<\EOF
1475 AS_ECHO(["SHELL=$SHELL"])
1477 echo hello from parent
1478 AS_ECHO(["SHELL=$SHELL"])
1481 AT_CHECK_M4SH
1482 AT_CHECK([$CONFIG_SHELL ./script], [0], [stdout])
1483 AT_CHECK([grep 'SHELL=.' stdout], [0], [ignore])
1484 sed s/parent/child/ <stdout >expout
1485 AT_CHECK([./child], [0], [expout])
1486 SHELL=/bogus
1487 export SHELL
1488 cp stdout expout
1489 mv child child.bak
1490 AT_CHECK([$CONFIG_SHELL ./script], [0], [expout])
1491 AT_CHECK([cmp child child.bak])
1492 AT_CHECK([grep 'SHELL=.' stdout], [0], [ignore])
1493 sed s/parent/child/ <stdout >expout
1494 AT_CHECK([./child], [0], [expout])
1497 dnl Second run, with logging from parent and child, tests fd handling
1498 AT_DATA_M4SH([script.as], [[dnl
1499 AS_INIT
1500 child=${1-child}
1501 m4_define([AS_MESSAGE_LOG_FD], [5])
1502 exec AS_MESSAGE_LOG_FD>log
1503 AS_INIT_GENERATED([$child], [echo hello1 from $child]) || AS_EXIT([1])
1504 cat >>$child <<\EOF
1505 m4_pushdef([AS_MESSAGE_LOG_FD])
1506 AS_MESSAGE([hello2 from ${child}child])
1507 m4_popdef([AS_MESSAGE_LOG_FD])
1508 exec AS_MESSAGE_LOG_FD>>log
1509 AS_MESSAGE([hello3 from child])
1511 AS_MESSAGE([hello from parent])
1512 dnl close log in parent before spawning child, for mingw
1513 exec AS_MESSAGE_LOG_FD>&-
1514 ./$child
1517 rm -f script
1518 AT_CHECK_M4SH
1519 AT_CHECK([$CONFIG_SHELL ./script], [0], [[script: hello from parent
1520 hello1 from child
1521 child: hello2 from child
1522 child: hello3 from child
1524 AT_CHECK([[sed 's,:[0-9][0-9]*:,:0:,' log]], [0],
1525 [[script:0: hello from parent
1526 child:0: hello3 from child
1529 # Force write error creating a file on stdout
1530 if test -w /dev/full && test -c /dev/full; then
1531   AT_CHECK([$CONFIG_SHELL ./script /dev/full], [1], [ignore], [ignore])
1534 AT_CLEANUP
1537 ## --------------- ##
1538 ## AS_MESSAGE_FD.  ##
1539 ## --------------- ##
1541 AT_SETUP([AS@&t@_MESSAGE_FD])
1542 AT_KEYWORDS([AS@&t@_MESSAGE AS@&t@_MESSAGE_LOG_FD AS@&t_ORIGINAL_STDIN_FD])
1543 AT_KEYWORDS([AS@&t@_LINENO_PUSH])
1545 AT_DATA_M4SH([script.as], [[dnl
1546 AS_INIT
1547 m4_define([AS_ORIGINAL_STDIN_FD], [5])
1548 m4_define([AS_MESSAGE_LOG_FD], [6])
1549 m4_define([AS_MESSAGE_FD], [7])
1550 exec AS_ORIGINAL_STDIN_FD<&0 </dev/null AS_MESSAGE_LOG_FD>log
1551 if test $[#] -gt 0; then
1552   exec AS_MESSAGE_FD>/dev/null
1553 else
1554   exec AS_MESSAGE_FD>&1
1556 AS_LINENO_PUSH([100])
1557 cat # tests that stdin is neutralized
1558 AS_MESSAGE([hello world])
1559 cat <&AS_ORIGINAL_STDIN_FD
1562 AT_CHECK_M4SH
1563 AT_CHECK([echo goodbye | $CONFIG_SHELL ./script], [0],
1564 [[script: hello world
1565 goodbye
1567 AT_CHECK([cat log], [0],
1568 [[script:100: hello world
1570 rm log
1571 AT_CHECK([echo goodbye | $CONFIG_SHELL ./script silent], [0],
1572 [[goodbye
1574 AT_CHECK([cat log], [0],
1575 [[script:100: hello world
1578 AT_CLEANUP
1581 ## --------------- ##
1582 ## _AS_CLEAN_DIR.  ##
1583 ## --------------- ##
1585 AT_SETUP([_AS@&t@_CLEAN_DIR])
1587 dnl ensure that we can erase all files in a directory.  Note that
1588 dnl _AS_CLEAN_DIR needs three globs to catch all these files.
1589 AT_DATA_M4SH([script.as], [[dnl
1590 AS_INIT
1591 # Unwritable subdirectories are common during 'make distcheck'.
1592 mkdir sub sub/unwritable || AS_ERROR([failed to mkdir])
1593 touch sub/unwritable/file || AS_ERROR([failed to touch])
1594 chmod a-wx sub/unwritable || AS_ERROR([failed to chmod])
1595 # Cygwin 1.5 can't touch 'sub/...', so make that file optional.
1596 touch sub/a sub/aa sub/aaa sub/.a sub/..a sub/.aa \
1597   || AS_ERROR([failed to touch])
1598 touch sub/... 2>/dev/null
1599 _AS_CLEAN_DIR([sub]) || AS_ERROR([failed to clean])
1600 # rmdir instead of 'rm -fr' here proves that we emptied sub.
1601 rmdir sub || AS_ERROR([failed to rmdir])
1604 AT_CHECK_M4SH
1605 AT_CHECK([$CONFIG_SHELL ./script])
1607 AT_CLEANUP
1610 ## -------- ##
1611 ## ECHO_C.  ##
1612 ## -------- ##
1614 AT_SETUP([ECHO_C])
1616 AT_DATA_M4SH([script.as], [[dnl
1617 AS_INIT
1618 _AS_PREPARE
1619 foo=`echo foobar`
1620 echo "$foo"
1623 AT_CHECK_M4SH
1624 AT_CHECK([$CONFIG_SHELL ./script], [], [foobar
1627 AT_CLEANUP