Debian Codegraph @

tests/m4sh.at

raw
1 # -*- Autotest -*-
2
3 AT_BANNER([M4sh.])
4
5 # Copyright (C) 2000-2017, 2020-2026 Free Software Foundation, Inc.
6 #
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.
11 #
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.
16 #
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/>.
19
20 ## --------------------------- ##
21 ## Re-exec with CONFIG_SHELL. ##
22 ## --------------------------- ##
23
24 AT_SETUP([No extra re-exec with CONFIG_SHELL])
25 AT_KEYWORDS([CONFIG_SHELL])
26 AT_DATA_M4SH([script.as],
27 [[
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
39
40 AT_CLEANUP
41
42 AT_SETUP([Forced re-exec with CONFIG_SHELL])
43 AT_KEYWORDS([CONFIG_SHELL])
44
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
51
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
55
56 AT_DATA([fake-shell],
57 [[#!/bin/sh
58 echo 'Fake shell executed.'
59 shift # fake shell
60 echo "nargs = @S|@#"
61 for i
62 do
63 printf ' :%s:\n' "$i"
64 done
65 ]])
66 chmod a+x fake-shell
67
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.
78
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.
90
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.
107
108 AT_CLEANUP
109
110 AT_SETUP([Configure re-execs self with CONFIG_SHELL])
111
112 AT_DATA([configure.ac],
113 [[AC_INIT
114 echo foobar >> quux
115 AC_OUTPUT
116 ]])
117
118 AT_CHECK_AUTOCONF
119
120 AT_DATA([cfg-sh],
121 [[#!/bin/sh
122 : > cfg-sh-has-run
123 exec sh "@S|@@"
124 ]])
125 chmod a+x cfg-sh
126
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 ], [])
137
138 rm -f quux cfg-sh*
139 AT_CLEANUP
140
141
142 ## ------------------- ##
143 ## AS_WARN, AS_ERROR. ##
144 ## ------------------- ##
145
146 AT_SETUP([AS@&t@_WARN and AS@&t@_ERROR])
147 AT_KEYWORDS([m4sh])
148
149 dnl without logging
150 AT_DATA_M4SH([script.as],
151 [[AS_INIT
152 AS_WARN([*watch out*])dnl
153
154 if test x"$die" != x; then
155 AS_ERROR([you're dead])dnl
156
157 AS_ERROR([really])dnl
158
159 fi
160 echo got here
161 ]])
162
163 AT_CHECK_M4SH
164 AT_CHECK([$CONFIG_SHELL ./script], [],
165 [[got here
166 ]], [[script: WARNING: *watch out*
167 ]])
168 AT_CHECK([die=: $CONFIG_SHELL ./script], [1],
169 [], [[script: WARNING: *watch out*
170 script: error: you're dead
171 ]])
172
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
181
182 if test x"$die" != x; then
183 AS_ERROR([you're dead])dnl
184
185 AS_ERROR([really])dnl
186
187 fi
188 echo got here
189 exec AS_MESSAGE_LOG_FD>&-
190 ]])
191
192 AT_CHECK_M4SH
193 AT_CHECK([$CONFIG_SHELL ./script], [],
194 [[got here
195 ]], [[script: WARNING: *watch out*
196 ]])
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
201 ]])
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])
204
205 AT_CLEANUP
206
207 ## ---------------- ##
208 ## LINENO support. ##
209 ## ---------------- ##
210
211 AT_SETUP([LINENO])
212 AT_KEYWORDS([m4sh])
213
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)
219
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.
226 #
227 # Use COUNTER, COUNTER-RE = [__LINENO__], [LINENO]
228 # or = [__OLINE__], [_oline__]
229 #
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).
233 #
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])
242 fi
243 ])
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
249 ]])
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
254
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])
260
261 # The reference:
262 mv stdout expout
263
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])
267
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])
273
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])
280
281 AT_CLEANUP
282
283
284 ## ---------------------- ##
285 ## LINENO stack support. ##
286 ## ---------------------- ##
287
288 AT_SETUP([LINENO stack])
289 AT_KEYWORDS([m4sh])
290
291 AT_DATA_M4SH([script.as],
292 [[AS_INIT
293
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])
302
303 AS_EXIT([0])
304 ]])
305
306 AT_CHECK_M4SH
307 AT_CHECK([$CONFIG_SHELL ./script])
308
309 AT_CLEANUP
310
311
312 ## -------- ##
313 ## AS_BOX. ##
314 ## -------- ##
315
316 # Output a framed one-line message.
317 AT_SETUP([AS@&t@_BOX])
318 AT_KEYWORDS([m4sh])
319
320 AT_DATA_M4SH([script.as],
321 [[AS_INIT
322 echo
323 AS_BOX([Send a simple message, to [email protected]])
324 AS_BOX([Send a simple message, to [email protected]], [$])
325 m4_define([msg], [$complex])
326 complex='Not quite as simple |$[1]'
327 AS_BOX([msg])
328 AS_BOX([msg], [,])
329 AS_EXIT(0)
330 ]])
331
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 [email protected] ##
337 ## -------------------------------------------- ##
338 ]])
339
340 AT_CHECK([$CONFIG_SHELL ./script], [], [[
341 ## -------------------------------------------- ##
342 ## Send a simple message, to [email protected] ##
343 ## -------------------------------------------- ##
344 ## $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ ##
345 ## Send a simple message, to [email protected] ##
346 ## $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ ##
347 ## ----------------------- ##
348 ## Not quite as simple |$1 ##
349 ## ----------------------- ##
350 ## ,,,,,,,,,,,,,,,,,,,,,,, ##
351 ## Not quite as simple |$1 ##
352 ## ,,,,,,,,,,,,,,,,,,,,,,, ##
353 ]])
354
355 AT_CLEANUP
356
357
358 # Strip path from file.
359 AT_SETUP([AS@&t@_BASENAME])
360 AT_KEYWORDS([m4sh])
361
362 AT_DATA_M4SH([script.as],
363 [[AS_INIT
364
365 m4_define([BASENAME_TEST],
366 [base=`AS_BASENAME([$1])`
367 test "$base" = "$2" ||
368 echo "basename($1) = $base instead of $2" >&2
369
370 base=`_AS_BASENAME_SED([$1])`
371 test "$base" = "$2" ||
372 echo "basename_sed($1) = $base instead of $2" >&2])
373
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)
403 ]])
404
405 AT_CHECK_M4SH
406 AT_CHECK([$CONFIG_SHELL ./script])
407
408 AT_CLEANUP
409
410
411 ## ------------ ##
412 ## AS_DIRNAME. ##
413 ## ------------ ##
414
415 # Strip filename component.
416 AT_SETUP([AS@&t@_DIRNAME])
417 AT_KEYWORDS([m4sh])
418
419 AT_DATA_M4SH([script.as],
420 [[AS_INIT
421
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
428
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
433 fi
434
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])
438
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)
463 ]])
464
465 AT_CHECK_M4SH
466 AT_CHECK([$CONFIG_SHELL ./script])
467
468 AT_CLEANUP
469
470
471 ## ---------------- ##
472 ## AS_SET_CATFILE. ##
473 ## ---------------- ##
474
475 AT_SETUP([AS@&t@_SET_CATFILE])
476 AT_KEYWORDS([m4sh])
477
478 AT_DATA_M4SH([script.as],
479 [[AS_INIT
480
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
487 fi
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
495 fi
496 ])
497
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'])
504
505 AS_EXIT(0)
506 ]])
507
508 AT_CHECK_M4SH
509 AT_CHECK([$CONFIG_SHELL ./script])
510
511 AT_CLEANUP
512
513
514 ## --------- ##
515 ## AS_ECHO. ##
516 ## --------- ##
517
518 # Print literal strings, with/without newline.
519 AT_SETUP([AS@&t@_ECHO and AS@&t@_ECHO_N])
520 AT_KEYWORDS([m4sh])
521
522 AT_DATA_M4SH([script.as],
523 [[AS_INIT
524
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
529
530 echo=`AS_ECHO_N(['$1'])`
531 test "X$echo" = 'X$1' ||
532 echo "AS@&t@_ECHO_N('"'$1'"') outputs '$echo'" >&2])
533
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
547 cd
548 e])
549 ECHO_TEST([
550 ])
551 ECHO_TEST([
552 \c])
553 AS_EXIT(0)
554 ]])
555
556 AT_CHECK_M4SH
557 AT_CHECK([$CONFIG_SHELL ./script])
558
559 AT_CLEANUP
560
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])
564
565 AT_DATA_M4SH([script.as],
566 [[AS_INIT
567
568 m4_define([ECHO_TEST],
569 [echo=`$as_echo '$1'`
570 test "X$echo" = 'X$1' ||
571 echo "\$as@&t@_echo '$1' outputs '$echo'" >&2
572
573 echo=`$as_echo_n '$1'`
574 test "X$echo" = 'X$1' ||
575 echo "\$as@&t@_echo_n '$1' outputs '$echo'" >&2])
576
577 ECHO_TEST([-])
578 ECHO_TEST([--])
579 ECHO_TEST([---...---])
580 ECHO_TEST([ ])
581 ECHO_TEST([-e])
582 ECHO_TEST([-E])
583 ECHO_TEST([-n])
584 ECHO_TEST([-n -n])
585 ECHO_TEST([-e -n])
586 ECHO_TEST([ab\ncd])
587 ECHO_TEST([abcd\c])
588 ECHO_TEST([\a\b\c\f\n\r\t\v\"\])
589 ECHO_TEST([ab
590 cd
591 e])
592 ECHO_TEST([
593 ])
594 ECHO_TEST([
595 \c])
596 AS_EXIT(0)
597 ]])
598
599 AT_CHECK_M4SH([], 0, [],
600 [[script.as:12: warning: $as_echo is obsolete; use AS@&t@_ECHO(["message"]) instead
601 m4sh.m4: _as_echo_var_prepare is expanded from...
602 m4sh.m4: as_echo is expanded from...
603 script.as:12: the top level
604 script.as:12: warning: $as_echo_n is obsolete; use AS@&t@_ECHO_N(["message"]) instead
605 m4sh.m4: _as_echo_n_var_prepare is expanded from...
606 m4sh.m4: as_echo_n is expanded from...
607 script.as:12: the top level
608 ]])
609 AT_CHECK([$CONFIG_SHELL ./script])
610
611 AT_CLEANUP
612
613
614 ## ------------------------------ ##
615 ## Redefining AS_ECHO internals. ##
616 ## ------------------------------ ##
617
618 AT_SETUP([Redefining AS@&t@_ECHO internals])
619
620 # None of the tests below do any AC_DEFINEs, so running autoheader is
621 # a waste of time, but the skeleton generated by AT_CONFIGURE_AC needs
622 # this file to exist anyway.
623 AT_DATA([config.hin])
624
625 # Defining a macro named 's', 'n', or 'c' should not affect AS_ECHO or
626 # macros that use it.
627
628 AT_CONFIGURE_AC(
629 [[m4@&t@_pushdef([s], [z])
630 m4@&t@_pushdef([n], [u])
631 m4@&t@_pushdef([c], [d])
632 AC_MSG_NOTICE([checking whether m4sugar echo works... yes])
633 AC_MSG_CHECKING([whether m4sugar echo_n works])
634 AC_MSG_RESULT([yes])
635 m4@&t@_popdef([s])
636 m4@&t@_popdef([n])
637 m4@&t@_popdef([c])
638 ]])
639
640 AT_CHECK_AUTOCONF
641 AT_CHECK_CONFIGURE([], [],
642 [[configure: checking whether m4sugar echo works... yes
643 checking whether m4sugar echo_n works... yes
644 configure: creating ./config.status
645 config.status: creating config.h
646 ]], [])
647 AT_CHECK_ENV
648 rm config.h
649
650 # Defining 's', 'n', or 'c' also should not affect use of the
651 # obsolete $as_echo and $as_echo_n macros.
652 AT_CONFIGURE_AC(
653 [[m4@&t@_pushdef([s], [z])
654 m4@&t@_pushdef([n], [u])
655 m4@&t@_pushdef([c], [d])
656 $as_echo "checking whether obsolete \$as_echo works... yes"
657 $as_echo_n "checking whether obsolete \$as_echo_n works... "
658 $as_echo yes
659 m4@&t@_popdef([s])
660 m4@&t@_popdef([n])
661 m4@&t@_popdef([c])
662 ]])
663
664 AT_CHECK_AUTOCONF([-Wno-obsolete])
665 AT_CHECK_CONFIGURE([], [],
666 [[checking whether obsolete $as@&t@_echo works... yes
667 checking whether obsolete $as@&t@_echo_n works... yes
668 configure: creating ./config.status
669 config.status: creating config.h
670 ]], [])
671 AT_CHECK_ENV
672 rm config.h
673
674 # A more realistic scenario, derived from actual code in ruby 2.7.2's
675 # configure script.
676
677 AT_CONFIGURE_AC(
678 [[AC@&t@_DEFUN([RUBY_CHECK_SIZEOF],[
679 AS@&t@_VAR_PUSHDEF([s], [ac_cv_sizeof_size])
680 AC@&t@_CACHE_CHECK([size of $1],
681 [AS@&t@_TR_SH([ac_cv_sizeof_$1])],
682 [AS@&t@_TR_SH(ac_cv_sizeof_$1)=1])
683
684 # fake use of 's' for illustrative purposes:
685 s=42
686 echo "s is defined as ${s}"
687
688 AS@&t@_VAR_POPDEF([s])
689 ])
690
691 RUBY_CHECK_SIZEOF(int)
692 echo "ac_cv_sizeof_int=${ac_cv_sizeof_int}"
693 ]])
694
695
696
697 AT_CHECK_AUTOCONF
698 AT_CHECK_CONFIGURE([], [],
699 [[checking size of int... 1
700 ac_cv_sizeof_size is defined as 42
701 ac_cv_sizeof_int=1
702 configure: creating ./config.status
703 config.status: creating config.h
704 ]], [])
705 AT_CHECK_ENV
706 rm config.h
707
708 # However, defining a macro named 'printf' _is_ expected to affect
709 # the functioning of AS_ECHO.
710
711 AT_CONFIGURE_AC(
712 [[# At this point in a configure script, defining shell functions is safe.
713 fn_printf_override () {
714 for arg; do
715 printf '+ %s\n' "$arg"
716 done
717 AS@&t@_UNSET([arg])
718 }
719 m4@&t@_pushdef([printf], [fn_printf_override])
720 AC_MSG_NOTICE([checking whether m4sugar echo works... yes])
721 AC_MSG_CHECKING([whether m4sugar echo_n works])
722 AC_MSG_RESULT([yes])
723 m4@&t@_popdef([printf])
724 ]])
725
726 AT_CHECK_AUTOCONF
727 AT_CHECK_CONFIGURE([], [],
728 [[+ %s\n
729 + configure: checking whether m4sugar echo works... yes
730 + %s
731 + checking whether m4sugar echo_n works... @&t@
732 + %s\n
733 + yes
734 configure: creating ./config.status
735 config.status: creating config.h
736 ]], [])
737 AT_CHECK_ENV
738
739 AT_CLEANUP
740
741
742 ## ----------------- ##
743 ## AS_EXECUTABLE_P. ##
744 ## ----------------- ##
745
746 # Check for executable regular files.
747 AT_SETUP([AS@&t@_EXECUTABLE_P])
748 AT_KEYWORDS([m4sh])
749
750 AT_DATA_M4SH([script.as],
751 [[AS_INIT
752
753 if AS_EXECUTABLE_P([/]); then
754 echo fail
755 else
756 echo 1
757 fi
758 cat > foo.sh <<\EOF || AS_EXIT([1])
759 #!/bin/sh
760 exit 0
761 EOF
762 # File systems like FAT tend to fake executable permissions on all files.
763 # At this point, foo.sh should be executable iff permissions are faked.
764 AS_EXECUTABLE_P([foo.sh])
765 st1=$?
766 (./foo.sh) >/dev/null 2>&1
767 st2=$?
768 case $st1:$st2 in
769 *[[1-9]]*:*[[1-9]]* | 0:0 ) echo 2 ;;
770 *) echo "fail ($st1:$st2)" ;;
771 esac
772 # Now things better be executable
773 chmod a+x foo.sh || AS_EXIT([2])
774 mkdir 'two spaces' || AS_EXIT([3])
775 'two spaces'/../foo.sh || AS_EXIT([4])
776 if AS_EXECUTABLE_P(["two spaces/../foo.sh"]); then
777 echo 3
778 else
779 echo fail
780 fi
781 ]])
782
783 AT_CHECK_M4SH
784 AT_CHECK([$CONFIG_SHELL ./script], [],
785 [[1
786 2
787 3
788 ]])
789
790 AT_CLEANUP
791
792
793
794 ## --------- ##
795 ## AS_EXIT. ##
796 ## --------- ##
797
798 # Exit scripts with given status.
799 AT_SETUP([AS@&t@_EXIT])
800 AT_KEYWORDS([m4sh AS@&t@_SET_STATUS])
801
802 AT_DATA_M4SH([script.as],
803 [[AS_INIT
804 test x${1} = xa && AS_EXIT
805 test x${1} = xb && AS_EXIT([${2}])
806 test x${1} = xc && { AS_SET_STATUS([${2}]); AS_EXIT; }
807 test x${1} = xd && trap 's=$?; echo $s; AS_EXIT([$s])' 0
808 test x${2} = xe && set -e
809 test $[#] -gt 0 || AS_EXIT
810 AS_SET_STATUS([3])
811 dnl Solaris /bin/sh 'set -e' doesn't react to failed function calls
812 test x${2} = xe \
813 && { echo 'skipping rest of test: set -e support is lousy'; exit 77; }
814 AS_SET_STATUS([4])
815 ]])
816
817 AT_CHECK_M4SH
818 AT_CHECK([$CONFIG_SHELL ./script], [1])
819 AT_CHECK([$CONFIG_SHELL ./script ''], [4])
820 AT_CHECK([$CONFIG_SHELL ./script a], [0])
821 AT_CHECK([$CONFIG_SHELL ./script b], [0])
822 AT_CHECK([$CONFIG_SHELL ./script b 0], [0])
823 AT_CHECK([$CONFIG_SHELL ./script b 2], [2])
824 AT_CHECK([$CONFIG_SHELL ./script c 0], [0])
825 AT_CHECK([$CONFIG_SHELL ./script c 2], [2])
826 AT_CHECK([$CONFIG_SHELL ./script d], [4], [[4
827 ]])
828 dnl If we got to this point without a FAIL, then AS_EXIT at least works.
829 dnl The rest of this test relies on semi-decent 'set -e' support, even
830 dnl though m4sh in general should not try to rely on it because of
831 dnl portability nightmares on what constructs are considered errors across
832 dnl various shells; therefore, an overall SKIP result is desirable on
833 dnl broken shells like Solaris /bin/sh.
834 AT_CHECK([$CONFIG_SHELL ./script '' e], [3])
835 AT_CHECK([$CONFIG_SHELL ./script d e], [3], [stdout])
836 dnl NetBSD sh fails to output on stderr here.
837 AT_CHECK([grep 3 stdout || exit 77], [], [ignore])
838
839 AT_CLEANUP
840
841
842
843 ## ------------ ##
844 ## AS_MKDIR_P. ##
845 ## ------------ ##
846
847 # Build nested dirs.
848 AT_SETUP([AS@&t@_MKDIR_P])
849 AT_KEYWORDS([m4sh])
850
851 AT_DATA_M4SH([script.as],
852 [[AS_INIT
853
854 pwd=`pwd`
855 set -e
856 # Absolute
857 AS_MKDIR_P(["$pwd/1/2/3/4/5/6"])
858 test -d "$pwd/1/2/3/4/5/6" ||
859 AS_ERROR([$pwd/1/2/3/4/5/6 has not been properly created])
860 # Relative
861 AS_MKDIR_P(["a/b/c/d/e/f"])
862 test -d a/b/c/d/e/f ||
863 AS_ERROR([a/b/c/d/e/f has not been properly created])
864 AS_EXIT(0)
865 ]])
866
867 AT_CHECK_M4SH
868 AT_CHECK([$CONFIG_SHELL ./script])
869
870 AT_CLEANUP
871
872
873
874
875 ## -------------------- ##
876 ## AS_VERSION_COMPARE. ##
877 ## -------------------- ##
878
879 # Three-way version comparison.
880 AT_SETUP([AS@&t@_VERSION_COMPARE])
881 AT_KEYWORDS([m4sh])
882
883 AT_DATA_M4SH([script.as],
884 [[AS_INIT
885
886 m4_define([VERSION_COMPARE_TEST],
887 [AS_VERSION_COMPARE([$1], [$3], [result='<'], [result='='], [result='>'])
888 test "X$result" = "X$2" ||
889 AS_ERROR([version $1 $result $3; should be $1 $2 $3])
890 m4_if([$1], <,
891 [AS_VERSION_COMPARE([$3], [$1], [result='<'], [result='='], [result='>'])
892 test "X$result" = "X>" ||
893 AS_ERROR([version $3 $result $1; should be $3 > $1])])])
894
895 VERSION_COMPARE_TEST([], =, [])
896 VERSION_COMPARE_TEST([1.0], =, [1.0])
897 VERSION_COMPARE_TEST([alpha-1.0], =, [alpha-1.0])
898
899 # These tests are taken from libc/string/tst-svc.expect.
900 tst_svc_expect='
901 000 001 00 00a 01 01a 0 0a 2.8 2.8-0.4 20 21 22 212 CP037 CP345 CP1257
902 foo foo-0.4 foo-0.4a foo-0.4b foo-0.5 foo-0.10.5 foo-3.01 foo-3.0
903 foo-3.0.0 foo-3.0.1 foo-3.2 foo-3.10 foo00 foo0
904 '
905 test1=''
906 for test2 in $tst_svc_expect; do
907 VERSION_COMPARE_TEST([$test1], <, [$test2])
908 test1=$test2
909 done
910
911 AS_EXIT(0)
912 ]])
913
914 AT_CHECK_M4SH
915 AT_CHECK([$CONFIG_SHELL ./script])
916
917 AT_CLEANUP
918
919
920
921
922 ## ------- ##
923 ## as_me. ##
924 ## ------- ##
925
926 AT_SETUP([as_me])
927 AT_KEYWORDS([m4sh])
928
929 AT_DATA_M4SH([script.as],
930 [[AS_INIT
931 AS_ME_PREPARE
932 test "$as_me" = script || AS_ECHO([["incorrect value of \$as_me: $as_me"]])
933 ]])
934
935 AT_CHECK_M4SH
936 AT_CHECK([$CONFIG_SHELL ./script])
937
938 AT_CLEANUP
939
940
941
942
943 ## ----------------------------- ##
944 ## Negated classes in globbing. ##
945 ## ----------------------------- ##
946
947 # According to https://www.in-ulm.de/~mascheck/bourne/, all shells with
948 # functions also support '[!...]'. But '[^...]' is not universally supported.
949
950 AT_SETUP([Negated classes in globbing])
951 AT_KEYWORDS([m4sh])
952
953 AT_DATA_M4SH([script.as],
954 [[AS_INIT
955
956 case 'with!two!bangs' in
957 *[[!a-z]]*) ;;
958 *) AS_ERROR([['*[!a-z]*' didn't match 'with!two!bangs']]);;
959 esac
960
961 case without in
962 *[[!a-z]]*) AS_ERROR([['*[!a-z]*' matched 'without']]);;
963 esac
964 ]])
965
966 AT_CHECK_M4SH
967 AT_CHECK([$CONFIG_SHELL ./script])
968
969 AT_CLEANUP
970
971 ## ---------------------------- ##
972 ## Null variable substitution. ##
973 ## ---------------------------- ##
974
975 # According to https://www.in-ulm.de/~mascheck/bourne/, all shells with
976 # functions also support '${a:-b}'.
977
978 AT_SETUP([Null variable substitution])
979 AT_KEYWORDS([m4sh])
980
981 AT_DATA_M4SH([script.as],
982 [[AS_INIT
983
984 AS_UNSET([a])
985 b=
986 c=.
987 case ${a:-x}${b:-y}${c:-z} in
988 xy.) ;;
989 *) exit 1 ;;
990 esac
991 case ${a-x}${b-y}${c-z} in
992 x.) ;;
993 *) exit 2 ;;
994 esac
995
996 case ${a+x}${b+y}${c+z} in
997 yz) ;;
998 *) exit 3 ;;
999 esac
1000 case ${a:+x}${b:+y}${c:+z} in
1001 z) ;;
1002 *) exit 4 ;;
1003 esac
1004
1005 case ${a=x}${b=y}${c=z} in
1006 x.) ;;
1007 *) exit 5 ;;
1008 esac
1009 AS_UNSET([a])
1010 case ${a:=x}${b:=y}${c:=z} in
1011 xy.) ;;
1012 *) exit 6 ;;
1013 esac
1014 case $a$b$c in
1015 xy.) ;;
1016 *) exit 7 ;;
1017 esac
1018 AS_UNSET([a])
1019 b=
1020
1021 (: ${a?oops}; echo fail) 2>err && exit 8
1022 grep oops err >/dev/null || exit 9
1023 test "${b?oops}" = '' || exit 10
1024 test "${c?oops}" = . || exit 11
1025 (: ${a:?oops}; echo fail) 2>err && exit 12
1026 grep oops err >/dev/null || exit 13
1027 (: ${b:?oops}; echo fail) 2>err && exit 14
1028 grep oops err >/dev/null || exit 15
1029 test "${c:?oops}" = . || exit 16
1030 ]])
1031
1032 AT_CHECK_M4SH
1033 AT_CHECK([$CONFIG_SHELL ./script])
1034
1035 AT_CLEANUP
1036
1037
1038 ## ------------------- ##
1039 ## Functions Support. ##
1040 ## ------------------- ##
1041
1042 # All m4sh scripts require function support.
1043
1044 AT_SETUP([Functions Support])
1045 AT_KEYWORDS([m4sh])
1046
1047 AT_DATA_M4SH([script.as],
1048 [[AS_INIT
1049 AS_LINENO_PREPARE
1050
1051 func_return () {
1052 (exit $1)
1053 }
1054
1055 func_success () {
1056 func_return 0
1057 }
1058
1059 func_failure () {
1060 func_return 1
1061 }
1062
1063 if func_success; then
1064 if func_failure; then
1065 AS_ERROR([func_failure passed])
1066 fi
1067 else
1068 AS_ERROR([func_success failed])
1069 fi
1070 ]])
1071
1072 AT_CHECK_M4SH
1073 AT_CHECK([$CONFIG_SHELL ./script])
1074
1075 AT_CLEANUP
1076
1077
1078
1079
1080 ## ------------------------------ ##
1081 ## Functions and return Support. ##
1082 ## ------------------------------ ##
1083
1084 # All m4sh scripts require working return within functions.
1085
1086 AT_SETUP([Functions and return Support])
1087 AT_KEYWORDS([m4sh])
1088
1089 AT_DATA_M4SH([script.as],
1090 [[AS_INIT
1091 AS_LINENO_PREPARE
1092
1093 func_success () {
1094 return 0
1095 }
1096
1097 func_failure () {
1098 return 1
1099 }
1100
1101 if func_success; then
1102 if func_failure; then
1103 AS_ERROR([func_failure passed])
1104 fi
1105 else
1106 AS_ERROR([func_success failed])
1107 fi
1108 ]])
1109
1110 AT_CHECK_M4SH
1111 AT_CHECK([$CONFIG_SHELL ./script])
1112
1113 AT_CLEANUP
1114
1115
1116 ## --------------------------- ##
1117 ## Nested AS_REQUIRE_SHELL_FN. ##
1118 ## --------------------------- ##
1119
1120 # Hypothesis: M4sh expands nested AS_REQUIRE_SHELL_FN
1121 # separately.
1122
1123 AT_SETUP([Nested AS@&t@_REQUIRE_SHELL_FN])
1124 AT_KEYWORDS([m4sh])
1125
1126 AT_DATA_M4SH([script.as], [[dnl
1127 m4_define([INIT], [oops])dnl
1128 AS_INIT
1129
1130 m4_defun([TEST_FUNC2_BODY], [
1131 :
1132 ])
1133
1134 m4_defun([TEST_FUNC1_BODY], [
1135 AS_REQUIRE_SHELL_FN([test_func2], [], [TEST_FUNC2_BODY])
1136 :
1137 ])
1138
1139 AS_REQUIRE_SHELL_FN([test_func1], [], [TEST_FUNC1_BODY])
1140 test_func2
1141 ]])
1142
1143 AT_CHECK_M4SH
1144 AT_CHECK([$CONFIG_SHELL ./script])
1145
1146 AT_CLEANUP
1147
1148
1149 ## ------------------- ##
1150 ## Nested AS_REQUIRE. ##
1151 ## ------------------- ##
1152
1153 # Hypothesis: M4sh expands the requirements of AS_REQUIRE in the
1154 # requested diversion, even if other AS_REQUIREs are interleaved.
1155
1156 AT_SETUP([Nested AS@&t@_REQUIRE])
1157 AT_KEYWORDS([m4sh])
1158
1159 AT_DATA_M4SH([script.as], [[dnl
1160 AS_INIT
1161
1162 m4_defun([in_fn_diversion], still_in_m4sh_init_fn=yes)
1163 m4_defun([not_in_fn_diversion], still_in_m4sh_init_fn=no)
1164
1165 m4_defun([NESTED], [nested_require_in_fn_diversion=$still_in_m4sh_init_fn])
1166
1167 m4_defun([OUTER], [AS_REQUIRE([NESTED])dnl
1168 outer_require_in_fn_diversion=$still_in_m4sh_init_fn])
1169
1170 m4_defun([test_init], [
1171 AS_REQUIRE([in_fn_diversion], , [M4SH-INIT-FN])
1172 AS_REQUIRE([OUTER], , [M4SH-INIT-FN])
1173 AS_REQUIRE([not_in_fn_diversion], , [M4SH-INIT-FN])
1174 ])
1175
1176 test_init
1177 if test $outer_require_in_fn_diversion != yes; then AS_EXIT([1]); fi
1178 if test $nested_require_in_fn_diversion != no; then AS_EXIT([1]); fi
1179 ]])
1180
1181 AT_CHECK_M4SH
1182 AT_CHECK([$CONFIG_SHELL ./script])
1183
1184 AT_CLEANUP
1185
1186
1187 ## ------------------------------------ ##
1188 ## AS_REQUIRE_SHELL_FN and m4_require. ##
1189 ## ------------------------------------ ##
1190
1191 # Hypothesis: M4sh expands the requirements of AS_REQUIRE_SHELL_FN
1192 # in M4SH-INIT-FN. This changed after Autoconf 2.63.
1193
1194 AT_SETUP([AS@&t@_REQUIRE_SHELL_FN and m4@&t@_require])
1195 AT_KEYWORDS([m4sh])
1196
1197 AT_DATA_M4SH([script.as], [[dnl
1198 AS_INIT
1199
1200 m4_defun([in_m4_sh_init], still_in_m4sh_init=yes)
1201 m4_defun([not_in_m4_sh_init], still_in_m4sh_init=no)
1202
1203 m4_defun([error_if_emitted_in_m4sh_init], [
1204 if test x$still_in_m4sh_init = xyes; then
1205 AS_ERROR([requirement emitted in M4SH-INIT])
1206 fi
1207 ])
1208
1209 m4_defun([TEST_FUNC_BODY], [
1210 m4_require([error_if_emitted_in_m4sh_init])
1211 : echo in shell function, with parameter = [$]1
1212 ])
1213
1214
1215 m4_defun([test_init], [
1216 AS_REQUIRE([in_m4_sh_init], , [M4SH-INIT-FN])
1217 AS_REQUIRE_SHELL_FN([test_func], [], [TEST_FUNC_BODY])
1218 AS_REQUIRE([not_in_m4_sh_init])
1219 ])
1220
1221 test_init
1222 test_func parameter1
1223 ]])
1224
1225 AT_CHECK_M4SH
1226 AT_CHECK([$CONFIG_SHELL ./script])
1227
1228 AT_CLEANUP
1229
1230
1231 ## -------------- ##
1232 ## AS_HELP_STRING ##
1233 ## -------------- ##
1234
1235 AT_SETUP([AS@&t@_HELP_STRING])
1236 AT_KEYWORDS([m4sh m4@&t@_text_wrap m4@&t@_expand])
1237
1238 AT_DATA_M4SH([script.as],
1239 [[AS_INIT
1240
1241 echo "AS_HELP_STRING([--an-option],[some text])"
1242 echo "AS_HELP_STRING([--another-much-longer-option],
1243 [some other text which should wrap at our default of 80 characters.])"
1244 echo "AS_HELP_STRING([--fooT=barT], [foo bar])"
1245 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@], [foo bar])"
1246 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@123456789], [foo bar])"
1247 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@1234567890], [foo bar])"
1248 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@12345678901], [foo bar])"
1249 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@123456789012], [foo bar])"
1250 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@1234567890123], [foo bar])"
1251 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@],
1252 [some other text which should wrap at our default of 80 characters.])"
1253 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@123456789],
1254 [some other text which should wrap at our default of 80 characters.])"
1255 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@1234567890],
1256 [some other text which should wrap at our default of 80 characters.])"
1257 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@12345678901],
1258 [some other text which should wrap at our default of 80 characters.])"
1259 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@123456789012],
1260 [some other text which should wrap at our default of 80 characters.])"
1261 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@1234567890123],
1262 [some other text which should wrap at our default of 80 characters.])"
1263 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@],
1264 [some other @<][:@ex@:][>@ which should wrap at our default of 80 characters.])"
1265 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@123456789],
1266 [some other @<][:@ex@:][>@ which should wrap at our default of 80 characters.])"
1267 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@1234567890],
1268 [some other @<][:@ex@:][>@ which should wrap at our default of 80 characters.])"
1269 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@12345678901],
1270 [some other @<][:@ex@:][>@ which should wrap at our default of 80 characters.])"
1271 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@123456789012],
1272 [some other @<][:@ex@:][>@ which should wrap at our default of 80 characters.])"
1273 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@1234567890123],
1274 [some other @<][:@ex@:][>@ which should wrap at our default of 80 characters.])"
1275 echo "AS_HELP_STRING([[--foo[=bar]]],
1276 [some other t[]t which should wrap at our default of 80 characters.])"
1277 echo "AS_HELP_STRING([[--foo[=bar]123456789]],
1278 [some other t[]t which should wrap at our default of 80 characters.])"
1279 echo "AS_HELP_STRING([[--foo[=bar]1234567890]],
1280 [some other t[]t which should wrap at our default of 80 characters.])"
1281 echo "AS_HELP_STRING([[--foo[=bar]12345678901]],
1282 [some other t[]t which should wrap at our default of 80 characters.])"
1283 echo "AS_HELP_STRING([[--foo[=bar]123456789012]],
1284 [some other t[]t which should wrap at our default of 80 characters.])"
1285 echo "AS_HELP_STRING([[--foo[=bar]1234567890123]],
1286 [some other t[]t which should wrap at our default of 80 characters.])"
1287 m4_define([mac], [MACRO])dnl
1288 echo "AS_HELP_STRING([--mac], [mac])"
1289 echo "AS_HELP_STRING([--o1, --o2], [two
1290 options, one description])"
1291 echo "AS_HELP_STRING([[[--o3, --o4]]], [comma inside literal quoting])"
1292 echo "AS_HELP_STRING([--tune1], [check out the tuned formatting],
1293 [ ])"
1294 echo "AS_HELP_STRING([--tune2], [check out the tuned formatting],
1295 [12])"
1296 echo "AS_HELP_STRING([--tune3], [check out the tuned formatting],
1297 [], [40])"
1298 echo "AS_HELP_STRING([--tune4], [check out the tuned formatting],
1299 [12], [40])"
1300 ]])
1301
1302 AT_CHECK_M4SH
1303 AT_CHECK([$CONFIG_SHELL ./script], [0],
1304 [[ --an-option some text
1305 --another-much-longer-option
1306 some other text which should wrap at our default of
1307 80 characters.
1308 --fooT=barT foo bar
1309 --foo[=bar] foo bar
1310 --foo[=bar]123456789 foo bar
1311 --foo[=bar]1234567890 foo bar
1312 --foo[=bar]12345678901 foo bar
1313 --foo[=bar]123456789012 foo bar
1314 --foo[=bar]1234567890123
1315 foo bar
1316 --foo[=bar] some other text which should wrap at our default of
1317 80 characters.
1318 --foo[=bar]123456789 some other text which should wrap at our default of
1319 80 characters.
1320 --foo[=bar]1234567890 some other text which should wrap at our default of
1321 80 characters.
1322 --foo[=bar]12345678901 some other text which should wrap at our default of
1323 80 characters.
1324 --foo[=bar]123456789012 some other text which should wrap at our default of
1325 80 characters.
1326 --foo[=bar]1234567890123
1327 some other text which should wrap at our default of
1328 80 characters.
1329 --foo[=bar] some other [ex] which should wrap at our default of
1330 80 characters.
1331 --foo[=bar]123456789 some other [ex] which should wrap at our default of
1332 80 characters.
1333 --foo[=bar]1234567890 some other [ex] which should wrap at our default of
1334 80 characters.
1335 --foo[=bar]12345678901 some other [ex] which should wrap at our default of
1336 80 characters.
1337 --foo[=bar]123456789012 some other [ex] which should wrap at our default of
1338 80 characters.
1339 --foo[=bar]1234567890123
1340 some other [ex] which should wrap at our default of
1341 80 characters.
1342 --foo[=bar] some other t[]t which should wrap at our default of
1343 80 characters.
1344 --foo[=bar]123456789 some other t[]t which should wrap at our default of
1345 80 characters.
1346 --foo[=bar]1234567890 some other t[]t which should wrap at our default of
1347 80 characters.
1348 --foo[=bar]12345678901 some other t[]t which should wrap at our default of
1349 80 characters.
1350 --foo[=bar]123456789012 some other t[]t which should wrap at our default of
1351 80 characters.
1352 --foo[=bar]1234567890123
1353 some other t[]t which should wrap at our default of
1354 80 characters.
1355 --MACRO mac
1356 --o1, --o2 two options, one description
1357 [--o3, --o4] comma inside literal quoting
1358 --tune1 check out the tuned formatting
1359 --tune2 check out the tuned formatting
1360 --tune3 check out the
1361 tuned
1362 formatting
1363 --tune4 check out the tuned
1364 formatting
1365 ]])
1366
1367 AT_CLEANUP
1368
1369
1370 ## ------------------- ##
1371 ## AS_IF and AS_CASE. ##
1372 ## ------------------- ##
1373
1374 AT_SETUP([AS@&t@_IF and AS@&t@_CASE])
1375 AT_KEYWORDS([m4sh m4@&t@_map_args_pair])
1376
1377 AT_DATA_M4SH([script.as], [[dnl
1378 AS_INIT
1379 # Syntax checks: cope with empty arguments.
1380 AS_IF([:], [], [echo wrong])
1381 AS_IF([:], [echo one], [echo wrong])
1382 AS_IF([false], [echo wrong], [echo two])
1383 AS_IF([false], [echo wrong])
1384 # n-ary version
1385 AS_IF([false], [echo wrong],
1386 [:], [echo three])
1387 AS_IF([false], [echo wrong],
1388 [:], [echo four],
1389 [echo wrong])
1390 AS_IF([false], [echo wrong],
1391 [false], [echo wrong])
1392 AS_IF([false], [echo wrong],
1393 [false], [echo wrong],
1394 [echo five])
1395 AS_IF([false], [echo wrong],
1396 [false], [echo wrong],
1397 [:], [echo six],
1398 [echo wrong])
1399 AS_CASE([foo])
1400 AS_CASE([foo], [echo seven])
1401 AS_CASE([foo],
1402 [foo], [echo eight],
1403 [echo wrong])
1404 AS_CASE([foo],
1405 [foo], [echo nine],
1406 [*], [echo wrong])
1407 AS_CASE([foo],
1408 [bar], [echo wrong],
1409 [foo], [echo ten],
1410 [*], [echo wrong])
1411
1412 # check for nesting, lists, and side effects, and quoting robustness
1413 empty=
1414 AS_IF([AS_IF([$empty], [echo eleven])]) && AS_CASE([foo]) && echo twelve
1415 rm -f file
1416 AS_IF([touch file; false]) && echo thirteen
1417 test -f file && echo fourteen
1418 rm -f file
1419 AS_CASE([`touch file; false`]) && test -f file && echo fifteen
1420 dnl The next line is badly underquoted; don't intentionally copy this style.
1421 AS_CASE([foo], [foo], m4_do(AS_CASE([bar], [bar], [echo sixteen])))
1422 dnl Handle blank arguments.
1423 AS_IF([false], [:], [ ]) && AS_CASE([foo], [foo], []
1424 ) && echo seventeen
1425 m4_define([empty])AS_IF([:], [empty]
1426 ) && AS_IF([false], [], [empty]
1427 ) || AS_CASE([foo], [foo], [empty]) && echo eighteen
1428 dnl Allow for users that don't know to avoid trailing whitespace
1429 AS_IF([:
1430 ], [echo nineteen])
1431 set -e
1432 AS_IF([false], [], [echo twenty])
1433 set +e
1434
1435 # check that require works correctly
1436 m4_for([n], 1, 9, [],
1437 [m4_defun([FOO]n, [foo]n[=]n)dnl
1438 m4_defun([BAR]n,
1439 [m4_require([FOO]]n[)dnl
1440 bar]n[=]n)[]dnl
1441 ])
1442
1443 AS_IF([:], [BAR1])
1444 echo "foo1=$foo1 bar1=$bar1"
1445 AS_IF([:], [], [BAR2])
1446 echo "foo2=$foo2 bar2=$bar2"
1447 AS_IF([false], [BAR3])
1448 echo "foo3=$foo3 bar3=$bar3"
1449 AS_IF([false], [], [BAR4])
1450 echo "foo4=$foo4 bar4=$bar4"
1451 AS_CASE([x], [x], [BAR5])
1452 echo "foo5=$foo5 bar5=$bar5"
1453 AS_CASE([x], [y], [BAR6])
1454 echo "foo6=$foo6 bar6=$bar6"
1455 AS_CASE([x],
1456 [x], [:],
1457 [BAR7])
1458 echo "foo7=$foo7 bar7=$bar7"
1459 AS_CASE([x],
1460 [y], [:],
1461 [BAR8])
1462 echo "foo8=$foo8 bar8=$bar8"
1463 AS_CASE([x],
1464 [y], [:],
1465 [x], [BAR9])
1466 echo "foo9=$foo9 bar9=$bar9"
1467 ]])
1468
1469 AT_CHECK_M4SH
1470 AT_CHECK([$CONFIG_SHELL ./script], [0], [[one
1471 two
1472 three
1473 four
1474 five
1475 six
1476 seven
1477 eight
1478 nine
1479 ten
1480 eleven
1481 twelve
1482 thirteen
1483 fourteen
1484 fifteen
1485 sixteen
1486 seventeen
1487 eighteen
1488 nineteen
1489 twenty
1490 foo1=1 bar1=1
1491 foo2=2 bar2=
1492 foo3=3 bar3=
1493 foo4=4 bar4=4
1494 foo5=5 bar5=5
1495 foo6=6 bar6=
1496 foo7=7 bar7=
1497 foo8=8 bar8=8
1498 foo9=9 bar9=9
1499 ]])
1500
1501 dnl stress test for large number of conditionals
1502 dnl too large, and we start tickling shell bugs
1503 m4_pushdef([limit], [1000])dnl
1504 AT_DATA_M4SH([script.as], [[dnl
1505 AS_INIT
1506 AS_IF(m4_shift(m4_for([i], [1], ]limit[, [], [, test $[1] = i, echo i])))
1507 AS_IF(m4_shift(m4_for([i], [1], ]limit[, [], [, test $[1] = i, echo i])),
1508 [echo default])
1509 AS_CASE([$[1]]m4_for([i], [1], ]limit[, [], [, i, echo i]))
1510 AS_CASE([$[1]]m4_for([i], [1], ]limit[, [], [, i, echo i]), [echo default])
1511 ]])
1512
1513 dnl Add --force so autom4te doesn't think 'script' is still up to date.
1514 AT_CHECK_M4SH([--force])
1515 AT_CHECK([$CONFIG_SHELL ./script 1], [0], [[1
1516 1
1517 1
1518 1
1519 ]])
1520 AT_CHECK([$CONFIG_SHELL ./script limit], [0], [limit
1521 limit
1522 limit
1523 limit
1524 ])
1525 AT_CHECK([$CONFIG_SHELL ./script default], [0], [[default
1526 default
1527 ]])
1528 m4_popdef([limit])
1529
1530 AT_CLEANUP
1531
1532
1533 ## -------- ##
1534 ## AS_FOR. ##
1535 ## -------- ##
1536
1537 AT_SETUP([AS@&t@_FOR])
1538 AT_KEYWORDS([m4sh])
1539
1540 AT_DATA_M4SH([script.as], [[dnl
1541 AS_INIT
1542
1543 # Simple checks.
1544 AS_FOR([m4var], [shvar], [a],
1545 [echo "m4var $shvar"])
1546 AS_FOR([m4var], [shvar], [b c],
1547 [echo "m4var $shvar"])
1548 list='d e'
1549 AS_FOR([m4var], [shvar], [$list],
1550 [echo "m4var $shvar"])
1551 AS_FOR([m4var], [shvar], ["$list"],
1552 [echo "m4var $shvar"])
1553 AS_FOR([m4var], [shvar], ['$list'],
1554 [echo "m4var $shvar"])
1555 AS_FOR([m4var], [shvar], [\'],
1556 [echo "m4var $shvar"])
1557
1558 # Syntax checks: cope with empty/blank arguments.
1559 set f g
1560 AS_FOR([], [shvar], [],
1561 [echo "m4_defn([]) $shvar"])
1562 rm -f file
1563 AS_FOR([], [shvar], [`touch file`])
1564 test -f file || exit 1
1565 AS_FOR([], [shvar], [], [ ])
1566 m4_define([empty])AS_FOR([], [shvar], [], [empty])
1567
1568 # Check that break works.
1569 while :
1570 do
1571 AS_FOR([m4var], [shvar], [h i],
1572 [echo "m4var"; break 2])
1573 exit 1
1574 done
1575 while :
1576 do
1577 AS_FOR([m4var], [shvar], [j],
1578 [echo "m4var"; break 2])
1579 exit 1
1580 done
1581 ]])
1582
1583 AT_CHECK_M4SH
1584 AT_CHECK([$CONFIG_SHELL ./script], [0], [[a a
1585 b b
1586 c c
1587 d d
1588 e e
1589 d e d e
1590 $list $list
1591 ' '
1592 f f
1593 g g
1594 h
1595 j
1596 ]])
1597
1598 AT_CLEANUP
1599
1600
1601 ## --------------- ##
1602 ## AS_LITERAL_IF. ##
1603 ## --------------- ##
1604
1605 AT_SETUP([AS@&t@_LITERAL_IF])
1606 AT_KEYWORDS([m4sh AS@&t@_LITERAL_WORD_IF AS@&t@_LITERAL_HEREDOC_IF])
1607
1608 AT_DATA_M4SH([script.as], [[dnl
1609 AS_INIT
1610 echo AS_LITERAL_IF([lit], [ok], [ERR]) 1
1611 echo AS_LITERAL_IF([l-/.it], [ok], [ERR]) 2
1612 echo AS_LITERAL_IF([l''it], [ERR], [ok]) 3
1613 echo AS_LITERAL_IF([l$it], [ERR], [ok]) 4
1614 echo AS_LITERAL_IF([l$it], [ERR1], [ERR2], [ok]) 5
1615 echo AS_LITERAL_IF([l${it}], [ERR1], [ERR2], [ok]) 6
1616 echo AS_LITERAL_IF([l`case a in b) ;; esac`it], [ERR], [ok]) 7
1617 echo AS_LITERAL_IF([l`case a in b) ;; esac`it], [ERR1], [ok], [ERR2]) 8
1618 m4_define([mac], [l-/.it])
1619 echo AS_LITERAL_IF([mac], [ok], [ERR]) 9
1620 echo AS_LITERAL_IF([mac($, ``)], [ok], [ERR]) 10
1621 m4_define([mac], [l$it])
1622 echo AS_LITERAL_IF([mac], [ERR], [ok]) 11
1623 echo AS_LITERAL_IF([mac], [ERR1], [ERR2], [ok]) 12
1624 m4_define([mac], [l``it])
1625 echo AS_LITERAL_IF([mac], [ERR], [ok]) 13
1626 echo AS_LITERAL_IF([mac], [ERR1], [ok], [ERR2]) 14
1627 echo AS_LITERAL_IF([ a ][
1628 b], [ok], [ERR]) 15
1629 echo AS_LITERAL_WORD_IF([ a ][
1630 b], [ERR], [ok]) 16
1631 echo AS_LITERAL_HEREDOC_IF([ a ][
1632 b], [ok], [ERR]) 17
1633 echo AS_LITERAL_IF([(a)], [ERR], [ok]) 18
1634 echo AS_LITERAL_WORD_IF([(a)], [ERR], [ok]) 19
1635 echo AS_LITERAL_HEREDOC_IF([(a)], [ok], [ERR]) 20
1636 echo AS_LITERAL_IF([@S|@a], [ERR], [ok]) 21
1637 echo AS_LITERAL_WORD_IF([@S|@a], [ERR], [ok]) 22
1638 echo AS_LITERAL_HEREDOC_IF([@S|@a], [ERR], [ok]) 23
1639 echo AS_LITERAL_IF([${a+b}], [ERR1], [ok], [ERR2]) 24
1640 echo AS_LITERAL_IF([${a=b}], [ERR1], [ok], [ERR2]) 25
1641 echo AS_LITERAL_IF([a+b], [ok], [ERR1], [ERR2]) 26
1642 echo AS_LITERAL_IF([a=b], [ok], [ERR1], [ERR2]) 27
1643 ]])
1644
1645 AT_CHECK_M4SH
1646 AT_CHECK([$CONFIG_SHELL ./script], [],
1647 [[ok 1
1648 ok 2
1649 ok 3
1650 ok 4
1651 ok 5
1652 ok 6
1653 ok 7
1654 ok 8
1655 ok 9
1656 ok 10
1657 ok 11
1658 ok 12
1659 ok 13
1660 ok 14
1661 ok 15
1662 ok 16
1663 ok 17
1664 ok 18
1665 ok 19
1666 ok 20
1667 ok 21
1668 ok 22
1669 ok 23
1670 ok 24
1671 ok 25
1672 ok 26
1673 ok 27
1674 ]])
1675
1676 AT_CLEANUP
1677
1678
1679 ## --------------------- ##
1680 ## AS_TR_SH, AS_TR_CPP. ##
1681 ## --------------------- ##
1682
1683 AT_SETUP([AS@&t@_TR_SH and AS@&t@_TR_CPP])
1684
1685 AT_DATA_M4SH([script.as], [[dnl
1686 AS_INIT
1687 m4_define([abc], [hI])m4_define([ABC], [Hi])
1688 m4_define([hi], [oops])m4_define([HI], [OOPS])
1689 echo AS_TR_SH(abc) AS_TR_SH(aBc) AS_TR_SH(ABC)
1690 echo AS_TR_SH([abc]) AS_TR_SH([aBc]) AS_TR_SH([ABC])
1691 echo AS_TR_SH([[abc]]) AS_TR_SH([[aBc]]) AS_TR_SH([[ABC]])
1692 echo AS_TR_CPP(abc) AS_TR_CPP(aBc) AS_TR_CPP(ABC)
1693 echo AS_TR_CPP([abc]) AS_TR_CPP([aBc]) AS_TR_CPP([ABC])
1694 echo AS_TR_CPP([[abc]]) AS_TR_CPP([[aBc]]) AS_TR_CPP([[ABC]])
1695 echo ===
1696 [var=abc vAr=aBc VAR=ABC]
1697 echo AS_TR_SH($var) AS_TR_SH($vAr) AS_TR_SH($VAR)
1698 echo AS_TR_SH([$var]) AS_TR_SH([$vAr]) AS_TR_SH([$VAR])
1699 echo AS_TR_SH([[$var]]) AS_TR_SH([[$vAr]]) AS_TR_SH([[$VAR]])
1700 echo AS_TR_CPP($var) AS_TR_CPP($vAr) AS_TR_CPP($VAR)
1701 echo AS_TR_CPP([$var]) AS_TR_CPP([$vAr]) AS_TR_CPP([$VAR])
1702 echo AS_TR_CPP([[$var]]) AS_TR_CPP([[$vAr]]) AS_TR_CPP([[$VAR]])
1703 echo ===
1704 echo AS_TR_SH(`echo abc`) AS_TR_SH(`echo aBc`) AS_TR_SH(`echo ABC`)
1705 echo AS_TR_SH([`echo abc`]) AS_TR_SH([`echo aBc`]) AS_TR_SH([`echo ABC`])
1706 echo AS_TR_SH([[`echo abc`]]) AS_TR_SH([[`echo aBc`]]) AS_TR_SH([[`echo ABC`]])
1707 echo AS_TR_CPP(`echo abc`) AS_TR_CPP(`echo aBc`) AS_TR_CPP(`echo ABC`)
1708 echo AS_TR_CPP([`echo abc`]) AS_TR_CPP([`echo aBc`]) AS_TR_CPP([`echo ABC`])
1709 echo AS_TR_CPP([[`echo abc`]]) AS_TR_CPP([[`echo aBc`]]) AS_TR_CPP([[`echo ABC`]])
1710 echo ===
1711 # start here
1712 echo AS_TR_SH([a.b/c+*-=])
1713 echo AS_TR_CPP([a.b/c+*-=])
1714 var=a.b/c+*-=
1715 echo AS_TR_SH([$var])
1716 echo AS_TR_CPP([$var])
1717 m4_define([macro], [a.b/c+*-=])
1718 echo AS_TR_SH([macro])
1719 echo AS_TR_CPP([macro])
1720 ]])
1721
1722 AT_CHECK_M4SH
1723 AT_CHECK([$CONFIG_SHELL ./script], [],
1724 [[hI aBc Hi
1725 hI aBc Hi
1726 abc aBc ABC
1727 HI ABC HI
1728 HI ABC HI
1729 ABC ABC ABC
1730 ===
1731 abc aBc ABC
1732 abc aBc ABC
1733 abc aBc ABC
1734 ABC ABC ABC
1735 ABC ABC ABC
1736 ABC ABC ABC
1737 ===
1738 hI aBc Hi
1739 hI aBc Hi
1740 abc aBc ABC
1741 HI ABC HI
1742 HI ABC HI
1743 ABC ABC ABC
1744 ===
1745 a_b_cpp__
1746 A_B_C_P__
1747 a_b_cpp__
1748 A_B_C_P__
1749 a_b_cpp__
1750 A_B_C_P__
1751 ]])
1752
1753 dnl Check that of the last 6 macros, only 2 needed command substitution.
1754 dnl This test abuses our knowledge of m4sh internals a bit; oh well.
1755 AT_CHECK([tab=' ' # a single ASCII tab character
1756 sed -n '/start here/,$ {
1757 /`.*`/p
1758 }' script | wc -l | sed "s/[[ $tab]]//g" ], [], [[2
1759 ]])
1760
1761 AT_CLEANUP
1762
1763
1764 ## ---------- ##
1765 ## AS_VAR_*. ##
1766 ## ---------- ##
1767
1768 AT_SETUP([AS@&t@_VAR basics])
1769 AT_KEYWORDS([m4sh AS@&t@_VAR_COPY AS@&t@_VAR_SET AS@&t@_VAR_GET])
1770 AT_KEYWORDS([AS@&t@_VAR_TEST_SET AS@&t@_VAR_SET_IF AS@&t@_VAR_IF])
1771 AT_KEYWORDS([AS@&t@_VAR_PUSHDEF AS@&t@_VAR_POPDEF])
1772
1773 AT_DATA_M4SH([script.as], [[dnl
1774 AS_INIT
1775 m4_define([with], [WITH])
1776 # Literals.
1777 dnl AS_VAR_SET_IF also covers AS_VAR_TEST_SET
1778 AS_VAR_SET_IF([foo], [echo oops]) && echo ok
1779 AS_VAR_IF([foo], [], [echo ok], [echo oops])
1780 foo=
1781 AS_VAR_SET_IF([foo], [echo ok])
1782 AS_VAR_SET([foo], ['\a "weird" `value` with; $fun '\''characters
1783 ']) # 'font-lock
1784 AS_VAR_COPY([bar], [foo])
1785 AS_ECHO(["$bar-"])
1786 AS_ECHO(["AS_VAR_GET([foo])-"])
1787 AS_VAR_SET_IF([foo], [echo ok], [echo oops])
1788 AS_VAR_IF([foo], [string], [echo oops]) && echo ok
1789 AS_VAR_PUSHDEF([tmp], [foo])
1790 AS_VAR_IF([tmp], ['\a "weird" `value` with; $fun '\''characters
1791 '], [echo ok], [echo oops]) # 'font-lock
1792 AS_VAR_POPDEF([tmp])
1793 m4_ifdef([tmp], [echo oops])
1794
1795 # Indirects via shell vars.
1796 echo '===='
1797 num=1
1798 AS_VAR_SET_IF([foo$num], [echo oops]) && echo ok
1799 AS_VAR_IF([foo$num], [], [echo ok], [echo oops])
1800 foo1=
1801 AS_VAR_SET_IF([foo$num], [echo ok])
1802 AS_VAR_SET([foo$num], ['\a "weird" `value` with; $fun '\''characters
1803 ']) # 'font-lock
1804 AS_VAR_COPY([bar], [foo$num])
1805 num=2
1806 AS_VAR_COPY([foo$num], [bar])
1807 AS_ECHO(["$foo2-"])
1808 AS_ECHO(["AS_VAR_GET([foo$num])-"])
1809 AS_VAR_SET_IF([foo$num], [echo ok], [echo oops])
1810 AS_VAR_IF([foo$num], [string], [echo oops]) && echo ok
1811 AS_VAR_PUSHDEF([tmp], [foo$num])
1812 AS_VAR_IF([tmp], ['\a "weird" `value` with; $fun '\''characters
1813 '], [echo ok], [echo oops]) # 'font-lock
1814 AS_VAR_POPDEF([tmp])
1815 m4_ifdef([tmp], [echo oops])
1816
1817 # Indirects via command substitution.
1818 echo '===='
1819 AS_VAR_SET_IF([`echo foo3`], [echo oops]) && echo ok
1820 AS_VAR_IF([`echo foo3`], [], [echo ok], [echo oops])
1821 foo3=
1822 AS_VAR_SET_IF([`echo foo3`], [echo ok])
1823 AS_VAR_SET([`echo foo3`], ['\a "weird" `value` with; $fun '\''characters
1824 ']) # 'font-lock
1825 AS_VAR_COPY([bar], [`echo foo3`])
1826 num=2
1827 AS_VAR_COPY([`echo foo4`], [bar])
1828 AS_ECHO(["$foo4-"])
1829 AS_ECHO(["AS_VAR_GET([`echo foo4`])-"])
1830 AS_VAR_SET_IF([`echo foo4`], [echo ok], [echo oops])
1831 AS_VAR_IF([`echo foo4`], [string], [echo oops]) && echo ok
1832 AS_VAR_PUSHDEF([tmp], [`echo foo4`])
1833 AS_VAR_IF([tmp], ['\a "weird" `value` with; $fun '\''characters
1834 '], [echo ok], [echo oops]) # 'font-lock
1835 AS_VAR_POPDEF([tmp])
1836 m4_ifdef([tmp], [echo oops])
1837 :
1838 ]])
1839
1840 AT_CHECK_M4SH
1841 AT_CHECK([$CONFIG_SHELL ./script], [], [[ok
1842 ok
1843 ok
1844 \a "weird" `value` WITH; $fun 'characters
1845 -
1846 \a "weird" `value` WITH; $fun 'characters
1847 -
1848 ok
1849 ok
1850 ok
1851 ====
1852 ok
1853 ok
1854 ok
1855 \a "weird" `value` WITH; $fun 'characters
1856 -
1857 \a "weird" `value` WITH; $fun 'characters-
1858 ok
1859 ok
1860 ok
1861 ====
1862 ok
1863 ok
1864 ok
1865 \a "weird" `value` WITH; $fun 'characters
1866 -
1867 \a "weird" `value` WITH; $fun 'characters-
1868 ok
1869 ok
1870 ok
1871 ]])
1872
1873 AT_CLEANUP
1874
1875
1876 ## --------------- ##
1877 ## AS_VAR_APPEND. ##
1878 ## --------------- ##
1879
1880 AT_SETUP([AS@&t@_VAR_APPEND])
1881 AT_KEYWORDS([m4sh AS@&t@_VAR])
1882
1883 AT_DATA_M4SH([script.as], [[dnl
1884 AS_INIT
1885 # Literals.
1886 AS_VAR_APPEND([foo], ["hello, "])
1887 AS_VAR_APPEND([foo], [world])
1888 echo "$foo"
1889 # Indirects via shell vars.
1890 num=1
1891 AS_VAR_APPEND([foo$num], ['hello, '])
1892 AS_VAR_APPEND([foo$num], [`echo "world"`])
1893 echo "$foo1"
1894 # Indirects via command substitution.
1895 h=hello w=', world'
1896 AS_VAR_APPEND([`echo foo2`], [${h}])
1897 AS_VAR_APPEND([`echo foo2`], ["$w"])
1898 echo "$foo2"
1899 ]])
1900
1901 AT_CHECK_M4SH
1902 AT_CHECK([$CONFIG_SHELL ./script], [],
1903 [[hello, world
1904 hello, world
1905 hello, world
1906 ]])
1907
1908 AT_CLEANUP
1909
1910
1911 ## -------------- ##
1912 ## AS_VAR_ARITH. ##
1913 ## -------------- ##
1914
1915 AT_SETUP([AS@&t@_VAR_ARITH])
1916 AT_KEYWORDS([m4sh AS@&t@_VAR])
1917
1918 AT_DATA_M4SH([script.as], [[dnl
1919 AS_INIT
1920 # Literals.
1921 AS_VAR_ARITH([foo], [1 + 1])
1922 echo "$foo"
1923 # Indirects via shell vars.
1924 num=1
1925 AS_VAR_ARITH([foo$num], [\( 2 + 3 \) \* 4])
1926 echo "$foo1"
1927 # Indirects via command substitution.
1928 AS_VAR_ARITH([`echo foo2`], [0 + -2 + $foo1 / 2])
1929 echo "$foo2"
1930 ]])
1931
1932 AT_CHECK_M4SH
1933 AT_CHECK([$CONFIG_SHELL ./script], [],
1934 [[2
1935 20
1936 8
1937 ]])
1938
1939 AT_CLEANUP
1940
1941
1942 ## ----------------- ##
1943 ## AS_INIT cleanup. ##
1944 ## ----------------- ##
1945
1946 AT_SETUP([AS@&t@_INIT cleanup])
1947 AT_KEYWORDS([m4sh m4@&t@_wrap m4@&t@_wrap_lifo])
1948
1949 AT_DATA_M4SH([script.as], [[dnl
1950 dnl Registered before AS_INIT's cleanups
1951 m4_wrap([echo cleanup 1
1952 ])
1953 m4_pushdef([_AS_SHELL_FN_SPY])dnl neutralize the spy, we don't care about it
1954 AS_INIT
1955 dnl Registered after AS_INIT's cleanups, thus goes to KILL diversion
1956 m4_wrap([echo cleanup 2
1957 dnl However, nested wraps and diversions can still be used
1958 dnl Also, test wrapping text that looks like parameter reference
1959 m4_wrap([echo cleanup 3
1960 m4_divert_text([M4SH-INIT], [m4_define([foo], [$1])dnl
1961 echo prep foo([4])
1962 ])])])
1963 dnl Registered before AS_INIT's cleanups
1964 m4_wrap_lifo([echo cleanup 5
1965 ])
1966 echo body
1967 ]])
1968
1969 AT_CHECK_M4SH
1970 AT_CHECK([$CONFIG_SHELL ./script], [], [[prep 4
1971 body
1972 cleanup 5
1973 cleanup 1
1974 ]])
1975
1976 AT_CLEANUP
1977
1978
1979 ## -------------------------- ##
1980 ## AS_INIT basename __file__. ##
1981 ## -------------------------- ##
1982
1983 AT_SETUP([AS@&t@_INIT basename __@&t@file__])
1984 AT_KEYWORDS([m4sh])
1985
1986 AT_CHECK([mkdir sub || exit 77])
1987 AT_DATA_M4SH([sub/script.as], [[dnl
1988 AS_INIT
1989 ]])
1990 AT_CHECK_AUTOM4TE([--language=m4sh sub/script.as -o script])
1991 AT_CHECK([grep '^# Generated from' script], [0], [dnl
1992 # Generated from script.as by ]m4_PACKAGE_STRING[.
1993 ])
1994
1995 AT_CLEANUP
1996
1997
1998 ## ------------------- ##
1999 ## AS_INIT_GENERATED. ##
2000 ## ------------------- ##
2001
2002 AT_SETUP([AS@&t@_INIT_GENERATED])
2003 AT_KEYWORDS([AS@&t@_MESSAGE AS@&t@_MESSAGE_LOG_FD])
2004
2005 dnl First run, no logging, tests shell selection
2006 AT_DATA_M4SH([script.as], [[dnl
2007 AS_INIT
2008 AS_INIT_GENERATED([child], [echo hello from child])
2009 cat >>child <<\EOF
2010 AS_ECHO(["SHELL=$SHELL"])
2011 EOF
2012 echo hello from parent
2013 AS_ECHO(["SHELL=$SHELL"])
2014 ]])
2015
2016 AT_CHECK_M4SH
2017 AT_CHECK([$CONFIG_SHELL ./script], [0], [stdout])
2018 AT_CHECK([grep 'SHELL=.' stdout], [0], [ignore])
2019 sed s/parent/child/ <stdout >expout
2020 AT_CHECK([./child], [0], [expout])
2021 SHELL=/bogus
2022 export SHELL
2023 cp stdout expout
2024 mv child child.bak
2025 AT_CHECK([$CONFIG_SHELL ./script], [0], [expout])
2026 AT_CHECK([cmp child child.bak])
2027 AT_CHECK([grep 'SHELL=.' stdout], [0], [ignore])
2028 sed s/parent/child/ <stdout >expout
2029 AT_CHECK([./child], [0], [expout])
2030
2031
2032 dnl Second run, with logging from parent and child, tests fd handling
2033 AT_DATA_M4SH([script.as], [[dnl
2034 AS_INIT
2035 child=${1-child}
2036 m4_define([AS_MESSAGE_LOG_FD], [5])
2037 exec AS_MESSAGE_LOG_FD>log
2038 AS_INIT_GENERATED([$child], [echo hello1 from $child]) || AS_EXIT([1])
2039 cat >>$child <<\EOF
2040 m4_pushdef([AS_MESSAGE_LOG_FD])
2041 AS_MESSAGE([hello2 from ${child}child])
2042 m4_popdef([AS_MESSAGE_LOG_FD])
2043 exec AS_MESSAGE_LOG_FD>>log
2044 AS_MESSAGE([hello3 from child])
2045 EOF
2046 AS_MESSAGE([hello from parent])
2047 dnl close log in parent before spawning child, for mingw
2048 exec AS_MESSAGE_LOG_FD>&-
2049 ./$child
2050 ]])
2051
2052 rm -f script
2053 AT_CHECK_M4SH
2054 AT_CHECK([$CONFIG_SHELL ./script], [0], [[script: hello from parent
2055 hello1 from child
2056 child: hello2 from child
2057 child: hello3 from child
2058 ]])
2059 AT_CHECK([[sed 's,:[0-9][0-9]*:,:0:,' log]], [0],
2060 [[script:0: hello from parent
2061 child:0: hello3 from child
2062 ]])
2063
2064 # Force write error creating a file on stdout
2065 if test -w /dev/full && test -c /dev/full; then
2066 AT_CHECK([$CONFIG_SHELL ./script /dev/full], [1], [ignore], [ignore])
2067 fi
2068
2069 AT_CLEANUP
2070
2071
2072 ## --------------- ##
2073 ## AS_MESSAGE_FD. ##
2074 ## --------------- ##
2075
2076 AT_SETUP([AS@&t@_MESSAGE_FD])
2077 AT_KEYWORDS([AS@&t@_MESSAGE AS@&t@_MESSAGE_LOG_FD AS@&t_ORIGINAL_STDIN_FD])
2078 AT_KEYWORDS([AS@&t@_LINENO_PUSH])
2079
2080 AT_DATA_M4SH([script.as], [[dnl
2081 AS_INIT
2082 m4_define([AS_ORIGINAL_STDIN_FD], [5])
2083 m4_define([AS_MESSAGE_LOG_FD], [6])
2084 m4_define([AS_MESSAGE_FD], [7])
2085 exec AS_ORIGINAL_STDIN_FD<&0 </dev/null AS_MESSAGE_LOG_FD>log
2086 if test $[#] -gt 0; then
2087 exec AS_MESSAGE_FD>/dev/null
2088 else
2089 exec AS_MESSAGE_FD>&1
2090 fi
2091 AS_LINENO_PUSH([100])
2092 cat # tests that stdin is neutralized
2093 AS_MESSAGE([hello world])
2094 cat <&AS_ORIGINAL_STDIN_FD
2095 ]])
2096
2097 AT_CHECK_M4SH
2098 AT_CHECK([echo goodbye | $CONFIG_SHELL ./script], [0],
2099 [[script: hello world
2100 goodbye
2101 ]])
2102 AT_CHECK([cat log], [0],
2103 [[script:100: hello world
2104 ]])
2105 rm log
2106 AT_CHECK([echo goodbye | $CONFIG_SHELL ./script silent], [0],
2107 [[goodbye
2108 ]])
2109 AT_CHECK([cat log], [0],
2110 [[script:100: hello world
2111 ]])
2112
2113 AT_CLEANUP
2114
2115
2116 ## --------------- ##
2117 ## _AS_CLEAN_DIR. ##
2118 ## --------------- ##
2119
2120 AT_SETUP([_AS@&t@_CLEAN_DIR])
2121
2122 dnl ensure that we can erase all files in a directory. Note that
2123 dnl _AS_CLEAN_DIR needs three globs to catch all these files.
2124 AT_DATA_M4SH([script.as], [[dnl
2125 AS_INIT
2126 # Unwritable subdirectories are common during 'make distcheck'.
2127 mkdir sub sub/unwritable || AS_ERROR([failed to mkdir])
2128 touch sub/unwritable/file || AS_ERROR([failed to touch])
2129 chmod a-wx sub/unwritable || AS_ERROR([failed to chmod])
2130 # Cygwin 1.5 can't touch 'sub/...', so make that file optional.
2131 touch sub/a sub/aa sub/aaa sub/.a sub/..a sub/.aa \
2132 || AS_ERROR([failed to touch])
2133 touch sub/... 2>/dev/null
2134 _AS_CLEAN_DIR([sub]) || AS_ERROR([failed to clean])
2135 # rmdir instead of 'rm -fr' here proves that we emptied sub.
2136 rmdir sub || AS_ERROR([failed to rmdir])
2137 ]])
2138
2139 AT_CHECK_M4SH
2140 AT_CHECK([$CONFIG_SHELL ./script])
2141
2142 AT_CLEANUP
2143
2144
2145 ## -------- ##
2146 ## ECHO_C. ##
2147 ## -------- ##
2148
2149 AT_SETUP([ECHO_C])
2150
2151 AT_DATA_M4SH([script.as], [[dnl
2152 AS_INIT
2153 _AS_PREPARE
2154 foo=`echo foobar`
2155 echo "$foo"
2156 ]])
2157
2158 AT_CHECK_M4SH
2159 AT_CHECK([$CONFIG_SHELL ./script], [], [foobar
2160 ])
2161
2162 AT_CLEANUP