5 # Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2, or (at your option)
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write to the Free Software
20 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23 ## ---------------- ##
25 ## ---------------- ##
29 # We cannot unset LINENO with Zsh, yet this test case relies on
30 # unsetting LINENO to compare its result when (i) LINENO is supported
31 # and when (ii) it is not.
32 # So just skip if the shell is ZSH.
33 AT_CHECK([test -n "${ZSH_VERSION+set}" && exit 77], ignore)
35 # AT_DATA_LINENO(FILE-NAME,
36 # UNSET-LINENO = true | false, COUNTER, COUNTER-RE)
37 # ----------------------------------------------------------------
38 # Produce the FILE-NAME M4sh script which uses the COUNTER LINENO or
39 # _oline_, which we can recognized via COUNTER-RE. Unset LINENO is
42 # Use COUNTER, COUNTER-RE = [__LINENO__], [LINENO]
43 # or = [__OLINE__], [_oline__]
45 # instead of the obvious $LINENO and __oline__, because they would
46 # be replaced in the test suite itself, even before creating these
47 # scripts. For the same reason, grep for LINENO and _oline__ (sic).
49 # UNSET-LINENO is a shell condition to make sure the scripts have the
50 # same number of lines in the output, so that their outputs be identical.
51 m4_define([AT_DATA_LINENO],
55 AS@&t@_UNSET([LINENO])
59 grep 'Line: .*$4' $[0] >/dev/null ||
60 AS@&t@_ERROR([cannot find original script])
63 # If occurrences of $LINENO or __oline__ were wanted, create them.
64 sed 's/__LINENO__/$''LINENO/g;s/__OLINE__/__''oline__/g' $1.tas >$1.as
65 AT_CHECK([autom4te -l m4sh $1.as -o $1])
68 # `_oline_', once processed and ran, produces our reference.
69 # We check that we find ourselves by looking at a string which is
70 # available only in the original script: `_oline_'.
71 AT_DATA_LINENO([reference], [false], [__OLINE__], [_oline__])
72 AT_CHECK([./reference], 0, [stdout])
77 # Now using a maybe-functioning LINENO, with different call conventions.
78 # Be sure to be out of the PATH.
79 AT_CHECK([mkdir test || exit 77])
81 AT_DATA_LINENO([test/test-1], [false], [__LINENO__], [LINENO])
82 AT_CHECK([./test/test-1], 0, [expout])
83 AT_CHECK([(PATH=test$PATH_SEPARATOR$PATH; export PATH; exec test-1)],
85 AT_CHECK([sh ./test/test-1], 0, [expout])
87 # Now using a disabled LINENO, with different call conventions.
88 AT_DATA_LINENO([test/test-2], [true], [__LINENO__], [LINENO])
89 AT_CHECK([./test/test-2], 0, [expout])
90 AT_CHECK([(PATH=test$PATH_SEPARATOR$PATH; export PATH; exec test-2)],
92 AT_CHECK([sh ./test/test-2], 0, [expout])
98 ## -------------------- ##
99 ## AS_VAR_SET_DIRNAME. ##
100 ## -------------------- ##
103 AT_SETUP([AS@&t@_VAR_SET_DIRNAME])
105 AT_DATA_M4SH([script.as],
108 m4_define([DIRNAME_TEST],
109 [AS_VAR_SET_DIRNAME([dir], [$1])
110 test "$dir" = "$2" || (test -n "$3" && test "$dir" = "$3") ||
111 echo "dirname($1) = $dir instead of $2" >&2])
113 DIRNAME_TEST([/], [/])
114 DIRNAME_TEST([//], [//], [/])
115 DIRNAME_TEST([///], [/])
116 DIRNAME_TEST([//1], [//], [/])
117 DIRNAME_TEST([/1], [/])
118 DIRNAME_TEST([./1], [.])
119 DIRNAME_TEST([../../2], [../..])
120 DIRNAME_TEST([//1/], [//], [/])
121 DIRNAME_TEST([/1/], [/])
122 DIRNAME_TEST([./1/], [.])
123 DIRNAME_TEST([../../2], [../..])
124 DIRNAME_TEST([//1/3], [//1])
125 DIRNAME_TEST([/1/3], [/1])
126 DIRNAME_TEST([./1/3], [./1])
127 DIRNAME_TEST([../../2/3], [../../2])
128 DIRNAME_TEST([//1/3///], [//1])
129 DIRNAME_TEST([/1/3///], [/1])
130 DIRNAME_TEST([./1/3///], [./1])
131 DIRNAME_TEST([../../2/3///], [../../2])
132 DIRNAME_TEST([//1//3/], [//1])
133 DIRNAME_TEST([/1//3/], [/1])
134 DIRNAME_TEST([./1//3/], [./1])
135 DIRNAME_TEST([../../2//3/], [../../2])
146 ## --------------------- ##
147 ## AS_VAR_SET_BASENAME. ##
148 ## --------------------- ##
151 AT_SETUP([AS@&t@_VAR_SET_BASENAME])
153 AT_DATA_M4SH([script.as],
156 m4_define([BASENAME_TEST],
157 [AS_VAR_SET_BASENAME([base], [$1])
158 test "$base" = "$2" ||
159 echo "basename($1) = $base instead of $2" >&2])
161 BASENAME_TEST([//1], [1])
162 BASENAME_TEST([/1], [1])
163 BASENAME_TEST([./1], [1])
164 BASENAME_TEST([../../2], [2])
165 BASENAME_TEST([//1/], [1])
166 BASENAME_TEST([/1/], [1])
167 BASENAME_TEST([./1/], [1])
168 BASENAME_TEST([../../2], [2])
169 BASENAME_TEST([//1/3], [3])
170 BASENAME_TEST([/1/3], [3])
171 BASENAME_TEST([./1/3], [3])
172 BASENAME_TEST([../../2/3], [3])
173 BASENAME_TEST([//1/3///], [3])
174 BASENAME_TEST([/1/3///], [3])
175 BASENAME_TEST([./1/3///], [3])
176 BASENAME_TEST([../../2/3///], [3])
177 BASENAME_TEST([//1//3/], [3])
178 BASENAME_TEST([/1//3/], [3])
179 BASENAME_TEST([./1//3/], [3])
180 BASENAME_TEST([a.c], [a.c])
181 BASENAME_TEST([a.c/], [a.c])
182 BASENAME_TEST([/a.c/], [a.c])
183 BASENAME_TEST([/1/a.c], [a.c])
184 BASENAME_TEST([/1/a.c/], [a.c])
185 BASENAME_TEST([/1/../a.c], [a.c])
186 BASENAME_TEST([/1/../a.c/], [a.c])
187 BASENAME_TEST([./1/a.c], [a.c])
188 BASENAME_TEST([./1/a.c/], [a.c])
204 AT_SETUP([AS@&t@_MKDIR_P])
206 AT_DATA_M4SH([script.as],
212 AS_MKDIR_P(["$pwd/1/2/3/4/5/6"])
213 test -d "$pwd/1/2/3/4/5/6" ||
214 AS_ERROR([$pwd/1/2/3/4/5/6 has not been properly created])
216 AS_MKDIR_P(["a/b/c/d/e/f"])
217 test -d a/b/c/d/e/f ||
218 AS_ERROR([a/b/c/d/e/f has not been properly created])
230 ## -------------------- ##
231 ## AS_VERSION_COMPARE. ##
232 ## -------------------- ##
235 AT_SETUP([AS@&t@_VERSION_COMPARE])
237 AT_DATA_M4SH([script.as],
240 m4_define([VERSION_COMPARE_TEST],
241 [AS_VERSION_COMPARE([$1], [$3], [result='<'], [result='='], [result='>'])
242 test "X$result" = "X$2" ||
243 AS_ERROR([version $1 $result $3; should be $1 $2 $3])
245 [AS_VERSION_COMPARE([$3], [$1], [result='<'], [result='='], [result='>'])
246 test "X$result" = "X>" ||
247 AS_ERROR([version $3 $result $1; should be $3 > $1])])])
249 VERSION_COMPARE_TEST([], =, [])
250 VERSION_COMPARE_TEST([1.0], =, [1.0])
251 VERSION_COMPARE_TEST([alpha-1.0], =, [alpha-1.0])
253 # These tests are taken from libc/string/tst-svc.expect.
255 000 001 00 00a 01 01a 0 0a 2.8 2.8-0.4 20 21 22 212 CP037 CP345 CP1257
256 foo foo-0.4 foo-0.4a foo-0.4b foo-0.5 foo-0.10.5 foo-3.01 foo-3.0
257 foo-3.0.0 foo-3.0.1 foo-3.2 foo-3.10 foo00 foo0
260 for test2 in $tst_svc_expect; do
261 VERSION_COMPARE_TEST([$test1], <, [$test2])
276 ## ----------------------------- ##
277 ## Negated classes in globbing. ##
278 ## ----------------------------- ##
280 # It is known that `[^...]' is not universally supported, but it is
281 # unknown for `[!...]'.
283 AT_SETUP([Negated classes in globbing])
285 AT_DATA_M4SH([script.as],
288 case 'with!two!bangs' in
290 *) AS_ERROR([[`*[!a-z]*' didn't match `with!two!bangs']]);;
294 *[[!a-z]]*) AS_ERROR([[`*[!a-z]*' matched `without']]);;
306 ## ------------------- ##
307 ## Functions Support. ##
308 ## ------------------- ##
310 # Hypothesis: the shell we are running, after having checked for
311 # $LINENO support, supports functions.
313 AT_SETUP([Functions Support])
315 AT_DATA_M4SH([script.as],
331 if func_success; then
332 if func_failure; then
333 AS_ERROR([func_failure passed])
336 AS_ERROR([func_success failed])
348 ## ------------------------------ ##
349 ## Functions and return Support. ##
350 ## ------------------------------ ##
352 # Hypothesis: the shell we are running, after having checked for
353 # $LINENO support, supports functions, and the `return' keyword.
355 AT_SETUP([Functions and return Support])
357 AT_DATA_M4SH([script.as],
369 if func_success; then
370 if func_failure; then
371 AS_ERROR([func_failure passed])
374 AS_ERROR([func_success failed])
384 ## ------------------------------------ ##
385 ## AS_REQUIRE_SHELL_FN and m4_require. ##
386 ## ------------------------------------ ##
388 # Hypothesis: M4sh expands the requirements of AS_REQUIRE_SHELL_FN
389 # in the main diversion, and not in M4SH-INIT.
391 AT_SETUP([AS@&t@_REQUIRE_SHELL_FN and m4@&t@_require])
393 AT_DATA_M4SH([script.as], [[dnl
396 m4_defun([in_m4_sh_init], still_in_m4sh_init=yes)
397 m4_defun([not_in_m4_sh_init], still_in_m4sh_init=no)
399 m4_defun([error_if_emitted_in_m4sh_init], [
400 if test x$still_in_m4sh_init = xyes; then
401 AS_ERROR([requirement emitted in M4SH-INIT])
405 m4_defun([TEST_FUNC_BODY], [
406 m4_require([error_if_emitted_in_m4sh_init])
407 : echo in shell function, with parameter = [$]1
411 m4_defun([test_init], [
412 AS_REQUIRE([in_m4_sh_init])
413 AS_REQUIRE_SHELL_FN([test_func], [TEST_FUNC_BODY])
414 AS_REQUIRE([not_in_m4_sh_init])
431 # I'm not totally certain that we want to enforce the defaults here,
432 # but at least it is being tested.
434 AT_SETUP([AS@&t@_HELP_STRING])
436 AT_DATA_M4SH([script.as],
440 echo "AS_HELP_STRING([--an-option],[some text])"
441 echo "AS_HELP_STRING([--another-much-longer-option],
442 [some other text which should wrap at our default of 80 characters.])"
443 echo "AS_HELP_STRING([--fooT=barT], [foo bar])"
444 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@], [foo bar])"
445 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@123456789], [foo bar])"
446 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@1234567890], [foo bar])"
447 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@12345678901], [foo bar])"
448 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@123456789012], [foo bar])"
449 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@1234567890123], [foo bar])"
450 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@],
451 [some other text which should wrap at our default of 80 characters.])"
452 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@123456789],
453 [some other text which should wrap at our default of 80 characters.])"
454 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@1234567890],
455 [some other text which should wrap at our default of 80 characters.])"
456 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@12345678901],
457 [some other text which should wrap at our default of 80 characters.])"
458 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@123456789012],
459 [some other text which should wrap at our default of 80 characters.])"
460 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@1234567890123],
461 [some other text which should wrap at our default of 80 characters.])"
462 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@],
463 [some other @<][:@ex@:][>@ which should wrap at our default of 80 characters.])"
464 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@123456789],
465 [some other @<][:@ex@:][>@ which should wrap at our default of 80 characters.])"
466 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@1234567890],
467 [some other @<][:@ex@:][>@ which should wrap at our default of 80 characters.])"
468 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@12345678901],
469 [some other @<][:@ex@:][>@ which should wrap at our default of 80 characters.])"
470 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@123456789012],
471 [some other @<][:@ex@:][>@ which should wrap at our default of 80 characters.])"
472 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@1234567890123],
473 [some other @<][:@ex@:][>@ which should wrap at our default of 80 characters.])"
477 AT_CHECK([./script], [0],
478 [[ --an-option some text
479 --another-much-longer-option
480 some other text which should wrap at our default of
484 --foo[=bar]123456789 foo bar
485 --foo[=bar]1234567890 foo bar
486 --foo[=bar]12345678901 foo bar
487 --foo[=bar]123456789012 foo bar
488 --foo[=bar]1234567890123
490 --foo[=bar] some other text which should wrap at our default of
492 --foo[=bar]123456789 some other text which should wrap at our default of
494 --foo[=bar]1234567890 some other text which should wrap at our default of
496 --foo[=bar]12345678901 some other text which should wrap at our default of
498 --foo[=bar]123456789012 some other text which should wrap at our default of
500 --foo[=bar]1234567890123
501 some other text which should wrap at our default of
503 --foo[=bar] some other [ex] which should wrap at our default of
505 --foo[=bar]123456789 some other [ex] which should wrap at our default of
507 --foo[=bar]1234567890 some other [ex] which should wrap at our default of
509 --foo[=bar]12345678901 some other [ex] which should wrap at our default of
511 --foo[=bar]123456789012 some other [ex] which should wrap at our default of
513 --foo[=bar]1234567890123
514 some other [ex] which should wrap at our default of
521 ## ------------------- ##
522 ## AS_IF and AS_CASE. ##
523 ## ------------------- ##
525 AT_SETUP([AS@&t@_IF and AS@&t@_CASE])
527 AT_DATA_M4SH([script.as], [[dnl
529 # Syntax checks: cope with empty arguments.
530 AS_IF([:], [], [echo wrong])
531 AS_IF([:], [echo one], [echo wrong])
532 AS_IF([false], [echo wrong], [echo two])
533 AS_IF([false], [echo wrong])
535 AS_IF([false], [echo wrong],
537 AS_IF([false], [echo wrong],
540 AS_IF([false], [echo wrong],
541 [false], [echo wrong])
542 AS_IF([false], [echo wrong],
543 [false], [echo wrong],
545 AS_IF([false], [echo wrong],
546 [false], [echo wrong],
550 AS_CASE([foo], [echo seven])
562 # check that require works correctly
563 m4_for([n], 1, 9, [],
564 [m4_defun([FOO]n, [foo]n[=]n)dnl
566 [m4_require([FOO]]n[)dnl
571 echo "foo1=$foo1 bar1=$bar1"
572 AS_IF([:], [], [BAR2])
573 echo "foo2=$foo2 bar2=$bar2"
574 AS_IF([false], [BAR3])
575 echo "foo3=$foo3 bar3=$bar3"
576 AS_IF([false], [], [BAR4])
577 echo "foo4=$foo4 bar4=$bar4"
578 AS_CASE([x], [x], [BAR5])
579 echo "foo5=$foo5 bar5=$bar5"
580 AS_CASE([x], [y], [BAR6])
581 echo "foo6=$foo6 bar6=$bar6"
585 echo "foo7=$foo7 bar7=$bar7"
589 echo "foo8=$foo8 bar8=$bar8"
593 echo "foo9=$foo9 bar9=$bar9"
597 AT_CHECK([./script], [0], [[one