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])
103 AT_SETUP([AS@&t@_DIRNAME])
105 AT_DATA_M4SH([script.as],
108 # The EXPR variant is allowed to fail if `expr' was considered as too
109 # weak for us, in which case `as_expr=false'.
110 m4_define([DIRNAME_TEST],
111 [dir=`AS_DIRNAME([$1])`
112 test "$dir" = "$2" || (test -n "$3" && test "$dir" = "$3") ||
113 echo "dirname($1) = $dir instead of $2" >&2
115 if test "$as_expr" != false; then
116 dir=`_AS_DIRNAME_EXPR([$1])`
117 test "$dir" = "$2" || (test -n "$3" && test "$dir" = "$3") ||
118 echo "dirname_expr($1) = $dir instead of $2" >&2
121 dir=`_AS_DIRNAME_SED([$1])`
122 test "$dir" = "$2" || (test -n "$3" && test "$dir" = "$3") ||
123 echo "dirname_sed($1) = $dir instead of $2" >&2])
125 DIRNAME_TEST([/], [/])
126 DIRNAME_TEST([//], [//], [/])
127 DIRNAME_TEST([///], [/])
128 DIRNAME_TEST([//1], [//], [/])
129 DIRNAME_TEST([/1], [/])
130 DIRNAME_TEST([./1], [.])
131 DIRNAME_TEST([../../2], [../..])
132 DIRNAME_TEST([//1/], [//], [/])
133 DIRNAME_TEST([/1/], [/])
134 DIRNAME_TEST([./1/], [.])
135 DIRNAME_TEST([../../2], [../..])
136 DIRNAME_TEST([//1/3], [//1])
137 DIRNAME_TEST([/1/3], [/1])
138 DIRNAME_TEST([./1/3], [./1])
139 DIRNAME_TEST([../../2/3], [../../2])
140 DIRNAME_TEST([//1/3///], [//1])
141 DIRNAME_TEST([/1/3///], [/1])
142 DIRNAME_TEST([./1/3///], [./1])
143 DIRNAME_TEST([../../2/3///], [../../2])
144 DIRNAME_TEST([//1//3/], [//1])
145 DIRNAME_TEST([/1//3/], [/1])
146 DIRNAME_TEST([./1//3/], [./1])
147 DIRNAME_TEST([../../2//3/], [../../2])
163 AT_SETUP([AS@&t@_BASENAME])
165 AT_DATA_M4SH([script.as],
168 m4_define([BASENAME_TEST],
169 [base=`AS_BASENAME([$1])`
170 test "$base" = "$2" ||
171 echo "basename($1) = $base instead of $2" >&2
173 base=`_AS_BASENAME_SED([$1])`
174 test "$base" = "$2" ||
175 echo "basename_sed($1) = $base instead of $2" >&2])
177 BASENAME_TEST([//1], [1])
178 BASENAME_TEST([/1], [1])
179 BASENAME_TEST([./1], [1])
180 BASENAME_TEST([../../2], [2])
181 BASENAME_TEST([//1/], [1])
182 BASENAME_TEST([/1/], [1])
183 BASENAME_TEST([./1/], [1])
184 BASENAME_TEST([../../2], [2])
185 BASENAME_TEST([//1/3], [3])
186 BASENAME_TEST([/1/3], [3])
187 BASENAME_TEST([./1/3], [3])
188 BASENAME_TEST([../../2/3], [3])
189 BASENAME_TEST([//1/3///], [3])
190 BASENAME_TEST([/1/3///], [3])
191 BASENAME_TEST([./1/3///], [3])
192 BASENAME_TEST([../../2/3///], [3])
193 BASENAME_TEST([//1//3/], [3])
194 BASENAME_TEST([/1//3/], [3])
195 BASENAME_TEST([./1//3/], [3])
196 BASENAME_TEST([a.c], [a.c])
197 BASENAME_TEST([a.c/], [a.c])
198 BASENAME_TEST([/a.c/], [a.c])
199 BASENAME_TEST([/1/a.c], [a.c])
200 BASENAME_TEST([/1/a.c/], [a.c])
201 BASENAME_TEST([/1/../a.c], [a.c])
202 BASENAME_TEST([/1/../a.c/], [a.c])
203 BASENAME_TEST([./1/a.c], [a.c])
204 BASENAME_TEST([./1/a.c/], [a.c])
220 AT_SETUP([AS@&t@_MKDIR_P])
222 AT_DATA_M4SH([script.as],
228 AS_MKDIR_P(["$pwd/1/2/3/4/5/6"])
229 test -d "$pwd/1/2/3/4/5/6" ||
230 AS_ERROR([$pwd/1/2/3/4/5/6 has not been properly created])
232 AS_MKDIR_P(["a/b/c/d/e/f"])
233 test -d a/b/c/d/e/f ||
234 AS_ERROR([a/b/c/d/e/f has not been properly created])
246 ## -------------------- ##
247 ## AS_VERSION_COMPARE. ##
248 ## -------------------- ##
251 AT_SETUP([AS@&t@_VERSION_COMPARE])
253 AT_DATA_M4SH([script.as],
256 m4_define([VERSION_COMPARE_TEST],
257 [AS_VERSION_COMPARE([$1], [$3], [result='<'], [result='='], [result='>'])
258 test "X$result" = "X$2" ||
259 AS_ERROR([version $1 $result $3; should be $1 $2 $3])
261 [AS_VERSION_COMPARE([$3], [$1], [result='<'], [result='='], [result='>'])
262 test "X$result" = "X>" ||
263 AS_ERROR([version $3 $result $1; should be $3 > $1])])])
265 VERSION_COMPARE_TEST([], =, [])
266 VERSION_COMPARE_TEST([1.0], =, [1.0])
267 VERSION_COMPARE_TEST([alpha-1.0], =, [alpha-1.0])
269 # These tests are taken from libc/string/tst-svc.expect.
271 000 001 00 00a 01 01a 0 0a 2.8 2.8-0.4 20 21 22 212 CP037 CP345 CP1257
272 foo foo-0.4 foo-0.4a foo-0.4b foo-0.5 foo-0.10.5 foo-3.01 foo-3.0
273 foo-3.0.0 foo-3.0.1 foo-3.2 foo-3.10 foo00 foo0
276 for test2 in $tst_svc_expect; do
277 VERSION_COMPARE_TEST([$test1], <, [$test2])
292 ## ----------------------------- ##
293 ## Negated classes in globbing. ##
294 ## ----------------------------- ##
296 # It is known that `[^...]' is not universally supported, but it is
297 # unknown for `[!...]'.
299 AT_SETUP([Negated classes in globbing])
301 AT_DATA_M4SH([script.as],
304 case 'with!two!bangs' in
306 *) AS_ERROR([[`*[!a-z]*' didn't match `with!two!bangs']]);;
310 *[[!a-z]]*) AS_ERROR([[`*[!a-z]*' matched `without']]);;
322 ## ------------------- ##
323 ## Functions Support. ##
324 ## ------------------- ##
326 # Hypothesis: the shell we are running, after having checked for
327 # $LINENO support, supports functions.
329 AT_SETUP([Functions Support])
331 AT_DATA_M4SH([script.as],
347 if func_success; then
348 if func_failure; then
349 AS_ERROR([func_failure passed])
352 AS_ERROR([func_success failed])
364 ## ------------------------------ ##
365 ## Functions and return Support. ##
366 ## ------------------------------ ##
368 # Hypothesis: the shell we are running, after having checked for
369 # $LINENO support, supports functions, and the `return' keyword.
371 AT_SETUP([Functions and return Support])
373 AT_DATA_M4SH([script.as],
385 if func_success; then
386 if func_failure; then
387 AS_ERROR([func_failure passed])
390 AS_ERROR([func_success failed])
400 ## ------------------------------------ ##
401 ## AS_REQUIRE_SHELL_FN and m4_require. ##
402 ## ------------------------------------ ##
404 # Hypothesis: M4sh expands the requirements of AS_REQUIRE_SHELL_FN
405 # in the main diversion, and not in M4SH-INIT.
407 AT_SETUP([AS@&t@_REQUIRE_SHELL_FN and m4@&t@_require])
409 AT_DATA_M4SH([script.as], [[dnl
412 m4_defun([in_m4_sh_init], still_in_m4sh_init=yes)
413 m4_defun([not_in_m4_sh_init], still_in_m4sh_init=no)
415 m4_defun([error_if_emitted_in_m4sh_init], [
416 if test x$still_in_m4sh_init = xyes; then
417 AS_ERROR([requirement emitted in M4SH-INIT])
421 m4_defun([TEST_FUNC_BODY], [
422 m4_require([error_if_emitted_in_m4sh_init])
423 : echo in shell function, with parameter = [$]1
427 m4_defun([test_init], [
428 AS_REQUIRE([in_m4_sh_init])
429 AS_REQUIRE_SHELL_FN([test_func], [TEST_FUNC_BODY])
430 AS_REQUIRE([not_in_m4_sh_init])
447 # I'm not totally certain that we want to enforce the defaults here,
448 # but at least it is being tested.
450 AT_SETUP([AS@&t@_HELP_STRING])
452 AT_DATA_M4SH([script.as],
456 echo "AS_HELP_STRING([--an-option],[some text])"
457 echo "AS_HELP_STRING([--another-much-longer-option],
458 [some other text which should wrap at our default of 80 characters.])"
459 echo "AS_HELP_STRING([--fooT=barT], [foo bar])"
460 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@], [foo bar])"
461 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@123456789], [foo bar])"
462 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@1234567890], [foo bar])"
463 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@12345678901], [foo bar])"
464 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@123456789012], [foo bar])"
465 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@1234567890123], [foo bar])"
466 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@],
467 [some other text which should wrap at our default of 80 characters.])"
468 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@123456789],
469 [some other text which should wrap at our default of 80 characters.])"
470 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@1234567890],
471 [some other text which should wrap at our default of 80 characters.])"
472 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@12345678901],
473 [some other text which should wrap at our default of 80 characters.])"
474 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@123456789012],
475 [some other text which should wrap at our default of 80 characters.])"
476 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@1234567890123],
477 [some other text which should wrap at our default of 80 characters.])"
478 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@],
479 [some other @<][:@ex@:][>@ which should wrap at our default of 80 characters.])"
480 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@123456789],
481 [some other @<][:@ex@:][>@ which should wrap at our default of 80 characters.])"
482 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@1234567890],
483 [some other @<][:@ex@:][>@ which should wrap at our default of 80 characters.])"
484 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@12345678901],
485 [some other @<][:@ex@:][>@ which should wrap at our default of 80 characters.])"
486 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@123456789012],
487 [some other @<][:@ex@:][>@ which should wrap at our default of 80 characters.])"
488 echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@1234567890123],
489 [some other @<][:@ex@:][>@ which should wrap at our default of 80 characters.])"
493 AT_CHECK([./script], [0],
494 [[ --an-option some text
495 --another-much-longer-option
496 some other text which should wrap at our default of
500 --foo[=bar]123456789 foo bar
501 --foo[=bar]1234567890 foo bar
502 --foo[=bar]12345678901 foo bar
503 --foo[=bar]123456789012 foo bar
504 --foo[=bar]1234567890123
506 --foo[=bar] some other text which should wrap at our default of
508 --foo[=bar]123456789 some other text which should wrap at our default of
510 --foo[=bar]1234567890 some other text which should wrap at our default of
512 --foo[=bar]12345678901 some other text which should wrap at our default of
514 --foo[=bar]123456789012 some other text which should wrap at our default of
516 --foo[=bar]1234567890123
517 some other text which should wrap at our default of
519 --foo[=bar] some other [ex] which should wrap at our default of
521 --foo[=bar]123456789 some other [ex] which should wrap at our default of
523 --foo[=bar]1234567890 some other [ex] which should wrap at our default of
525 --foo[=bar]12345678901 some other [ex] which should wrap at our default of
527 --foo[=bar]123456789012 some other [ex] which should wrap at our default of
529 --foo[=bar]1234567890123
530 some other [ex] which should wrap at our default of
537 ## ------------------- ##
538 ## AS_IF and AS_CASE. ##
539 ## ------------------- ##
541 AT_SETUP([AS@&t@_IF and AS@&t@_CASE])
543 AT_DATA_M4SH([script.as], [[dnl
545 # Syntax checks: cope with empty arguments.
546 AS_IF([:], [], [echo wrong])
547 AS_IF([:], [echo one], [echo wrong])
548 AS_IF([false], [echo wrong], [echo two])
549 AS_IF([false], [echo wrong])
551 AS_IF([false], [echo wrong],
553 AS_IF([false], [echo wrong],
556 AS_IF([false], [echo wrong],
557 [false], [echo wrong])
558 AS_IF([false], [echo wrong],
559 [false], [echo wrong],
561 AS_IF([false], [echo wrong],
562 [false], [echo wrong],
566 AS_CASE([foo], [echo seven])
578 # check that require works correctly
579 m4_for([n], 1, 9, [],
580 [m4_defun([FOO]n, [foo]n[=]n)dnl
582 [m4_require([FOO]]n[)dnl
587 echo "foo1=$foo1 bar1=$bar1"
588 AS_IF([:], [], [BAR2])
589 echo "foo2=$foo2 bar2=$bar2"
590 AS_IF([false], [BAR3])
591 echo "foo3=$foo3 bar3=$bar3"
592 AS_IF([false], [], [BAR4])
593 echo "foo4=$foo4 bar4=$bar4"
594 AS_CASE([x], [x], [BAR5])
595 echo "foo5=$foo5 bar5=$bar5"
596 AS_CASE([x], [y], [BAR6])
597 echo "foo6=$foo6 bar6=$bar6"
601 echo "foo7=$foo7 bar7=$bar7"
605 echo "foo8=$foo8 bar8=$bar8"
609 echo "foo9=$foo9 bar9=$bar9"
613 AT_CHECK([./script], [0], [[one