Improve AC_FUNC_MMAP comments
[autoconf.git] / tests / m4sh.at
blob66a8159962241cd12e4e9a3c4e2257111073eab6
1 #                                                       -*- Autotest -*-
3 AT_BANNER([M4sh.])
5 # Copyright (C) 2000-2017, 2020-2023 Free Software Foundation, Inc.
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program.  If not, see <https://www.gnu.org/licenses/>.
20 ## --------------------------- ##
21 ## Re-exec with CONFIG_SHELL.  ##
22 ## --------------------------- ##
24 AT_SETUP([No extra re-exec with CONFIG_SHELL])
25 AT_KEYWORDS([CONFIG_SHELL])
26 AT_DATA_M4SH([script.as],
28 dnl We have to muck with internal details to goad the script into
29 dnl thinking that the default shell is always good enough.
30 m4_define([_AS_DETECT_REQUIRED_BODY], [])dnl
31 m4_define([_AS_DETECT_SUGGESTED_BODY], [])dnl
32 AS_INIT
33 echo foo > ok
34 ]])
35 AT_CHECK_M4SH
36 AT_CHECK([CONFIG_SHELL=/bin/false ./script], [0], [], [])
37 AT_CHECK([test -f ok], [0])
38 rm -f ok
40 AT_CLEANUP
42 AT_SETUP([Forced re-exec with CONFIG_SHELL])
43 AT_KEYWORDS([CONFIG_SHELL])
45 AT_DATA_M4SH([script.as],
46 [[m4_define([_AS_FORCE_REEXEC_WITH_CONFIG_SHELL], [yes])
47 AS_INIT
48 echo foo > sentinel
49 ]])
50 AT_CHECK_M4SH
52 # Calling the script simply 'script' could cause problems with
53 # Solaris /usr/xpg4/bin/sh in the invocation 'sh script' below.
54 mv -f script script2
56 AT_DATA([fake-shell],
57 [[#!/bin/sh
58 echo 'Fake shell executed.'
59 shift # fake shell
60 echo "nargs = @S|@#"
61 for i
63   printf ' :%s:\n' "$i"
64 done
65 ]])
66 chmod a+x fake-shell
68 AT_CHECK([CONFIG_SHELL=./fake-shell ./script2 1 2 4 8], [0],
69 [Fake shell executed.
70 nargs = 4
71  :1:
72  :2:
73  :4:
74  :8:
75 ], [])
76 AT_CHECK([test ! -f sentinel], [0])
77 test ! -f sentinel || rm -f sentinel # Cleanup for next test.
79 AT_CHECK(
80 [CONFIG_SHELL=`pwd`/fake-shell sh script2 a 'b  c' '  d    e '],
81 [0],
82 [Fake shell executed.
83 nargs = 3
84  :a:
85  :b  c:
86  :  d      e :
87 ], [])
88 AT_CHECK([test ! -f sentinel], [0])
89 test ! -f sentinel || rm -f sentinel # Cleanup for next test.
91 AT_CHECK([(PATH=`pwd`:$PATH; export PATH;
92 CONFIG_SHELL=fake-shell script2 '' '&' '!;*' '<($[]@%:@)>,' 'x
93 y  z
94 1 2 3')], [0],
95 [Fake shell executed.
96 nargs = 5
97  ::
98  :&:
99  :!;*:
100  :<($[]@%:@)>,:
101  :x
102 y  z
103 1 2 3:
104 ], [])
105 AT_CHECK([test ! -f sentinel], [0])
106 test ! -f sentinel || rm -f sentinel # Cleanup for next test.
108 AT_CLEANUP
110 AT_SETUP([Configure re-execs self with CONFIG_SHELL])
112 AT_DATA([configure.ac],
113 [[AC_INIT
114 echo foobar >> quux
115 AC_OUTPUT
118 AT_CHECK_AUTOCONF
120 AT_DATA([cfg-sh],
121 [[#!/bin/sh
122 : > cfg-sh-has-run
123 exec sh "@S|@@"
125 chmod a+x cfg-sh
127 AT_CAPTURE_FILE([config.log])
128 AT_CHECK([env CONFIG_SHELL=./cfg-sh ./configure],
129          [0],
130 [[configure: creating ./config.status
131 ]], [])
132 # ./configure re-executed itself.
133 AT_CHECK([test -f cfg-sh-has-run], [0])
134 # And did that not to cause extra execution of later commands.
135 AT_CHECK([cat quux], [0], [foobar
136 ], [])
138 rm -f quux cfg-sh*
139 AT_CLEANUP
142 ## ------------------- ##
143 ## AS_WARN, AS_ERROR.  ##
144 ## ------------------- ##
146 AT_SETUP([AS@&t@_WARN and AS@&t@_ERROR])
147 AT_KEYWORDS([m4sh])
149 dnl without logging
150 AT_DATA_M4SH([script.as],
151 [[AS_INIT
152 AS_WARN([*watch out*])dnl
154 if test x"$die" != x; then
155   AS_ERROR([you're dead])dnl
157   AS_ERROR([really])dnl
160 echo got here
163 AT_CHECK_M4SH
164 AT_CHECK([$CONFIG_SHELL ./script], [],
165 [[got here
166 ]], [[script: WARNING: *watch out*
168 AT_CHECK([die=: $CONFIG_SHELL ./script], [1],
169 [], [[script: WARNING: *watch out*
170 script: error: you're dead
173 dnl with logging
174 rm script
175 AT_DATA_M4SH([script.as],
176 [[AS_INIT
177 m4_define([gone], [AS_ERROR([really])])
178 m4_define([AS_MESSAGE_LOG_FD], [5])
179 exec AS_MESSAGE_LOG_FD>log.txt
180 AS_WARN([*watch out*])dnl
182 if test x"$die" != x; then
183   AS_ERROR([you're dead])dnl
185   AS_ERROR([really])dnl
188 echo got here
189 exec AS_MESSAGE_LOG_FD>&-
192 AT_CHECK_M4SH
193 AT_CHECK([$CONFIG_SHELL ./script], [],
194 [[got here
195 ]], [[script: WARNING: *watch out*
197 AT_CHECK([[grep 'script:[0-9]*: WARNING: \*watch out\*' log.txt]], [], [ignore])
198 AT_CHECK([die=: $CONFIG_SHELL ./script], [1],
199 [], [[script: WARNING: *watch out*
200 script: error: you're dead
202 AT_CHECK([[grep 'script:[0-9]*: WARNING: \*watch out\*' log.txt]], [], [ignore])
203 AT_CHECK([[grep 'script:[0-9]*: error: you'\''re dead' log.txt]], [], [ignore])
205 AT_CLEANUP
207 ## ---------------- ##
208 ## LINENO support.  ##
209 ## ---------------- ##
211 AT_SETUP([LINENO])
212 AT_KEYWORDS([m4sh])
214 # We cannot unset LINENO with Zsh, yet this test case relies on
215 # unsetting LINENO to compare its result when (i) LINENO is supported
216 # and when (ii) it is not.
217 # So just skip if the shell is ZSH.
218 AT_CHECK([test ${ZSH_VERSION+y} && exit 77], ignore)
220 # AT_DATA_LINENO(FILE-NAME,
221 #                UNSET-LINENO = true | false, COUNTER, COUNTER-RE)
222 # ----------------------------------------------------------------
223 # Produce the FILE-NAME M4sh script which uses the COUNTER LINENO or
224 # _oline_, which we can recognized via COUNTER-RE.  Unset LINENO is
225 # UNSET-LINENO.
227 # Use COUNTER, COUNTER-RE = [__LINENO__], [LINENO]
228 #  or                     = [__OLINE__],  [_oline__]
230 # instead of the obvious $LINENO and __oline@&t@__, because they would
231 # be replaced in the test suite itself, even before creating these
232 # scripts.  For the same reason, grep for LINENO and _oline__ (sic).
234 # UNSET-LINENO is a shell condition to make sure the scripts have the
235 # same number of lines in the output, so that their outputs be identical.
236 m4_define([AT_DATA_LINENO],
237 [AT_DATA([$1.tas],
238 [[AS@&t@_INIT
239 m4@&t@_divert_text([], [
240 if $2; then
241   AS@&t@_UNSET([LINENO])
244 AS@&t@_LINENO_PREPARE
245 echo "Line: $3"
246 grep 'Line: .*$4' "$[0]" >/dev/null ||
247   AS@&t@_ERROR([cannot find original script])
248 exit 0
250 # If occurrences of $LINENO or __@&t@oline__ were wanted, create them.
251 sed 's/__LINENO__/$''LINENO/g;s/__OLINE__/__''oline__/g' $1.tas >$1.as
252 AT_CHECK([autom4te -l m4sh $1.as -o $1])
253 ])# AT_DATA_LINENO
255 # '_oline_', once processed and ran, produces our reference.
256 # We check that we find ourselves by looking at a string which is
257 # available only in the original script: '_oline_'.
258 AT_DATA_LINENO([reference], [true], [__OLINE__], [_oline__])
259 AT_CHECK([./reference], 0, [stdout])
261 # The reference:
262 mv stdout expout
264 # Now using a maybe-functioning LINENO, with different call conventions.
265 # Be sure to be out of the PATH.
266 AT_CHECK([mkdir test || exit 77])
268 AT_DATA_LINENO([test/test-1], [true], [__LINENO__], [LINENO])
269 AT_CHECK([./test/test-1],                          0, [expout])
270 AT_CHECK([(PATH=test$PATH_SEPARATOR$PATH; export PATH; exec test-1)],
271                                                    0, [expout])
272 AT_CHECK([sh ./test/test-1],                       0, [expout])
274 # Now using a disabled LINENO, with different call conventions.
275 AT_DATA_LINENO([test/test-2], [true], [__LINENO__], [LINENO])
276 AT_CHECK([./test/test-2],                          0, [expout])
277 AT_CHECK([(PATH=test$PATH_SEPARATOR$PATH; export PATH; exec test-2)],
278                                                    0, [expout])
279 AT_CHECK([sh ./test/test-2],                       0, [expout])
281 AT_CLEANUP
284 ## ---------------------- ##
285 ## LINENO stack support.  ##
286 ## ---------------------- ##
288 AT_SETUP([LINENO stack])
289 AT_KEYWORDS([m4sh])
291 AT_DATA_M4SH([script.as],
292 [[AS_INIT
294 AS_LINENO_PUSH([9999])
295 test $as_lineno = 9999 || AS_ERROR([bad as_lineno at depth 1])
296 AS_LINENO_PUSH([8888])
297 test $as_lineno = 9999 || AS_ERROR([bad as_lineno at depth 2])
298 AS_LINENO_POP
299 test $as_lineno = 9999 || AS_ERROR([bad as_lineno at depth 1])
300 AS_LINENO_POP
301 test ${as_lineno+y} && AS_ERROR([as_lineno set at depth 0])
303 AS_EXIT([0])
306 AT_CHECK_M4SH
307 AT_CHECK([$CONFIG_SHELL ./script])
309 AT_CLEANUP
312 ## -------- ##
313 ## AS_BOX.  ##
314 ## -------- ##
316 # Output a framed one-line message.
317 AT_SETUP([AS@&t@_BOX])
318 AT_KEYWORDS([m4sh])
320 AT_DATA_M4SH([script.as],
321 [[AS_INIT
322 echo
323 AS_BOX([Send a simple message, to foobar@example.com])
324 AS_BOX([Send a simple message, to foobar@example.com], [$])
325 m4_define([msg], [$complex])
326 complex='Not quite as simple |$[1]'
327 AS_BOX([msg])
328 AS_BOX([msg], [,])
329 AS_EXIT(0)
332 AT_CHECK_M4SH
333 AT_CHECK([sed -n '/ -\{44\} /,/ -\{44\} /p' script ]dnl
334 [| sed '1 s/.*## -/## -/; 3 s/- ##.*/- ##/'], [],
335 [[## -------------------------------------------- ##
336 ## Send a simple message, to foobar@example.com ##
337 ## -------------------------------------------- ##
340 AT_CHECK([$CONFIG_SHELL ./script], [], [[
341 ## -------------------------------------------- ##
342 ## Send a simple message, to foobar@example.com ##
343 ## -------------------------------------------- ##
344 ## $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ ##
345 ## Send a simple message, to foobar@example.com ##
346 ## $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ ##
347 ## ----------------------- ##
348 ## Not quite as simple |$1 ##
349 ## ----------------------- ##
350 ## ,,,,,,,,,,,,,,,,,,,,,,, ##
351 ## Not quite as simple |$1 ##
352 ## ,,,,,,,,,,,,,,,,,,,,,,, ##
355 AT_CLEANUP
358 # Strip path from file.
359 AT_SETUP([AS@&t@_BASENAME])
360 AT_KEYWORDS([m4sh])
362 AT_DATA_M4SH([script.as],
363 [[AS_INIT
365 m4_define([BASENAME_TEST],
366 [base=`AS_BASENAME([$1])`
367 test "$base" = "$2" ||
368   echo "basename($1) = $base instead of $2" >&2
370 base=`_AS_BASENAME_SED([$1])`
371 test "$base" = "$2" ||
372   echo "basename_sed($1) = $base instead of $2" >&2])
374 BASENAME_TEST([//1],             [1])
375 BASENAME_TEST([/1],              [1])
376 BASENAME_TEST([./1],             [1])
377 BASENAME_TEST([../../2],         [2])
378 BASENAME_TEST([//1/],            [1])
379 BASENAME_TEST([/1/],             [1])
380 BASENAME_TEST([./1/],            [1])
381 BASENAME_TEST([../../2],         [2])
382 BASENAME_TEST([//1/3],           [3])
383 BASENAME_TEST([/1/3],            [3])
384 BASENAME_TEST([./1/3],           [3])
385 BASENAME_TEST([../../2/3],       [3])
386 BASENAME_TEST([//1/3///],        [3])
387 BASENAME_TEST([/1/3///],         [3])
388 BASENAME_TEST([./1/3///],        [3])
389 BASENAME_TEST([../../2/3///],    [3])
390 BASENAME_TEST([//1//3/],         [3])
391 BASENAME_TEST([/1//3/],          [3])
392 BASENAME_TEST([./1//3/],         [3])
393 BASENAME_TEST([a.c],             [a.c])
394 BASENAME_TEST([a.c/],            [a.c])
395 BASENAME_TEST([/a.c/],           [a.c])
396 BASENAME_TEST([/1/a.c],          [a.c])
397 BASENAME_TEST([/1/a.c/],         [a.c])
398 BASENAME_TEST([/1/../a.c],       [a.c])
399 BASENAME_TEST([/1/../a.c/],      [a.c])
400 BASENAME_TEST([./1/a.c],         [a.c])
401 BASENAME_TEST([./1/a.c/],        [a.c])
402 AS_EXIT(0)
405 AT_CHECK_M4SH
406 AT_CHECK([$CONFIG_SHELL ./script])
408 AT_CLEANUP
411 ## ------------ ##
412 ## AS_DIRNAME.  ##
413 ## ------------ ##
415 # Strip filename component.
416 AT_SETUP([AS@&t@_DIRNAME])
417 AT_KEYWORDS([m4sh])
419 AT_DATA_M4SH([script.as],
420 [[AS_INIT
422 # The EXPR variant is allowed to fail if 'expr' was considered as too
423 # weak for us, in which case 'as_expr=false'.
424 m4_define([DIRNAME_TEST],
425 [dir=`AS_DIRNAME([$1])`
426 test "$dir" = "$2" || (test -n "$3" && test "$dir" = "$3") ||
427   echo "dirname($1) = $dir instead of $2" >&2
429 if test "$as_expr" != false; then
430   dir=`_AS_DIRNAME_EXPR([$1])`
431   test "$dir" = "$2" || (test -n "$3" && test "$dir" = "$3") ||
432     echo "dirname_expr($1) = $dir instead of $2" >&2
435 dir=`_AS_DIRNAME_SED([$1])`
436 test "$dir" = "$2" || (test -n "$3" && test "$dir" = "$3") ||
437   echo "dirname_sed($1) = $dir instead of $2" >&2])
439 DIRNAME_TEST([/],               [/])
440 DIRNAME_TEST([//],              [//],   [/])
441 DIRNAME_TEST([///],             [/])
442 DIRNAME_TEST([//1],             [//],   [/])
443 DIRNAME_TEST([/1],              [/])
444 DIRNAME_TEST([./1],             [.])
445 DIRNAME_TEST([../../2],         [../..])
446 DIRNAME_TEST([//1/],            [//],   [/])
447 DIRNAME_TEST([/1/],             [/])
448 DIRNAME_TEST([./1/],            [.])
449 DIRNAME_TEST([../../2],         [../..])
450 DIRNAME_TEST([//1/3],           [//1])
451 DIRNAME_TEST([/1/3],            [/1])
452 DIRNAME_TEST([./1/3],           [./1])
453 DIRNAME_TEST([../../2/3],       [../../2])
454 DIRNAME_TEST([//1/3///],        [//1])
455 DIRNAME_TEST([/1/3///],         [/1])
456 DIRNAME_TEST([./1/3///],        [./1])
457 DIRNAME_TEST([../../2/3///],    [../../2])
458 DIRNAME_TEST([//1//3/],         [//1])
459 DIRNAME_TEST([/1//3/],          [/1])
460 DIRNAME_TEST([./1//3/],         [./1])
461 DIRNAME_TEST([../../2//3/],     [../../2])
462 AS_EXIT(0)
465 AT_CHECK_M4SH
466 AT_CHECK([$CONFIG_SHELL ./script])
468 AT_CLEANUP
471 ## ---------------- ##
472 ## AS_SET_CATFILE.  ##
473 ## ---------------- ##
475 AT_SETUP([AS@&t@_SET_CATFILE])
476 AT_KEYWORDS([m4sh])
478 AT_DATA_M4SH([script.as],
479 [[AS_INIT
481 # CATFILE_TEST(DIR, FILE, EXPECTED)
482 m4_define([CATFILE_TEST],
483 [# AS_SET_CATFILE works and can be used in a compound list.
484 if AS_SET_CATFILE([var], [$1], [$2]) \
485    && test "$var" = $3; then :; else
486   echo "catfile($1, $2) = $var != $3" >&2
488 # AS_SET_CATFILE can use non-literals in its arguments.
489 varname=var2
490 dirpart=$1
491 filepart=$2
492 if AS_SET_CATFILE([$varname], [$dirpart], [$filepart]) \
493    && test "$var2" = $3; then :; else
494   echo "catfile($dirpart, $filepart) = $var2 != $3" >&2
498 CATFILE_TEST([dir], [file], [dir/file])
499 CATFILE_TEST([.], [file], [file])
500 CATFILE_TEST([dir], [.], [dir])
501 CATFILE_TEST([dir], [/abs/file], [/abs/file])
502 CATFILE_TEST([dir], [C:/abs/file], [C:/abs/file])
503 CATFILE_TEST(["dir  name"], ['file  name'], ['dir  name/file  name'])
505 AS_EXIT(0)
508 AT_CHECK_M4SH
509 AT_CHECK([$CONFIG_SHELL ./script])
511 AT_CLEANUP
514 ## --------- ##
515 ## AS_ECHO.  ##
516 ## --------- ##
518 # Print literal strings, with/without newline.
519 AT_SETUP([AS@&t@_ECHO and AS@&t@_ECHO_N])
520 AT_KEYWORDS([m4sh])
522 AT_DATA_M4SH([script.as],
523 [[AS_INIT
525 m4_define([ECHO_TEST],
526 [echo=`AS_ECHO(['$1'])`
527 test "X$echo" = 'X$1' ||
528   echo "AS@&t@_ECHO('"'$1'"') outputs '$echo'" >&2
530 echo=`AS_ECHO_N(['$1'])`
531 test "X$echo" = 'X$1' ||
532   echo "AS@&t@_ECHO_N('"'$1'"') outputs '$echo'" >&2])
534 ECHO_TEST([-])
535 ECHO_TEST([--])
536 ECHO_TEST([---...---])
537 ECHO_TEST([      ])
538 ECHO_TEST([-e])
539 ECHO_TEST([-E])
540 ECHO_TEST([-n])
541 ECHO_TEST([-n -n])
542 ECHO_TEST([-e -n])
543 ECHO_TEST([ab\ncd])
544 ECHO_TEST([abcd\c])
545 ECHO_TEST([\a\b\c\f\n\r\t\v\"\])
546 ECHO_TEST([ab
549 ECHO_TEST([
550  ])
551 ECHO_TEST([
552 \c])
553 AS_EXIT(0)
556 AT_CHECK_M4SH
557 AT_CHECK([$CONFIG_SHELL ./script])
559 AT_CLEANUP
561 # Obsolete shell variables with the same functionality as above.
562 AT_SETUP([obsolete $as@&t@_echo and $as@&t@_echo_n])
563 AT_KEYWORDS([m4sh])
565 AT_DATA_M4SH([script.as],
566 [[AS_INIT
567 AS_REQUIRE([_AS_ECHO_N_PREPARE])
569 m4_define([ECHO_TEST],
570 [echo=`$as_echo '$1'`
571 test "X$echo" = 'X$1' ||
572   echo "\$as@&t@_echo '$1' outputs '$echo'" >&2
574 echo=`$as_echo_n '$1'`
575 test "X$echo" = 'X$1' ||
576   echo "\$as@&t@_echo_n '$1' outputs '$echo'" >&2])
578 ECHO_TEST([-])
579 ECHO_TEST([--])
580 ECHO_TEST([---...---])
581 ECHO_TEST([      ])
582 ECHO_TEST([-e])
583 ECHO_TEST([-E])
584 ECHO_TEST([-n])
585 ECHO_TEST([-n -n])
586 ECHO_TEST([-e -n])
587 ECHO_TEST([ab\ncd])
588 ECHO_TEST([abcd\c])
589 ECHO_TEST([\a\b\c\f\n\r\t\v\"\])
590 ECHO_TEST([ab
593 ECHO_TEST([
594  ])
595 ECHO_TEST([
596 \c])
597 AS_EXIT(0)
600 AT_CHECK_M4SH([], 0, [],
601 [[script.as:13: warning: $as@&t@_echo is obsolete; use AS@&t@_ECHO(["message"]) instead
602 script.as:13: warning: $as@&t@_echo_n is obsolete; use AS@&t@_ECHO_N(["message"]) instead
603 script.as:14: warning: $as@&t@_echo is obsolete; use AS@&t@_ECHO(["message"]) instead
604 script.as:14: warning: $as@&t@_echo_n is obsolete; use AS@&t@_ECHO_N(["message"]) instead
605 script.as:15: warning: $as@&t@_echo is obsolete; use AS@&t@_ECHO(["message"]) instead
606 script.as:15: warning: $as@&t@_echo_n is obsolete; use AS@&t@_ECHO_N(["message"]) instead
607 script.as:16: warning: $as@&t@_echo is obsolete; use AS@&t@_ECHO(["message"]) instead
608 script.as:16: warning: $as@&t@_echo_n is obsolete; use AS@&t@_ECHO_N(["message"]) instead
609 script.as:17: warning: $as@&t@_echo is obsolete; use AS@&t@_ECHO(["message"]) instead
610 script.as:17: warning: $as@&t@_echo_n is obsolete; use AS@&t@_ECHO_N(["message"]) instead
611 script.as:18: warning: $as@&t@_echo is obsolete; use AS@&t@_ECHO(["message"]) instead
612 script.as:18: warning: $as@&t@_echo_n is obsolete; use AS@&t@_ECHO_N(["message"]) instead
613 script.as:19: warning: $as@&t@_echo is obsolete; use AS@&t@_ECHO(["message"]) instead
614 script.as:19: warning: $as@&t@_echo_n is obsolete; use AS@&t@_ECHO_N(["message"]) instead
615 script.as:20: warning: $as@&t@_echo is obsolete; use AS@&t@_ECHO(["message"]) instead
616 script.as:20: warning: $as@&t@_echo_n is obsolete; use AS@&t@_ECHO_N(["message"]) instead
617 script.as:21: warning: $as@&t@_echo is obsolete; use AS@&t@_ECHO(["message"]) instead
618 script.as:21: warning: $as@&t@_echo_n is obsolete; use AS@&t@_ECHO_N(["message"]) instead
619 script.as:22: warning: $as@&t@_echo is obsolete; use AS@&t@_ECHO(["message"]) instead
620 script.as:22: warning: $as@&t@_echo_n is obsolete; use AS@&t@_ECHO_N(["message"]) instead
621 script.as:23: warning: $as@&t@_echo is obsolete; use AS@&t@_ECHO(["message"]) instead
622 script.as:23: warning: $as@&t@_echo_n is obsolete; use AS@&t@_ECHO_N(["message"]) instead
623 script.as:24: warning: $as@&t@_echo is obsolete; use AS@&t@_ECHO(["message"]) instead
624 script.as:24: warning: $as@&t@_echo_n is obsolete; use AS@&t@_ECHO_N(["message"]) instead
625 script.as:25: warning: $as@&t@_echo is obsolete; use AS@&t@_ECHO(["message"]) instead
626 script.as:25: warning: $as@&t@_echo_n is obsolete; use AS@&t@_ECHO_N(["message"]) instead
627 script.as:28: warning: $as@&t@_echo is obsolete; use AS@&t@_ECHO(["message"]) instead
628 script.as:28: warning: $as@&t@_echo_n is obsolete; use AS@&t@_ECHO_N(["message"]) instead
629 script.as:30: warning: $as@&t@_echo is obsolete; use AS@&t@_ECHO(["message"]) instead
630 script.as:30: warning: $as@&t@_echo_n is obsolete; use AS@&t@_ECHO_N(["message"]) instead
632 AT_CHECK([$CONFIG_SHELL ./script])
634 AT_CLEANUP
637 ## ------------------------------ ##
638 ## Redefining AS_ECHO internals.  ##
639 ## ------------------------------ ##
641 AT_SETUP([Redefining AS@&t@_ECHO internals])
643 # None of the tests below do any AC_DEFINEs, so running autoheader is
644 # a waste of time, but the skeleton generated by AT_CONFIGURE_AC needs
645 # this file to exist anyway.
646 AT_DATA([config.hin])
648 # Defining a macro named 's' or 'n' should not affect AS_ECHO or
649 # macros that use it.
651 AT_CONFIGURE_AC(
652 [[m4@&t@_pushdef([s], [z])
653 m4@&t@_pushdef([n], [u])
654 AC_MSG_NOTICE([checking whether m4sugar echo works... yes])
655 AC_MSG_CHECKING([whether m4sugar echo_n works])
656 AC_MSG_RESULT([yes])
657 m4@&t@_popdef([s])
658 m4@&t@_popdef([n])
661 AT_CHECK_AUTOCONF
662 AT_CHECK_CONFIGURE([], [],
663 [[configure: checking whether m4sugar echo works... yes
664 checking whether m4sugar echo_n works... yes
665 configure: creating ./config.status
666 config.status: creating config.h
667 ]], [])
668 AT_CHECK_ENV
669 rm config.h
671 # More elaborate version of the above; derived from actual code in
672 # ruby 2.7.2's configure script.
674 AT_CONFIGURE_AC(
675 [[AC@&t@_DEFUN([RUBY_CHECK_SIZEOF],[
676 AS@&t@_VAR_PUSHDEF([s], [ac_cv_sizeof_size])
677 AC@&t@_CACHE_CHECK([size of $1],
678     [AS@&t@_TR_SH([ac_cv_sizeof_$1])],
679     [AS@&t@_TR_SH(ac_cv_sizeof_$1)=1])
681 # fake use of 's' for illustrative purposes:
682 s=42
683 echo "s is defined as ${s}"
685 AS@&t@_VAR_POPDEF([s])
688 RUBY_CHECK_SIZEOF(int)
689 echo "ac_cv_sizeof_int=${ac_cv_sizeof_int}"
692 AT_CHECK_AUTOCONF
693 AT_CHECK_CONFIGURE([], [],
694 [[checking size of int... 1
695 ac_cv_sizeof_size is defined as 42
696 ac_cv_sizeof_int=1
697 configure: creating ./config.status
698 config.status: creating config.h
699 ]], [])
700 AT_CHECK_ENV
701 rm config.h
703 # However, defining a macro named 'printf' _is_ expected to affect
704 # the functioning of AS_ECHO.
706 AT_CONFIGURE_AC(
707 [[# At this point in a configure script, defining shell functions is safe.
708 fn_printf_override () {
709   for arg; do
710     printf '+ %s\n' "$arg"
711   done
712   AS@&t@_UNSET([arg])
714 m4@&t@_pushdef([printf], [fn_printf_override])
715 AC_MSG_NOTICE([checking whether m4sugar echo works... yes])
716 AC_MSG_CHECKING([whether m4sugar echo_n works])
717 AC_MSG_RESULT([yes])
718 m4@&t@_popdef([printf])
721 AT_CHECK_AUTOCONF
722 AT_CHECK_CONFIGURE([], [],
723 [[+ %s\n
724 + configure: checking whether m4sugar echo works... yes
725 + %s
726 + checking whether m4sugar echo_n works... @&t@
727 + %s\n
728 + yes
729 configure: creating ./config.status
730 config.status: creating config.h
731 ]], [])
732 AT_CHECK_ENV
734 AT_CLEANUP
737 ## ----------------- ##
738 ## AS_EXECUTABLE_P.  ##
739 ## ----------------- ##
741 # Check for executable regular files.
742 AT_SETUP([AS@&t@_EXECUTABLE_P])
743 AT_KEYWORDS([m4sh])
745 AT_DATA_M4SH([script.as],
746 [[AS_INIT
748 if AS_EXECUTABLE_P([/]); then
749   echo fail
750 else
751   echo 1
753 cat > foo.sh <<\EOF || AS_EXIT([1])
754 #!/bin/sh
755 exit 0
757 # File systems like FAT tend to fake executable permissions on all files.
758 # At this point, foo.sh should be executable iff permissions are faked.
759 AS_EXECUTABLE_P([foo.sh])
760 st1=$?
761 (./foo.sh) >/dev/null 2>&1
762 st2=$?
763 case $st1:$st2 in
764   *[[1-9]]*:*[[1-9]]* | 0:0 ) echo 2 ;;
765   *) echo "fail ($st1:$st2)" ;;
766 esac
767 # Now things better be executable
768 chmod a+x foo.sh || AS_EXIT([2])
769 mkdir 'two  spaces' || AS_EXIT([3])
770 'two  spaces'/../foo.sh || AS_EXIT([4])
771 if AS_EXECUTABLE_P(["two  spaces/../foo.sh"]); then
772   echo 3
773 else
774   echo fail
778 AT_CHECK_M4SH
779 AT_CHECK([$CONFIG_SHELL ./script], [],
785 AT_CLEANUP
789 ## --------- ##
790 ## AS_EXIT.  ##
791 ## --------- ##
793 # Exit scripts with given status.
794 AT_SETUP([AS@&t@_EXIT])
795 AT_KEYWORDS([m4sh AS@&t@_SET_STATUS])
797 AT_DATA_M4SH([script.as],
798 [[AS_INIT
799 test x${1} = xa && AS_EXIT
800 test x${1} = xb && AS_EXIT([${2}])
801 test x${1} = xc && { AS_SET_STATUS([${2}]); AS_EXIT; }
802 test x${1} = xd && trap 's=$?; echo $s; AS_EXIT([$s])' 0
803 test x${2} = xe && set -e
804 test $[#] -gt 0 || AS_EXIT
805 AS_SET_STATUS([3])
806 dnl Solaris /bin/sh 'set -e' doesn't react to failed function calls
807 test x${2} = xe \
808   && { echo 'skipping rest of test: set -e support is lousy'; exit 77; }
809 AS_SET_STATUS([4])
812 AT_CHECK_M4SH
813 AT_CHECK([$CONFIG_SHELL ./script], [1])
814 AT_CHECK([$CONFIG_SHELL ./script ''], [4])
815 AT_CHECK([$CONFIG_SHELL ./script a], [0])
816 AT_CHECK([$CONFIG_SHELL ./script b], [0])
817 AT_CHECK([$CONFIG_SHELL ./script b 0], [0])
818 AT_CHECK([$CONFIG_SHELL ./script b 2], [2])
819 AT_CHECK([$CONFIG_SHELL ./script c 0], [0])
820 AT_CHECK([$CONFIG_SHELL ./script c 2], [2])
821 AT_CHECK([$CONFIG_SHELL ./script d], [4], [[4
823 dnl If we got to this point without a FAIL, then AS_EXIT at least works.
824 dnl The rest of this test relies on semi-decent 'set -e' support, even
825 dnl though m4sh in general should not try to rely on it because of
826 dnl portability nightmares on what constructs are considered errors across
827 dnl various shells; therefore, an overall SKIP result is desirable on
828 dnl broken shells like Solaris /bin/sh.
829 AT_CHECK([$CONFIG_SHELL ./script '' e], [3])
830 AT_CHECK([$CONFIG_SHELL ./script d e], [3], [stdout])
831 dnl NetBSD sh fails to output on stderr here.
832 AT_CHECK([grep 3 stdout || exit 77], [], [ignore])
834 AT_CLEANUP
838 ## ------------ ##
839 ## AS_MKDIR_P.  ##
840 ## ------------ ##
842 # Build nested dirs.
843 AT_SETUP([AS@&t@_MKDIR_P])
844 AT_KEYWORDS([m4sh])
846 AT_DATA_M4SH([script.as],
847 [[AS_INIT
849 pwd=`pwd`
850 set -e
851 # Absolute
852 AS_MKDIR_P(["$pwd/1/2/3/4/5/6"])
853 test -d "$pwd/1/2/3/4/5/6" ||
854   AS_ERROR([$pwd/1/2/3/4/5/6 has not been properly created])
855 # Relative
856 AS_MKDIR_P(["a/b/c/d/e/f"])
857 test -d a/b/c/d/e/f ||
858   AS_ERROR([a/b/c/d/e/f has not been properly created])
859 AS_EXIT(0)
862 AT_CHECK_M4SH
863 AT_CHECK([$CONFIG_SHELL ./script])
865 AT_CLEANUP
870 ## -------------------- ##
871 ## AS_VERSION_COMPARE.  ##
872 ## -------------------- ##
874 # Three-way version comparison.
875 AT_SETUP([AS@&t@_VERSION_COMPARE])
876 AT_KEYWORDS([m4sh])
878 AT_DATA_M4SH([script.as],
879 [[AS_INIT
881 m4_define([VERSION_COMPARE_TEST],
882 [AS_VERSION_COMPARE([$1], [$3], [result='<'], [result='='], [result='>'])
883 test "X$result" = "X$2" ||
884   AS_ERROR([version $1 $result $3; should be $1 $2 $3])
885 m4_if([$1], <,
886 [AS_VERSION_COMPARE([$3], [$1], [result='<'], [result='='], [result='>'])
887 test "X$result" = "X>" ||
888   AS_ERROR([version $3 $result $1; should be $3 > $1])])])
890 VERSION_COMPARE_TEST([], =, [])
891 VERSION_COMPARE_TEST([1.0], =, [1.0])
892 VERSION_COMPARE_TEST([alpha-1.0], =, [alpha-1.0])
894 # These tests are taken from libc/string/tst-svc.expect.
895 tst_svc_expect='
896   000 001 00 00a 01 01a 0 0a 2.8 2.8-0.4 20 21 22 212 CP037 CP345 CP1257
897   foo foo-0.4 foo-0.4a foo-0.4b foo-0.5 foo-0.10.5 foo-3.01 foo-3.0
898   foo-3.0.0 foo-3.0.1 foo-3.2 foo-3.10 foo00 foo0
900 test1=''
901 for test2 in $tst_svc_expect; do
902   VERSION_COMPARE_TEST([$test1], <, [$test2])
903   test1=$test2
904 done
906 AS_EXIT(0)
909 AT_CHECK_M4SH
910 AT_CHECK([$CONFIG_SHELL ./script])
912 AT_CLEANUP
917 ## ------- ##
918 ## as_me.  ##
919 ## ------- ##
921 AT_SETUP([as_me])
922 AT_KEYWORDS([m4sh])
924 AT_DATA_M4SH([script.as],
925 [[AS_INIT
926 AS_ME_PREPARE
927 test "$as_me" = script || AS_ECHO([["incorrect value of \$as_me: $as_me"]])
930 AT_CHECK_M4SH
931 AT_CHECK([$CONFIG_SHELL ./script])
933 AT_CLEANUP
938 ## ----------------------------- ##
939 ## Negated classes in globbing.  ##
940 ## ----------------------------- ##
942 # According to https://www.in-ulm.de/~mascheck/bourne/, all shells with
943 # functions also support '[!...]'.  But '[^...]' is not universally supported.
945 AT_SETUP([Negated classes in globbing])
946 AT_KEYWORDS([m4sh])
948 AT_DATA_M4SH([script.as],
949 [[AS_INIT
951 case 'with!two!bangs' in
952   *[[!a-z]]*) ;;
953            *) AS_ERROR([['*[!a-z]*' didn't match 'with!two!bangs']]);;
954 esac
956 case without in
957   *[[!a-z]]*) AS_ERROR([['*[!a-z]*' matched 'without']]);;
958 esac
961 AT_CHECK_M4SH
962 AT_CHECK([$CONFIG_SHELL ./script])
964 AT_CLEANUP
966 ## ---------------------------- ##
967 ## Null variable substitution.  ##
968 ## ---------------------------- ##
970 # According to https://www.in-ulm.de/~mascheck/bourne/, all shells with
971 # functions also support '${a:-b}'.
973 AT_SETUP([Null variable substitution])
974 AT_KEYWORDS([m4sh])
976 AT_DATA_M4SH([script.as],
977 [[AS_INIT
979 AS_UNSET([a])
982 case ${a:-x}${b:-y}${c:-z} in
983   xy.) ;;
984   *) exit 1 ;;
985 esac
986 case ${a-x}${b-y}${c-z} in
987   x.) ;;
988   *) exit 2 ;;
989 esac
991 case ${a+x}${b+y}${c+z} in
992   yz) ;;
993   *) exit 3 ;;
994 esac
995 case ${a:+x}${b:+y}${c:+z} in
996   z) ;;
997   *) exit 4 ;;
998 esac
1000 case ${a=x}${b=y}${c=z} in
1001   x.) ;;
1002   *) exit 5 ;;
1003 esac
1004 AS_UNSET([a])
1005 case ${a:=x}${b:=y}${c:=z} in
1006   xy.) ;;
1007   *) exit 6 ;;
1008 esac
1009 case $a$b$c in
1010   xy.) ;;
1011   *) exit 7 ;;
1012 esac
1013 AS_UNSET([a])
1016 (: ${a?oops}; echo fail) 2>err && exit 8
1017 grep oops err >/dev/null || exit 9
1018 test "${b?oops}" = '' || exit 10
1019 test "${c?oops}" = . || exit 11
1020 (: ${a:?oops}; echo fail) 2>err && exit 12
1021 grep oops err >/dev/null || exit 13
1022 (: ${b:?oops}; echo fail) 2>err && exit 14
1023 grep oops err >/dev/null || exit 15
1024 test "${c:?oops}" = . || exit 16
1027 AT_CHECK_M4SH
1028 AT_CHECK([$CONFIG_SHELL ./script])
1030 AT_CLEANUP
1033 ## ------------------- ##
1034 ## Functions Support.  ##
1035 ## ------------------- ##
1037 # All m4sh scripts require function support.
1039 AT_SETUP([Functions Support])
1040 AT_KEYWORDS([m4sh])
1042 AT_DATA_M4SH([script.as],
1043 [[AS_INIT
1044 AS_LINENO_PREPARE
1046 func_return () {
1047   (exit $1)
1050 func_success () {
1051   func_return 0
1054 func_failure () {
1055   func_return 1
1058 if func_success; then
1059   if func_failure; then
1060     AS_ERROR([func_failure passed])
1061   fi
1062 else
1063   AS_ERROR([func_success failed])
1067 AT_CHECK_M4SH
1068 AT_CHECK([$CONFIG_SHELL ./script])
1070 AT_CLEANUP
1075 ## ------------------------------ ##
1076 ## Functions and return Support.  ##
1077 ## ------------------------------ ##
1079 # All m4sh scripts require working return within functions.
1081 AT_SETUP([Functions and return Support])
1082 AT_KEYWORDS([m4sh])
1084 AT_DATA_M4SH([script.as],
1085 [[AS_INIT
1086 AS_LINENO_PREPARE
1088 func_success () {
1089   return 0
1092 func_failure () {
1093   return 1
1096 if func_success; then
1097   if func_failure; then
1098     AS_ERROR([func_failure passed])
1099   fi
1100 else
1101   AS_ERROR([func_success failed])
1105 AT_CHECK_M4SH
1106 AT_CHECK([$CONFIG_SHELL ./script])
1108 AT_CLEANUP
1111 ## --------------------------- ##
1112 ## Nested AS_REQUIRE_SHELL_FN. ##
1113 ## --------------------------- ##
1115 # Hypothesis: M4sh expands nested AS_REQUIRE_SHELL_FN
1116 # separately.
1118 AT_SETUP([Nested AS@&t@_REQUIRE_SHELL_FN])
1119 AT_KEYWORDS([m4sh])
1121 AT_DATA_M4SH([script.as], [[dnl
1122 m4_define([INIT], [oops])dnl
1123 AS_INIT
1125 m4_defun([TEST_FUNC2_BODY], [
1129 m4_defun([TEST_FUNC1_BODY], [
1130 AS_REQUIRE_SHELL_FN([test_func2], [], [TEST_FUNC2_BODY])
1134 AS_REQUIRE_SHELL_FN([test_func1], [], [TEST_FUNC1_BODY])
1135 test_func2
1138 AT_CHECK_M4SH
1139 AT_CHECK([$CONFIG_SHELL ./script])
1141 AT_CLEANUP
1144 ## ------------------- ##
1145 ## Nested AS_REQUIRE.  ##
1146 ## ------------------- ##
1148 # Hypothesis: M4sh expands the requirements of AS_REQUIRE in the
1149 # requested diversion, even if other AS_REQUIREs are interleaved.
1151 AT_SETUP([Nested AS@&t@_REQUIRE])
1152 AT_KEYWORDS([m4sh])
1154 AT_DATA_M4SH([script.as], [[dnl
1155 AS_INIT
1157 m4_defun([in_fn_diversion], still_in_m4sh_init_fn=yes)
1158 m4_defun([not_in_fn_diversion], still_in_m4sh_init_fn=no)
1160 m4_defun([NESTED], [nested_require_in_fn_diversion=$still_in_m4sh_init_fn])
1162 m4_defun([OUTER], [AS_REQUIRE([NESTED])dnl
1163 outer_require_in_fn_diversion=$still_in_m4sh_init_fn])
1165 m4_defun([test_init], [
1166 AS_REQUIRE([in_fn_diversion], , [M4SH-INIT-FN])
1167 AS_REQUIRE([OUTER], , [M4SH-INIT-FN])
1168 AS_REQUIRE([not_in_fn_diversion], , [M4SH-INIT-FN])
1171 test_init
1172 if test $outer_require_in_fn_diversion != yes; then AS_EXIT([1]); fi
1173 if test $nested_require_in_fn_diversion != no; then AS_EXIT([1]); fi
1176 AT_CHECK_M4SH
1177 AT_CHECK([$CONFIG_SHELL ./script])
1179 AT_CLEANUP
1182 ## ------------------------------------ ##
1183 ## AS_REQUIRE_SHELL_FN and m4_require.  ##
1184 ## ------------------------------------ ##
1186 # Hypothesis: M4sh expands the requirements of AS_REQUIRE_SHELL_FN
1187 # in M4SH-INIT-FN.  This changed after Autoconf 2.63.
1189 AT_SETUP([AS@&t@_REQUIRE_SHELL_FN and m4@&t@_require])
1190 AT_KEYWORDS([m4sh])
1192 AT_DATA_M4SH([script.as], [[dnl
1193 AS_INIT
1195 m4_defun([in_m4_sh_init], still_in_m4sh_init=yes)
1196 m4_defun([not_in_m4_sh_init], still_in_m4sh_init=no)
1198 m4_defun([error_if_emitted_in_m4sh_init], [
1199   if test x$still_in_m4sh_init = xyes; then
1200     AS_ERROR([requirement emitted in M4SH-INIT])
1201   fi
1204 m4_defun([TEST_FUNC_BODY], [
1205 m4_require([error_if_emitted_in_m4sh_init])
1206 : echo in shell function, with parameter = [$]1
1210 m4_defun([test_init], [
1211 AS_REQUIRE([in_m4_sh_init], , [M4SH-INIT-FN])
1212 AS_REQUIRE_SHELL_FN([test_func], [], [TEST_FUNC_BODY])
1213 AS_REQUIRE([not_in_m4_sh_init])
1216 test_init
1217 test_func parameter1
1220 AT_CHECK_M4SH
1221 AT_CHECK([$CONFIG_SHELL ./script])
1223 AT_CLEANUP
1226 ## -------------- ##
1227 ## AS_HELP_STRING ##
1228 ## -------------- ##
1230 AT_SETUP([AS@&t@_HELP_STRING])
1231 AT_KEYWORDS([m4sh m4@&t@_text_wrap m4@&t@_expand])
1233 AT_DATA_M4SH([script.as],
1234 [[AS_INIT
1236 echo "AS_HELP_STRING([--an-option],[some text])"
1237 echo "AS_HELP_STRING([--another-much-longer-option],
1238 [some other text which should wrap at our default of 80 characters.])"
1239 echo "AS_HELP_STRING([--fooT=barT], [foo bar])"
1240 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@], [foo bar])"
1241 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@123456789], [foo bar])"
1242 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@1234567890], [foo bar])"
1243 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@12345678901], [foo bar])"
1244 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@123456789012], [foo bar])"
1245 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@1234567890123], [foo bar])"
1246 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@],
1247 [some other text which should wrap at our default of 80 characters.])"
1248 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@123456789],
1249 [some other text which should wrap at our default of 80 characters.])"
1250 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@1234567890],
1251 [some other text which should wrap at our default of 80 characters.])"
1252 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@12345678901],
1253 [some other text which should wrap at our default of 80 characters.])"
1254 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@123456789012],
1255 [some other text which should wrap at our default of 80 characters.])"
1256 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@1234567890123],
1257 [some other text which should wrap at our default of 80 characters.])"
1258 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@],
1259 [some other @<][:@ex@:][>@ which should wrap at our default of 80 characters.])"
1260 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@123456789],
1261 [some other @<][:@ex@:][>@ which should wrap at our default of 80 characters.])"
1262 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@1234567890],
1263 [some other @<][:@ex@:][>@ which should wrap at our default of 80 characters.])"
1264 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@12345678901],
1265 [some other @<][:@ex@:][>@ which should wrap at our default of 80 characters.])"
1266 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@123456789012],
1267 [some other @<][:@ex@:][>@ which should wrap at our default of 80 characters.])"
1268 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@1234567890123],
1269 [some other @<][:@ex@:][>@ which should wrap at our default of 80 characters.])"
1270 echo "AS_HELP_STRING([[--foo[=bar]]],
1271 [some other t[]t which should wrap at our default of 80 characters.])"
1272 echo "AS_HELP_STRING([[--foo[=bar]123456789]],
1273 [some other t[]t which should wrap at our default of 80 characters.])"
1274 echo "AS_HELP_STRING([[--foo[=bar]1234567890]],
1275 [some other t[]t which should wrap at our default of 80 characters.])"
1276 echo "AS_HELP_STRING([[--foo[=bar]12345678901]],
1277 [some other t[]t which should wrap at our default of 80 characters.])"
1278 echo "AS_HELP_STRING([[--foo[=bar]123456789012]],
1279 [some other t[]t which should wrap at our default of 80 characters.])"
1280 echo "AS_HELP_STRING([[--foo[=bar]1234567890123]],
1281 [some other t[]t which should wrap at our default of 80 characters.])"
1282 m4_define([mac], [MACRO])dnl
1283 echo "AS_HELP_STRING([--mac], [mac])"
1284 echo "AS_HELP_STRING([--o1, --o2], [two
1285 options,        one  description])"
1286 echo "AS_HELP_STRING([[[--o3, --o4]]], [comma inside literal quoting])"
1287 echo "AS_HELP_STRING([--tune1], [check out the tuned formatting],
1288 [            ])"
1289 echo "AS_HELP_STRING([--tune2], [check out the tuned formatting],
1290 [12])"
1291 echo "AS_HELP_STRING([--tune3], [check out the tuned formatting],
1292 [], [40])"
1293 echo "AS_HELP_STRING([--tune4], [check out the tuned formatting],
1294 [12], [40])"
1297 AT_CHECK_M4SH
1298 AT_CHECK([$CONFIG_SHELL ./script], [0],
1299 [[  --an-option             some text
1300   --another-much-longer-option
1301                           some other text which should wrap at our default of
1302                           80 characters.
1303   --fooT=barT             foo bar
1304   --foo[=bar]             foo bar
1305   --foo[=bar]123456789    foo bar
1306   --foo[=bar]1234567890   foo bar
1307   --foo[=bar]12345678901  foo bar
1308   --foo[=bar]123456789012 foo bar
1309   --foo[=bar]1234567890123
1310                           foo bar
1311   --foo[=bar]             some other text which should wrap at our default of
1312                           80 characters.
1313   --foo[=bar]123456789    some other text which should wrap at our default of
1314                           80 characters.
1315   --foo[=bar]1234567890   some other text which should wrap at our default of
1316                           80 characters.
1317   --foo[=bar]12345678901  some other text which should wrap at our default of
1318                           80 characters.
1319   --foo[=bar]123456789012 some other text which should wrap at our default of
1320                           80 characters.
1321   --foo[=bar]1234567890123
1322                           some other text which should wrap at our default of
1323                           80 characters.
1324   --foo[=bar]             some other [ex] which should wrap at our default of
1325                           80 characters.
1326   --foo[=bar]123456789    some other [ex] which should wrap at our default of
1327                           80 characters.
1328   --foo[=bar]1234567890   some other [ex] which should wrap at our default of
1329                           80 characters.
1330   --foo[=bar]12345678901  some other [ex] which should wrap at our default of
1331                           80 characters.
1332   --foo[=bar]123456789012 some other [ex] which should wrap at our default of
1333                           80 characters.
1334   --foo[=bar]1234567890123
1335                           some other [ex] which should wrap at our default of
1336                           80 characters.
1337   --foo[=bar]             some other t[]t which should wrap at our default of
1338                           80 characters.
1339   --foo[=bar]123456789    some other t[]t which should wrap at our default of
1340                           80 characters.
1341   --foo[=bar]1234567890   some other t[]t which should wrap at our default of
1342                           80 characters.
1343   --foo[=bar]12345678901  some other t[]t which should wrap at our default of
1344                           80 characters.
1345   --foo[=bar]123456789012 some other t[]t which should wrap at our default of
1346                           80 characters.
1347   --foo[=bar]1234567890123
1348                           some other t[]t which should wrap at our default of
1349                           80 characters.
1350   --MACRO                 mac
1351   --o1, --o2              two options, one description
1352   [--o3, --o4]            comma inside literal quoting
1353   --tune1   check out the tuned formatting
1354   --tune2   check out the tuned formatting
1355   --tune3                 check out the
1356                           tuned
1357                           formatting
1358   --tune4   check out the tuned
1359             formatting
1362 AT_CLEANUP
1365 ## ------------------- ##
1366 ## AS_IF and AS_CASE.  ##
1367 ## ------------------- ##
1369 AT_SETUP([AS@&t@_IF and AS@&t@_CASE])
1370 AT_KEYWORDS([m4sh m4@&t@_map_args_pair])
1372 AT_DATA_M4SH([script.as], [[dnl
1373 AS_INIT
1374 # Syntax checks: cope with empty arguments.
1375 AS_IF([:], [], [echo wrong])
1376 AS_IF([:], [echo one], [echo wrong])
1377 AS_IF([false], [echo wrong], [echo two])
1378 AS_IF([false], [echo wrong])
1379 # n-ary version
1380 AS_IF([false], [echo wrong],
1381       [:], [echo three])
1382 AS_IF([false], [echo wrong],
1383       [:], [echo four],
1384       [echo wrong])
1385 AS_IF([false], [echo wrong],
1386       [false], [echo wrong])
1387 AS_IF([false], [echo wrong],
1388       [false], [echo wrong],
1389       [echo five])
1390 AS_IF([false], [echo wrong],
1391       [false], [echo wrong],
1392       [:], [echo six],
1393       [echo wrong])
1394 AS_CASE([foo])
1395 AS_CASE([foo], [echo seven])
1396 AS_CASE([foo],
1397         [foo], [echo eight],
1398         [echo wrong])
1399 AS_CASE([foo],
1400         [foo], [echo nine],
1401         [*],   [echo wrong])
1402 AS_CASE([foo],
1403         [bar], [echo wrong],
1404         [foo], [echo ten],
1405         [*],   [echo wrong])
1407 # check for nesting, lists, and side effects, and quoting robustness
1408 empty=
1409 AS_IF([AS_IF([$empty], [echo eleven])]) && AS_CASE([foo]) && echo twelve
1410 rm -f file
1411 AS_IF([touch file; false]) && echo thirteen
1412 test -f file && echo fourteen
1413 rm -f file
1414 AS_CASE([`touch file; false`]) && test -f file && echo fifteen
1415 dnl The next line is badly underquoted; don't intentionally copy this style.
1416 AS_CASE([foo], [foo], m4_do(AS_CASE([bar], [bar], [echo sixteen])))
1417 dnl Handle blank arguments.
1418 AS_IF([false], [:], [ ]) && AS_CASE([foo], [foo], []
1419 ) && echo seventeen
1420 m4_define([empty])AS_IF([:], [empty]
1421 ) && AS_IF([false], [], [empty]
1422 ) || AS_CASE([foo], [foo], [empty]) && echo eighteen
1423 dnl Allow for users that don't know to avoid trailing whitespace
1424 AS_IF([:
1425 ], [echo nineteen])
1426 set -e
1427 AS_IF([false], [], [echo twenty])
1428 set +e
1430 # check that require works correctly
1431 m4_for([n], 1, 9, [],
1432 [m4_defun([FOO]n, [foo]n[=]n)dnl
1433 m4_defun([BAR]n,
1434          [m4_require([FOO]]n[)dnl
1435 bar]n[=]n)[]dnl
1438 AS_IF([:], [BAR1])
1439 echo "foo1=$foo1 bar1=$bar1"
1440 AS_IF([:], [], [BAR2])
1441 echo "foo2=$foo2 bar2=$bar2"
1442 AS_IF([false], [BAR3])
1443 echo "foo3=$foo3 bar3=$bar3"
1444 AS_IF([false], [], [BAR4])
1445 echo "foo4=$foo4 bar4=$bar4"
1446 AS_CASE([x], [x], [BAR5])
1447 echo "foo5=$foo5 bar5=$bar5"
1448 AS_CASE([x], [y], [BAR6])
1449 echo "foo6=$foo6 bar6=$bar6"
1450 AS_CASE([x],
1451         [x], [:],
1452         [BAR7])
1453 echo "foo7=$foo7 bar7=$bar7"
1454 AS_CASE([x],
1455         [y], [:],
1456         [BAR8])
1457 echo "foo8=$foo8 bar8=$bar8"
1458 AS_CASE([x],
1459         [y], [:],
1460         [x], [BAR9])
1461 echo "foo9=$foo9 bar9=$bar9"
1464 AT_CHECK_M4SH
1465 AT_CHECK([$CONFIG_SHELL ./script], [0], [[one
1467 three
1468 four
1469 five
1471 seven
1472 eight
1473 nine
1475 eleven
1476 twelve
1477 thirteen
1478 fourteen
1479 fifteen
1480 sixteen
1481 seventeen
1482 eighteen
1483 nineteen
1484 twenty
1485 foo1=1 bar1=1
1486 foo2=2 bar2=
1487 foo3=3 bar3=
1488 foo4=4 bar4=4
1489 foo5=5 bar5=5
1490 foo6=6 bar6=
1491 foo7=7 bar7=
1492 foo8=8 bar8=8
1493 foo9=9 bar9=9
1496 dnl stress test for large number of conditionals
1497 dnl too large, and we start tickling shell bugs
1498 m4_pushdef([limit], [1000])dnl
1499 AT_DATA_M4SH([script.as], [[dnl
1500 AS_INIT
1501 AS_IF(m4_shift(m4_for([i], [1], ]limit[, [], [, test $[1] = i, echo i])))
1502 AS_IF(m4_shift(m4_for([i], [1], ]limit[, [], [, test $[1] = i, echo i])),
1503       [echo default])
1504 AS_CASE([$[1]]m4_for([i], [1], ]limit[, [], [, i, echo i]))
1505 AS_CASE([$[1]]m4_for([i], [1], ]limit[, [], [, i, echo i]), [echo default])
1508 dnl Add --force so autom4te doesn't think 'script' is still up to date.
1509 AT_CHECK_M4SH([--force])
1510 AT_CHECK([$CONFIG_SHELL ./script 1], [0], [[1
1515 AT_CHECK([$CONFIG_SHELL ./script limit], [0], [limit
1516 limit
1517 limit
1518 limit
1520 AT_CHECK([$CONFIG_SHELL ./script default], [0], [[default
1521 default
1523 m4_popdef([limit])
1525 AT_CLEANUP
1528 ## -------- ##
1529 ## AS_FOR.  ##
1530 ## -------- ##
1532 AT_SETUP([AS@&t@_FOR])
1533 AT_KEYWORDS([m4sh])
1535 AT_DATA_M4SH([script.as], [[dnl
1536 AS_INIT
1538 # Simple checks.
1539 AS_FOR([m4var], [shvar], [a],
1540 [echo "m4var $shvar"])
1541 AS_FOR([m4var], [shvar], [b c],
1542 [echo "m4var $shvar"])
1543 list='d e'
1544 AS_FOR([m4var], [shvar], [$list],
1545 [echo "m4var $shvar"])
1546 AS_FOR([m4var], [shvar], ["$list"],
1547 [echo "m4var $shvar"])
1548 AS_FOR([m4var], [shvar], ['$list'],
1549 [echo "m4var $shvar"])
1550 AS_FOR([m4var], [shvar], [\'],
1551 [echo "m4var $shvar"])
1553 # Syntax checks: cope with empty/blank arguments.
1554 set f g
1555 AS_FOR([], [shvar], [],
1556 [echo "m4_defn([]) $shvar"])
1557 rm -f file
1558 AS_FOR([], [shvar], [`touch file`])
1559 test -f file || exit 1
1560 AS_FOR([], [shvar], [], [ ])
1561 m4_define([empty])AS_FOR([], [shvar], [], [empty])
1563 # Check that break works.
1564 while :
1566   AS_FOR([m4var], [shvar], [h i],
1567     [echo "m4var"; break 2])
1568   exit 1
1569 done
1570 while :
1572   AS_FOR([m4var], [shvar], [j],
1573     [echo "m4var"; break 2])
1574   exit 1
1575 done
1578 AT_CHECK_M4SH
1579 AT_CHECK([$CONFIG_SHELL ./script], [0], [[a a
1580 b b
1581 c c
1582 d d
1583 e e
1584 d e d e
1585 $list $list
1586 ' '
1587 f f
1588 g g
1593 AT_CLEANUP
1596 ## --------------- ##
1597 ## AS_LITERAL_IF.  ##
1598 ## --------------- ##
1600 AT_SETUP([AS@&t@_LITERAL_IF])
1601 AT_KEYWORDS([m4sh AS@&t@_LITERAL_WORD_IF AS@&t@_LITERAL_HEREDOC_IF])
1603 AT_DATA_M4SH([script.as], [[dnl
1604 AS_INIT
1605 echo AS_LITERAL_IF([lit], [ok], [ERR]) 1
1606 echo AS_LITERAL_IF([l-/.it], [ok], [ERR]) 2
1607 echo AS_LITERAL_IF([l''it], [ERR], [ok]) 3
1608 echo AS_LITERAL_IF([l$it], [ERR], [ok]) 4
1609 echo AS_LITERAL_IF([l$it], [ERR1], [ERR2], [ok]) 5
1610 echo AS_LITERAL_IF([l${it}], [ERR1], [ERR2], [ok]) 6
1611 echo AS_LITERAL_IF([l`case a in b) ;; esac`it], [ERR], [ok]) 7
1612 echo AS_LITERAL_IF([l`case a in b) ;; esac`it], [ERR1], [ok], [ERR2]) 8
1613 m4_define([mac], [l-/.it])
1614 echo AS_LITERAL_IF([mac], [ok], [ERR]) 9
1615 echo AS_LITERAL_IF([mac($, ``)], [ok], [ERR]) 10
1616 m4_define([mac], [l$it])
1617 echo AS_LITERAL_IF([mac], [ERR], [ok]) 11
1618 echo AS_LITERAL_IF([mac], [ERR1], [ERR2], [ok]) 12
1619 m4_define([mac], [l``it])
1620 echo AS_LITERAL_IF([mac], [ERR], [ok]) 13
1621 echo AS_LITERAL_IF([mac], [ERR1], [ok], [ERR2]) 14
1622 echo AS_LITERAL_IF([    a ][
1623 b], [ok], [ERR]) 15
1624 echo AS_LITERAL_WORD_IF([       a ][
1625 b], [ERR], [ok]) 16
1626 echo AS_LITERAL_HEREDOC_IF([    a ][
1627 b], [ok], [ERR]) 17
1628 echo AS_LITERAL_IF([(a)], [ERR], [ok]) 18
1629 echo AS_LITERAL_WORD_IF([(a)], [ERR], [ok]) 19
1630 echo AS_LITERAL_HEREDOC_IF([(a)], [ok], [ERR]) 20
1631 echo AS_LITERAL_IF([@S|@a], [ERR], [ok]) 21
1632 echo AS_LITERAL_WORD_IF([@S|@a], [ERR], [ok]) 22
1633 echo AS_LITERAL_HEREDOC_IF([@S|@a], [ERR], [ok]) 23
1634 echo AS_LITERAL_IF([${a+b}], [ERR1], [ok], [ERR2]) 24
1635 echo AS_LITERAL_IF([${a=b}], [ERR1], [ok], [ERR2]) 25
1636 echo AS_LITERAL_IF([a+b], [ok], [ERR1], [ERR2]) 26
1637 echo AS_LITERAL_IF([a=b], [ok], [ERR1], [ERR2]) 27
1640 AT_CHECK_M4SH
1641 AT_CHECK([$CONFIG_SHELL ./script], [],
1642 [[ok 1
1643 ok 2
1644 ok 3
1645 ok 4
1646 ok 5
1647 ok 6
1648 ok 7
1649 ok 8
1650 ok 9
1651 ok 10
1652 ok 11
1653 ok 12
1654 ok 13
1655 ok 14
1656 ok 15
1657 ok 16
1658 ok 17
1659 ok 18
1660 ok 19
1661 ok 20
1662 ok 21
1663 ok 22
1664 ok 23
1665 ok 24
1666 ok 25
1667 ok 26
1668 ok 27
1671 AT_CLEANUP
1674 ## --------------------- ##
1675 ## AS_TR_SH, AS_TR_CPP.  ##
1676 ## --------------------- ##
1678 AT_SETUP([AS@&t@_TR_SH and AS@&t@_TR_CPP])
1680 AT_DATA_M4SH([script.as], [[dnl
1681 AS_INIT
1682 m4_define([abc], [hI])m4_define([ABC], [Hi])
1683 m4_define([hi], [oops])m4_define([HI], [OOPS])
1684 echo AS_TR_SH(abc) AS_TR_SH(aBc) AS_TR_SH(ABC)
1685 echo AS_TR_SH([abc]) AS_TR_SH([aBc]) AS_TR_SH([ABC])
1686 echo AS_TR_SH([[abc]]) AS_TR_SH([[aBc]]) AS_TR_SH([[ABC]])
1687 echo AS_TR_CPP(abc) AS_TR_CPP(aBc) AS_TR_CPP(ABC)
1688 echo AS_TR_CPP([abc]) AS_TR_CPP([aBc]) AS_TR_CPP([ABC])
1689 echo AS_TR_CPP([[abc]]) AS_TR_CPP([[aBc]]) AS_TR_CPP([[ABC]])
1690 echo ===
1691 [var=abc vAr=aBc VAR=ABC]
1692 echo AS_TR_SH($var) AS_TR_SH($vAr) AS_TR_SH($VAR)
1693 echo AS_TR_SH([$var]) AS_TR_SH([$vAr]) AS_TR_SH([$VAR])
1694 echo AS_TR_SH([[$var]]) AS_TR_SH([[$vAr]]) AS_TR_SH([[$VAR]])
1695 echo AS_TR_CPP($var) AS_TR_CPP($vAr) AS_TR_CPP($VAR)
1696 echo AS_TR_CPP([$var]) AS_TR_CPP([$vAr]) AS_TR_CPP([$VAR])
1697 echo AS_TR_CPP([[$var]]) AS_TR_CPP([[$vAr]]) AS_TR_CPP([[$VAR]])
1698 echo ===
1699 echo AS_TR_SH(`echo abc`) AS_TR_SH(`echo aBc`) AS_TR_SH(`echo ABC`)
1700 echo AS_TR_SH([`echo abc`]) AS_TR_SH([`echo aBc`]) AS_TR_SH([`echo ABC`])
1701 echo AS_TR_SH([[`echo abc`]]) AS_TR_SH([[`echo aBc`]]) AS_TR_SH([[`echo ABC`]])
1702 echo AS_TR_CPP(`echo abc`) AS_TR_CPP(`echo aBc`) AS_TR_CPP(`echo ABC`)
1703 echo AS_TR_CPP([`echo abc`]) AS_TR_CPP([`echo aBc`]) AS_TR_CPP([`echo ABC`])
1704 echo AS_TR_CPP([[`echo abc`]]) AS_TR_CPP([[`echo aBc`]]) AS_TR_CPP([[`echo ABC`]])
1705 echo ===
1706 # start here
1707 echo AS_TR_SH([a.b/c+*-=])
1708 echo AS_TR_CPP([a.b/c+*-=])
1709 var=a.b/c+*-=
1710 echo AS_TR_SH([$var])
1711 echo AS_TR_CPP([$var])
1712 m4_define([macro], [a.b/c+*-=])
1713 echo AS_TR_SH([macro])
1714 echo AS_TR_CPP([macro])
1717 AT_CHECK_M4SH
1718 AT_CHECK([$CONFIG_SHELL ./script], [],
1719 [[hI aBc Hi
1720 hI aBc Hi
1721 abc aBc ABC
1722 HI ABC HI
1723 HI ABC HI
1724 ABC ABC ABC
1726 abc aBc ABC
1727 abc aBc ABC
1728 abc aBc ABC
1729 ABC ABC ABC
1730 ABC ABC ABC
1731 ABC ABC ABC
1733 hI aBc Hi
1734 hI aBc Hi
1735 abc aBc ABC
1736 HI ABC HI
1737 HI ABC HI
1738 ABC ABC ABC
1740 a_b_cpp__
1741 A_B_C_P__
1742 a_b_cpp__
1743 A_B_C_P__
1744 a_b_cpp__
1745 A_B_C_P__
1748 dnl Check that of the last 6 macros, only 2 needed command substitution.
1749 dnl This test abuses our knowledge of m4sh internals a bit; oh well.
1750 AT_CHECK([tab=' ' # a single ASCII tab character
1751 sed -n '/start here/,$ {
1752 /`.*`/p
1753 }' script | wc -l | sed "s/[[ $tab]]//g" ], [], [[2
1756 AT_CLEANUP
1759 ## ---------- ##
1760 ## AS_VAR_*.  ##
1761 ## ---------- ##
1763 AT_SETUP([AS@&t@_VAR basics])
1764 AT_KEYWORDS([m4sh AS@&t@_VAR_COPY AS@&t@_VAR_SET AS@&t@_VAR_GET])
1765 AT_KEYWORDS([AS@&t@_VAR_TEST_SET AS@&t@_VAR_SET_IF AS@&t@_VAR_IF])
1766 AT_KEYWORDS([AS@&t@_VAR_PUSHDEF AS@&t@_VAR_POPDEF])
1768 AT_DATA_M4SH([script.as], [[dnl
1769 AS_INIT
1770  m4_define([with], [WITH])
1771 # Literals.
1772 dnl AS_VAR_SET_IF also covers AS_VAR_TEST_SET
1773 AS_VAR_SET_IF([foo], [echo oops]) && echo ok
1774 AS_VAR_IF([foo], [], [echo ok], [echo oops])
1775 foo=
1776 AS_VAR_SET_IF([foo], [echo ok])
1777 AS_VAR_SET([foo], ['\a  "weird" `value` with; $fun '\''characters
1778 ']) # 'font-lock
1779 AS_VAR_COPY([bar], [foo])
1780 AS_ECHO(["$bar-"])
1781 AS_ECHO(["AS_VAR_GET([foo])-"])
1782 AS_VAR_SET_IF([foo], [echo ok], [echo oops])
1783 AS_VAR_IF([foo], [string], [echo oops]) && echo ok
1784 AS_VAR_PUSHDEF([tmp], [foo])
1785 AS_VAR_IF([tmp], ['\a  "weird" `value` with; $fun '\''characters
1786 '], [echo ok], [echo oops]) # 'font-lock
1787 AS_VAR_POPDEF([tmp])
1788 m4_ifdef([tmp], [echo oops])
1790 # Indirects via shell vars.
1791 echo '===='
1792 num=1
1793 AS_VAR_SET_IF([foo$num], [echo oops]) && echo ok
1794 AS_VAR_IF([foo$num], [], [echo ok], [echo oops])
1795 foo1=
1796 AS_VAR_SET_IF([foo$num], [echo ok])
1797 AS_VAR_SET([foo$num], ['\a  "weird" `value` with; $fun '\''characters
1798 ']) # 'font-lock
1799 AS_VAR_COPY([bar], [foo$num])
1800 num=2
1801 AS_VAR_COPY([foo$num], [bar])
1802 AS_ECHO(["$foo2-"])
1803 AS_ECHO(["AS_VAR_GET([foo$num])-"])
1804 AS_VAR_SET_IF([foo$num], [echo ok], [echo oops])
1805 AS_VAR_IF([foo$num], [string], [echo oops]) && echo ok
1806 AS_VAR_PUSHDEF([tmp], [foo$num])
1807 AS_VAR_IF([tmp], ['\a  "weird" `value` with; $fun '\''characters
1808 '], [echo ok], [echo oops]) # 'font-lock
1809 AS_VAR_POPDEF([tmp])
1810 m4_ifdef([tmp], [echo oops])
1812 # Indirects via command substitution.
1813 echo '===='
1814 AS_VAR_SET_IF([`echo foo3`], [echo oops]) && echo ok
1815 AS_VAR_IF([`echo foo3`], [], [echo ok], [echo oops])
1816 foo3=
1817 AS_VAR_SET_IF([`echo foo3`], [echo ok])
1818 AS_VAR_SET([`echo foo3`], ['\a  "weird" `value` with; $fun '\''characters
1819 ']) # 'font-lock
1820 AS_VAR_COPY([bar], [`echo foo3`])
1821 num=2
1822 AS_VAR_COPY([`echo foo4`], [bar])
1823 AS_ECHO(["$foo4-"])
1824 AS_ECHO(["AS_VAR_GET([`echo foo4`])-"])
1825 AS_VAR_SET_IF([`echo foo4`], [echo ok], [echo oops])
1826 AS_VAR_IF([`echo foo4`], [string], [echo oops]) && echo ok
1827 AS_VAR_PUSHDEF([tmp], [`echo foo4`])
1828 AS_VAR_IF([tmp], ['\a  "weird" `value` with; $fun '\''characters
1829 '], [echo ok], [echo oops]) # 'font-lock
1830 AS_VAR_POPDEF([tmp])
1831 m4_ifdef([tmp], [echo oops])
1835 AT_CHECK_M4SH
1836 AT_CHECK([$CONFIG_SHELL ./script], [], [[ok
1839 \a  "weird" `value` WITH; $fun 'characters
1841 \a  "weird" `value` WITH; $fun 'characters
1846 ====
1850 \a  "weird" `value` WITH; $fun 'characters
1852 \a  "weird" `value` WITH; $fun 'characters-
1856 ====
1860 \a  "weird" `value` WITH; $fun 'characters
1862 \a  "weird" `value` WITH; $fun 'characters-
1868 AT_CLEANUP
1871 ## --------------- ##
1872 ## AS_VAR_APPEND.  ##
1873 ## --------------- ##
1875 AT_SETUP([AS@&t@_VAR_APPEND])
1876 AT_KEYWORDS([m4sh AS@&t@_VAR])
1878 AT_DATA_M4SH([script.as], [[dnl
1879 AS_INIT
1880 # Literals.
1881 AS_VAR_APPEND([foo], ["hello,  "])
1882 AS_VAR_APPEND([foo], [world])
1883 echo "$foo"
1884 # Indirects via shell vars.
1885 num=1
1886 AS_VAR_APPEND([foo$num], ['hello,  '])
1887 AS_VAR_APPEND([foo$num], [`echo "world"`])
1888 echo "$foo1"
1889 # Indirects via command substitution.
1890 h=hello w=',  world'
1891 AS_VAR_APPEND([`echo foo2`], [${h}])
1892 AS_VAR_APPEND([`echo foo2`], ["$w"])
1893 echo "$foo2"
1896 AT_CHECK_M4SH
1897 AT_CHECK([$CONFIG_SHELL ./script], [],
1898 [[hello,  world
1899 hello,  world
1900 hello,  world
1903 AT_CLEANUP
1906 ## -------------- ##
1907 ## AS_VAR_ARITH.  ##
1908 ## -------------- ##
1910 AT_SETUP([AS@&t@_VAR_ARITH])
1911 AT_KEYWORDS([m4sh AS@&t@_VAR])
1913 AT_DATA_M4SH([script.as], [[dnl
1914 AS_INIT
1915 # Literals.
1916 AS_VAR_ARITH([foo], [1 + 1])
1917 echo "$foo"
1918 # Indirects via shell vars.
1919 num=1
1920 AS_VAR_ARITH([foo$num], [\( 2 + 3 \) \* 4])
1921 echo "$foo1"
1922 # Indirects via command substitution.
1923 AS_VAR_ARITH([`echo foo2`], [0 + -2 + $foo1 / 2])
1924 echo "$foo2"
1927 AT_CHECK_M4SH
1928 AT_CHECK([$CONFIG_SHELL ./script], [],
1934 AT_CLEANUP
1937 ## ----------------- ##
1938 ## AS_INIT cleanup.  ##
1939 ## ----------------- ##
1941 AT_SETUP([AS@&t@_INIT cleanup])
1942 AT_KEYWORDS([m4sh m4@&t@_wrap m4@&t@_wrap_lifo])
1944 AT_DATA_M4SH([script.as], [[dnl
1945 dnl Registered before AS_INIT's cleanups
1946 m4_wrap([echo cleanup 1
1948 m4_pushdef([_AS_SHELL_FN_SPY])dnl neutralize the spy, we don't care about it
1949 AS_INIT
1950 dnl Registered after AS_INIT's cleanups, thus goes to KILL diversion
1951 m4_wrap([echo cleanup 2
1952 dnl However, nested wraps and diversions can still be used
1953 dnl Also, test wrapping text that looks like parameter reference
1954 m4_wrap([echo cleanup 3
1955 m4_divert_text([M4SH-INIT], [m4_define([foo], [$1])dnl
1956 echo prep foo([4])
1957 ])])])
1958 dnl Registered before AS_INIT's cleanups
1959 m4_wrap_lifo([echo cleanup 5
1961 echo body
1964 AT_CHECK_M4SH
1965 AT_CHECK([$CONFIG_SHELL ./script], [], [[prep 4
1966 body
1967 cleanup 5
1968 cleanup 1
1971 AT_CLEANUP
1974 ## -------------------------- ##
1975 ## AS_INIT basename __file__. ##
1976 ## -------------------------- ##
1978 AT_SETUP([AS@&t@_INIT basename __@&t@file__])
1979 AT_KEYWORDS([m4sh])
1981 AT_CHECK([mkdir sub || exit 77])
1982 AT_DATA_M4SH([sub/script.as], [[dnl
1983 AS_INIT
1985 AT_CHECK_AUTOM4TE([--language=m4sh sub/script.as -o script])
1986 AT_CHECK([grep '^# Generated from' script], [0], [dnl
1987 # Generated from script.as by ]m4_PACKAGE_STRING[.
1990 AT_CLEANUP
1993 ## ------------------- ##
1994 ## AS_INIT_GENERATED.  ##
1995 ## ------------------- ##
1997 AT_SETUP([AS@&t@_INIT_GENERATED])
1998 AT_KEYWORDS([AS@&t@_MESSAGE AS@&t@_MESSAGE_LOG_FD])
2000 dnl First run, no logging, tests shell selection
2001 AT_DATA_M4SH([script.as], [[dnl
2002 AS_INIT
2003 AS_INIT_GENERATED([child], [echo hello from child])
2004 cat >>child <<\EOF
2005 AS_ECHO(["SHELL=$SHELL"])
2007 echo hello from parent
2008 AS_ECHO(["SHELL=$SHELL"])
2011 AT_CHECK_M4SH
2012 AT_CHECK([$CONFIG_SHELL ./script], [0], [stdout])
2013 AT_CHECK([grep 'SHELL=.' stdout], [0], [ignore])
2014 sed s/parent/child/ <stdout >expout
2015 AT_CHECK([./child], [0], [expout])
2016 SHELL=/bogus
2017 export SHELL
2018 cp stdout expout
2019 mv child child.bak
2020 AT_CHECK([$CONFIG_SHELL ./script], [0], [expout])
2021 AT_CHECK([cmp child child.bak])
2022 AT_CHECK([grep 'SHELL=.' stdout], [0], [ignore])
2023 sed s/parent/child/ <stdout >expout
2024 AT_CHECK([./child], [0], [expout])
2027 dnl Second run, with logging from parent and child, tests fd handling
2028 AT_DATA_M4SH([script.as], [[dnl
2029 AS_INIT
2030 child=${1-child}
2031 m4_define([AS_MESSAGE_LOG_FD], [5])
2032 exec AS_MESSAGE_LOG_FD>log
2033 AS_INIT_GENERATED([$child], [echo hello1 from $child]) || AS_EXIT([1])
2034 cat >>$child <<\EOF
2035 m4_pushdef([AS_MESSAGE_LOG_FD])
2036 AS_MESSAGE([hello2 from ${child}child])
2037 m4_popdef([AS_MESSAGE_LOG_FD])
2038 exec AS_MESSAGE_LOG_FD>>log
2039 AS_MESSAGE([hello3 from child])
2041 AS_MESSAGE([hello from parent])
2042 dnl close log in parent before spawning child, for mingw
2043 exec AS_MESSAGE_LOG_FD>&-
2044 ./$child
2047 rm -f script
2048 AT_CHECK_M4SH
2049 AT_CHECK([$CONFIG_SHELL ./script], [0], [[script: hello from parent
2050 hello1 from child
2051 child: hello2 from child
2052 child: hello3 from child
2054 AT_CHECK([[sed 's,:[0-9][0-9]*:,:0:,' log]], [0],
2055 [[script:0: hello from parent
2056 child:0: hello3 from child
2059 # Force write error creating a file on stdout
2060 if test -w /dev/full && test -c /dev/full; then
2061   AT_CHECK([$CONFIG_SHELL ./script /dev/full], [1], [ignore], [ignore])
2064 AT_CLEANUP
2067 ## --------------- ##
2068 ## AS_MESSAGE_FD.  ##
2069 ## --------------- ##
2071 AT_SETUP([AS@&t@_MESSAGE_FD])
2072 AT_KEYWORDS([AS@&t@_MESSAGE AS@&t@_MESSAGE_LOG_FD AS@&t_ORIGINAL_STDIN_FD])
2073 AT_KEYWORDS([AS@&t@_LINENO_PUSH])
2075 AT_DATA_M4SH([script.as], [[dnl
2076 AS_INIT
2077 m4_define([AS_ORIGINAL_STDIN_FD], [5])
2078 m4_define([AS_MESSAGE_LOG_FD], [6])
2079 m4_define([AS_MESSAGE_FD], [7])
2080 exec AS_ORIGINAL_STDIN_FD<&0 </dev/null AS_MESSAGE_LOG_FD>log
2081 if test $[#] -gt 0; then
2082   exec AS_MESSAGE_FD>/dev/null
2083 else
2084   exec AS_MESSAGE_FD>&1
2086 AS_LINENO_PUSH([100])
2087 cat # tests that stdin is neutralized
2088 AS_MESSAGE([hello world])
2089 cat <&AS_ORIGINAL_STDIN_FD
2092 AT_CHECK_M4SH
2093 AT_CHECK([echo goodbye | $CONFIG_SHELL ./script], [0],
2094 [[script: hello world
2095 goodbye
2097 AT_CHECK([cat log], [0],
2098 [[script:100: hello world
2100 rm log
2101 AT_CHECK([echo goodbye | $CONFIG_SHELL ./script silent], [0],
2102 [[goodbye
2104 AT_CHECK([cat log], [0],
2105 [[script:100: hello world
2108 AT_CLEANUP
2111 ## --------------- ##
2112 ## _AS_CLEAN_DIR.  ##
2113 ## --------------- ##
2115 AT_SETUP([_AS@&t@_CLEAN_DIR])
2117 dnl ensure that we can erase all files in a directory.  Note that
2118 dnl _AS_CLEAN_DIR needs three globs to catch all these files.
2119 AT_DATA_M4SH([script.as], [[dnl
2120 AS_INIT
2121 # Unwritable subdirectories are common during 'make distcheck'.
2122 mkdir sub sub/unwritable || AS_ERROR([failed to mkdir])
2123 touch sub/unwritable/file || AS_ERROR([failed to touch])
2124 chmod a-wx sub/unwritable || AS_ERROR([failed to chmod])
2125 # Cygwin 1.5 can't touch 'sub/...', so make that file optional.
2126 touch sub/a sub/aa sub/aaa sub/.a sub/..a sub/.aa \
2127   || AS_ERROR([failed to touch])
2128 touch sub/... 2>/dev/null
2129 _AS_CLEAN_DIR([sub]) || AS_ERROR([failed to clean])
2130 # rmdir instead of 'rm -fr' here proves that we emptied sub.
2131 rmdir sub || AS_ERROR([failed to rmdir])
2134 AT_CHECK_M4SH
2135 AT_CHECK([$CONFIG_SHELL ./script])
2137 AT_CLEANUP
2140 ## -------- ##
2141 ## ECHO_C.  ##
2142 ## -------- ##
2144 AT_SETUP([ECHO_C])
2146 AT_DATA_M4SH([script.as], [[dnl
2147 AS_INIT
2148 _AS_PREPARE
2149 foo=`echo foobar`
2150 echo "$foo"
2153 AT_CHECK_M4SH
2154 AT_CHECK([$CONFIG_SHELL ./script], [], [foobar
2157 AT_CLEANUP