diff --git a/ChangeLog b/ChangeLog index f0807607..ae768eaf 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2001-10-08 Akim Demaille + + * lib/m4sugar/m4sh.m4 (AS_DIRNAME_EXPR): Use AS_REQUIRE. + * tests/tools.at (AT_DATA_FORBIDDEN): Rename/move/duplicate to... + * tests/atspecific.m4 (AT_DATA_M4SUGAR, AT_DATA_M4SH): here. + * tests/tools.at, tests/m4sh.at: Use it. + * tests/m4sh.at: Don't rely on Autoconf macros. + (DIRNAME_TEST): Also exercise the expr variant. + * tests/m4sugar.at, tests/atspecific.m4 (AT_CHECK_M4SUGAR): The + preferred M4sugar extension is now `.4s'. + * tests/README: Remove. + 2001-10-08 Akim Demaille * lib/m4sugar/m4sugar.m4 (m4_provide_ifelse): Rename as... diff --git a/lib/m4sugar/m4sh.m4 b/lib/m4sugar/m4sh.m4 index 1b67796d..8bb7c614 100644 --- a/lib/m4sugar/m4sh.m4 +++ b/lib/m4sugar/m4sh.m4 @@ -388,13 +388,8 @@ m4_define([AS_ERROR], # a silly length limit that causes expr to fail if the matched # substring is longer than 120 bytes. So fall back on echo|sed if # expr fails. -# -# FIXME: Please note the following m4_require is quite wrong: if the first -# occurrence of AS_DIRNAME_EXPR is in a backquoted expression, the -# shell will be lost. We might have to introduce diversions for -# setting up an M4sh script: required macros will then be expanded there. m4_defun([AS_DIRNAME_EXPR], -[m4_require([_AS_EXPR_PREPARE])dnl +[AS_REQUIRE([_AS_EXPR_PREPARE])dnl $as_expr X[]$1 : 'X\(.*[[^/]]\)//*[[^/][^/]]*/*$' \| \ X[]$1 : 'X\(//\)[[^/]]' \| \ X[]$1 : 'X\(//\)$' \| \ diff --git a/tests/README b/tests/README deleted file mode 100644 index c9ef9fcb..00000000 --- a/tests/README +++ /dev/null @@ -1,78 +0,0 @@ - -*- outline -*- - -This directory holds the M4sugar, M4sh and Autoconf test suites. - - -Here are a few rules on how to write tests. - -* Order of the tests - -It is extremely important to pay attention to the order of the tests. -There are basically two philosophies: (i) test earlier the most -critical features (hence hurried users will at least check those), or -(ii) test earlier the primitives. - -For having tried both, I definitely recommend (ii). In practice users -will run the whole test suite even if it's long. And if they don't, -there will be enough other users who will do the job. - -But also in practice some problems in the core of project can be -responsible for an incredible number of failures. Then the problems -at the origin will be hidden by the consequences. If dependencies are -properly ordered in the test suite (test features which depend upon -other features *after* having checked the latter), basically you'll -just have to pay attention to the first failures. BTW, it also makes -`./testsuite -e' much more useful. - - -* Write tests! - -Don't let you be bitten three times by the same dog! When you spent a -significant amount of time tracking the failure of feature in some -more primitive problem, immediately write a test for the latter. - -If you track down several bugs down to the same origin, write a test -especially for it. - -Of course in both cases, more primitive tests will be run beforehand. -Write your test and have it failed before your fixing, and succeeding -after. This usually means having at hand two copies of the source -tree, one running the test suite to have it fail, and the other to -have the same testsuite succeed. - - -* Autoconf - -** Use of `exit' -Don't directly `exit 1' or `exit 77', rather use `AC_MSG_ERROR'. -First of all because when we have to read the test suite logs we are -happy to know why `configure' exited thanks to the error -message. Secondly, because `configure' traps the `exit' and pretty -many shells fail to set $? to 77 when trapping `exit 77'. This -results in the test suite not being able to check the exit status. - -** AC_MSG_ERROR -Of course, since macro names are forbidden in `configure', if you -really want to mention the macro name, you'll have to do without -including `A?_' in the output. - ------ - -Copyright 2000 Free Software Foundation, Inc. - -This file is part of GNU Autoconf. - -GNU Autoconf is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU Autoconf is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with autoconf; see the file COPYING. If not, write to -the Free Software Foundation, Inc., 59 Temple Place - Suite 330, -Boston, MA 02111-1307, USA. diff --git a/tests/atspecific.m4 b/tests/atspecific.m4 index 6fe738b8..6a5fa75f 100644 --- a/tests/atspecific.m4 +++ b/tests/atspecific.m4 @@ -1,5 +1,4 @@ # M4 macros used in building Autoconf test suites. -*- Autotest -*- -# Copyright 2000, 2001 Free Software Foundation, Inc. # Copyright 2000, 2001 Free Software Foundation, Inc. @@ -19,18 +18,43 @@ # 02111-1307, USA. -## ------------------------------------ ## -## Macros specialized in testing M4sh. ## -## ------------------------------------ ## +## ----------------- ## +## Testing M4sugar. ## +## ----------------- ## + + +# AT_DATA_M4SUGAR(FILENAME, CONTENTS) +# -------------------------------- +# Escape the invalid tokens with @&t@. +m4_define([AT_DATA_M4SUGAR], +[AT_DATA([$1], +[m4_patsubst(m4_patsubst([[$2]], [\(m4\)_], [\1@&t@_]), + [dnl], [d@&t@nl])])]) + # AT_CHECK_M4SUGAR(FLAGS, [EXIT-STATUS = 0], STDOUT, STDERR) # ---------------------------------------------------------- m4_define([AT_CHECK_M4SUGAR], [AT_CLEANUP_FILES([script.4s script autom4te.cache])dnl -AT_CHECK([autom4te --language=m4sugar script.s4g -o script $1], +AT_CHECK([autom4te --language=m4sugar script.4s -o script $1], m4_default([$2], [0]), [$3], [$4])]) + +## -------------- ## +## Testing M4sh. ## +## -------------- ## + + +# AT_DATA_M4SH(FILENAME, CONTENTS) +# -------------------------------- +# Escape the invalid tokens with @&t@. +m4_define([AT_DATA_M4SH], +[AT_DATA([$1], +[m4_patsubst(m4_patsubst([[$2]], [\(m4\|AS\)_], [\1@&t@_]), + [dnl], [d@&t@nl])])]) + + # AT_CHECK_M4SH(FLAGS, [EXIT-STATUS = 0], STDOUT, STDERR) # ------------------------------------------------------- m4_define([AT_CHECK_M4SH], @@ -39,9 +63,10 @@ AT_CHECK([autom4te --language=m4sh script.as -o script $1], m4_default([$2], [0]), [$3], [$4])]) -## ---------------------------------------- ## -## Macros specialized in testing Autoconf. ## -## ---------------------------------------- ## + +## ------------------ ## +## Testing Autoconf. ## +## ------------------ ## # AT_CONFIGURE_AC(BODY) diff --git a/tests/m4sh.at b/tests/m4sh.at index aa873dd7..b5f8a2d8 100644 --- a/tests/m4sh.at +++ b/tests/m4sh.at @@ -42,18 +42,15 @@ AT_SETUP([LINENO]) # UNSET-LINENO is a shell condition to make sure the scripts have the # same number of lines in the output, so that their outputs be identical. m4_define([AT_DATA_LINENO], -[AT_DATA([$1], -[[AS@&t@_INIT -m4@&t@_divert_push([0])d@&t@nl -m4@&t@_wrap([m4@&t@_divert_pop([0])[]])d@&t@nl -#! /bin/sh +[AT_DATA_M4SH([$1], +[[AS_INIT if $2; then - AS@&t@_UNSET([LINENO]) + AS_UNSET([LINENO]) fi -AS@&t@_SHELL_SANITIZE +AS_SHELL_SANITIZE echo "Line: $3" grep 'Line: .*$4' $[0] >/dev/null || - AS@&t@_ERROR([cannot find original script]) + AS_ERROR([cannot find original script]) exit 0 ]]) ])# AT_DATA_LINENO @@ -89,24 +86,29 @@ AT_CHECK([sh test/test-2], 0, [expout]) AT_CLEANUP(reference test test-1.lineno test-2.lineno) -## ----------------------------- ## -## AS_DIRNAME & AS_DIRNAME_SED. ## -## ----------------------------- ## +## ------------ ## +## AS_DIRNAME. ## +## ------------ ## # Build nested dirs. -m4_pattern_allow([^AS_DIRNAME(_SED)?$]) -AT_SETUP([[AS_DIRNAME & AS_DIRNAME_SED]]) +AT_SETUP([[AS@&t@_DIRNAME]]) -AT_DATA([configure.ac], -[[AS@&t@_INIT - -_AS@&t@_EXPR_PREPARE +AT_DATA_M4SH([script.as], +[[AS_INIT +# The EXPR variant is allowed to fail if `expr' was considered as too +# weak for us, in which case `as_expr=false'. m4_define([DIRNAME_TEST], [dir=`AS_DIRNAME([$1])` test "$dir" = "$2" || echo "dirname($1) = $dir instead of $2" >&2 +if test "$as_expr" != false; then + dir=`AS_DIRNAME_EXPR([$1])` + test "$dir" = "$2" || + echo "dirname_expr($1) = $dir instead of $2" >&2 +fi + dir=`AS_DIRNAME_SED([$1])` test "$dir" = "$2" || echo "dirname_sed($1) = $dir instead of $2" >&2]) @@ -137,25 +139,22 @@ DIRNAME_TEST([../../2//3/], [../../2]) AS_EXIT(0) ]]) -AT_CHECK_AUTOCONF -AT_CHECK_CONFIGURE +AT_CHECK_M4SH +AT_CHECK([script]) -AT_CLEANUP(configure) +AT_CLEANUP -## ------------------------------- ## -## AS_BASENAME & AS_BASENAME_SED. ## -## ------------------------------- ## +## ------------- ## +## AS_BASENAME. ## +## ------------- ## # Build nested dirs. -m4_pattern_allow([^AS_BASENAME(_SED)?$]) -AT_SETUP([[AS_BASENAME & AS_BASENAME_SED]]) +AT_SETUP([[AS@&t@_BASENAME]]) -AT_DATA([configure.ac], -[[AS@&t@_INIT - -_AS@&t@_EXPR_PREPARE +AT_DATA_M4SH([script.as], +[[AS_INIT m4_define([BASENAME_TEST], [base=`AS_BASENAME([$1])` @@ -197,10 +196,10 @@ BASENAME_TEST([./1/a.c/], [a.c]) AS_EXIT(0) ]]) -AT_CHECK_AUTOCONF -AT_CHECK_CONFIGURE +AT_CHECK_M4SH +AT_CHECK([script]) -AT_CLEANUP(configure) +AT_CLEANUP @@ -209,29 +208,28 @@ AT_CLEANUP(configure) ## ------------ ## # Build nested dirs. -m4_pattern_allow([^AS_MKDIR_P$]) -AT_SETUP([[AS_MKDIR_P]]) +AT_SETUP([[AS@&t@_MKDIR_P]]) -AT_DATA([configure.ac], -[[AS@&t@_INIT +AT_DATA_M4SH([script.as], +[[AS_INIT pwd=`pwd` set -e # Absolute AS_MKDIR_P(["$pwd/1/2/3/4/5/6"]) test -d "$pwd/1/2/3/4/5/6" || - AC_MSG_ERROR([$pwd/1/2/3/4/5/6 has not been properly created]) + AS_ERROR([$pwd/1/2/3/4/5/6 has not been properly created]) # Relative AS_MKDIR_P(["a/b/c/d/e/f"]) test -d a/b/c/d/e/f || - AC_MSG_ERROR([a/b/c/d/e/f has not been properly created]) + AS_ERROR([a/b/c/d/e/f has not been properly created]) AS_EXIT(0) ]]) -AT_CHECK_AUTOCONF -AT_CHECK_CONFIGURE +AT_CHECK_M4SH +AT_CHECK([script]) -AT_CLEANUP(configure 1 a) +AT_CLEANUP(1 a) @@ -245,20 +243,20 @@ AT_CLEANUP(configure 1 a) AT_SETUP([Negated classes in globbing]) -AT_DATA([configure.ac], -[[AS@&t@_INIT +AT_DATA_M4SH([script.as], +[[AS_INIT case 'with!two!bangs' in *[[!a-z]]*) ;; - *) AC_MSG_ERROR([[`*[!a-z]*' didn't match `with!two!bangs']]);; + *) AS_ERROR([[`*[!a-z]*' didn't match `with!two!bangs']]);; esac case without in - *[[!a-z]]*) AC_MSG_ERROR([[`*[!a-z]*' matched `without']]);; + *[[!a-z]]*) AS_ERROR([[`*[!a-z]*' matched `without']]);; esac ]]) -AT_CHECK_AUTOCONF -AT_CHECK_CONFIGURE +AT_CHECK_M4SH +AT_CHECK([script]) AT_CLEANUP diff --git a/tests/m4sugar.at b/tests/m4sugar.at index c1096756..563310c0 100644 --- a/tests/m4sugar.at +++ b/tests/m4sugar.at @@ -32,8 +32,7 @@ AT_BANNER([M4sugar.]) ## m4_warn. ## ## --------- ## -m4_pattern_allow([^m4_warn$]) -AT_SETUP([[m4_warn]]) +AT_SETUP([[m4@&t@_warn]]) # m4_text_wrap is used to display the help strings. Also, check that # commas are not swallowed. This can easily happen because of @@ -42,29 +41,29 @@ AT_SETUP([[m4_warn]]) # FIXME: For the time being we use -f to make sure we do issue the # warnings. But maybe autom4te should handle that by itself? -AT_DATA([script.s4g], +AT_DATA_M4SUGAR([script.4s], [[m4_warn([foo], [foo]) m4_warn([bar], [bar]) m4_warn([syntax], [syntax]) ]]) AT_CHECK_M4SUGAR([-o-], 0, [], -[script.s4g:3: warning: syntax +[script.4s:3: warning: syntax ]) AT_CHECK_M4SUGAR([-o- -Wall -f], 0, [], -[script.s4g:1: warning: foo -script.s4g:2: warning: bar -script.s4g:3: warning: syntax +[script.4s:1: warning: foo +script.4s:2: warning: bar +script.4s:3: warning: syntax ]) AT_CHECK_M4SUGAR([-o- -Wnone,bar -f], 0, [], -[script.s4g:2: warning: bar +[script.4s:2: warning: bar ]) AT_CHECK_M4SUGAR([-o- -Wnone,bar,error -f], 1, [], -[script.s4g:2: error: bar -script.s4g:2: the top level +[script.4s:2: error: bar +script.4s:2: the top level ]) AT_CLEANUP @@ -74,14 +73,13 @@ AT_CLEANUP ## m4_require: circular dependencies. ## ## ----------------------------------- ## -m4_pattern_allow([^m4_(require|defun|init)$]) -AT_SETUP([[m4_require: circular dependencies]]) +AT_SETUP([[m4@&t@_require: circular dependencies]]) # m4_text_wrap is used to display the help strings. Also, check that # commas are not swallowed. This can easily happen because of # m4-listification. -AT_DATA([script.s4g], +AT_DATA_M4SUGAR([script.4s], [[m4_defun([foo], [m4_require([bar])]) @@ -95,17 +93,18 @@ m4_init baz ]]) -AT_CHECK_M4SUGAR([], 1, [], -[[script.s4g:11: error: m4_require: circular dependency of foo -script.s4g:11: foo is required by... -script.s4g:5: bar is expanded from... -script.s4g:11: bar is required by... -script.s4g:2: foo is expanded from... -script.s4g:11: foo is required by... -script.s4g:8: baz is expanded from... -script.s4g:11: the top level +AT_DATA_M4SUGAR([experr], +[[script.4s:11: error: m4_require: circular dependency of foo +script.4s:11: foo is required by... +script.4s:5: bar is expanded from... +script.4s:11: bar is required by... +script.4s:2: foo is expanded from... +script.4s:11: foo is required by... +script.4s:8: baz is expanded from... +script.4s:11: the top level ]]) +AT_CHECK_M4SUGAR([], 1, [], experr) AT_CLEANUP @@ -113,15 +112,14 @@ AT_CLEANUP ## m4_text_wrap. ## ## -------------- ## -m4_pattern_allow([^m4_text_wrap$]) -AT_SETUP([[m4_text_wrap]]) +AT_SETUP([[m4@&t@_text_wrap]]) # m4_text_wrap is used to display the help strings. Also, check that # commas are not swallowed. This can easily happen because of # m4-listification. -AT_DATA([script.s4g], -[[m4@&t@_divert_push([0])m4@&t@_wrap([m4@&t@_divert_pop([0])])d@&t@nl +AT_DATA_M4SUGAR([script.4s], +[[m4_divert_push([0])m4_wrap([m4_divert_pop([0])])dnl m4_text_wrap([Short string */], [ ], [/* ], 20) m4_text_wrap([Much longer string */], [ ], [/* ], 20) diff --git a/tests/tools.at b/tests/tools.at index aff4e48e..ab1eb524 100644 --- a/tests/tools.at +++ b/tests/tools.at @@ -236,17 +236,12 @@ AT_CLEANUP ## autoconf: forbidden tokens. ## ## ---------------------------- ## -# AT_DATA_FORBIDDEN(FILENAME, CONTENTS) -# ------------------------------------- -# Escape the invalid tokens with @&t@. -m4_define([AT_DATA_FORBIDDEN], -[AT_DATA([$1], [m4_patsubst([$2], [\(m4\|AS\)_], [\1@&t@_])])]) # autoconf: forbidden tokens, basic # --------------------------------- AT_SETUP([autoconf: forbidden tokens, basic]) -AT_DATA_FORBIDDEN([configure.ac], +AT_DATA_M4SH([configure.ac], [[AS_INIT m4_foo _m4_bar @@ -255,7 +250,7 @@ _AS_BAR [d@&t@nl] ]]) -AT_DATA_FORBIDDEN([experr], +AT_DATA_M4SH([experr], [[configure.ac:2: error: possibly undefined macro: m4_foo configure.ac:3: error: possibly undefined macro: _m4_bar configure.ac:4: error: possibly undefined macro: AS_FOO @@ -272,7 +267,7 @@ AT_CLEANUP # -------------------------------------- AT_SETUP([autoconf: forbidden tokens, exceptions]) -AT_DATA_FORBIDDEN([configure.ac], +AT_DATA_M4SH([configure.ac], [[AS_INIT # This is allowed in spite of the name. @@ -294,7 +289,7 @@ BAS_DEFINE It would be very bad if Autoconf forgot to expand [AS_]INIT! ]]) -AT_DATA_FORBIDDEN([experr], +AT_DATA_M4SH([experr], [[configure.ac:1: error: possibly undefined macro: AS_INIT configure.ac:7: error: possibly undefined macro: AS_ALLOWED_NOT configure.ac:10: error: possibly undefined macro: FORBIDDEN