tests: refactor the handling of Perl

Let's make a difference between places where Perl is required for the
test (AT_PERL_REQUIRE), and the places where it's used to run the
test, but it's not not to run the test (AT_PERL_CHECK).

* tests/local.at (AT_REQUIRE): New.
(AT_PERL_CHECK, AT_PERL_REQUIRE): New.
Use them where appropriate.

* tests/local.mk ($(TESTSUITE)): Beware not to start the line with
'-pi' if Perl is empty, as Make understands this as "it's ok to fail".
Which it is not.
This commit is contained in:
Akim Demaille
2019-10-12 12:34:10 +02:00
parent 59cb1f421c
commit c483b6593f
13 changed files with 65 additions and 39 deletions

View File

@@ -760,7 +760,7 @@ EXTRACT_PRIVATE = AT_DOXYGEN_PRIVATE
EXTRACT_STATIC = AT_DOXYGEN_PRIVATE EXTRACT_STATIC = AT_DOXYGEN_PRIVATE
]) ])
AT_CHECK([doxygen --version || exit 77], 0, ignore) AT_REQUIRE([doxygen --version], 0, ignore)
AT_CHECK([doxygen], 0, [], [ignore]) AT_CHECK([doxygen], 0, [], [ignore])
AT_BISON_OPTION_POPDEFS AT_BISON_OPTION_POPDEFS

View File

@@ -619,7 +619,7 @@ AT_CHECK([cat stderr], 0, [expout])
# Make sure we did not introduce bad spaces. Checked here because all # Make sure we did not introduce bad spaces. Checked here because all
# the skeletons are (or should be) exercized here. # the skeletons are (or should be) exercized here.
m4_define([AT_CHECK_SPACES], m4_define([AT_CHECK_SPACES],
[AT_CHECK(["$PERL" -ne ' [AT_PERL_CHECK([-ne '
chomp; chomp;
print "$ARGV:$.: {$_}\n" print "$ARGV:$.: {$_}\n"
if (# No starting/ending empty lines. if (# No starting/ending empty lines.
@@ -628,8 +628,8 @@ m4_define([AT_CHECK_SPACES],
|| /\s$/ || /\s$/
# No tabs. # No tabs.
|| /\t/ || /\t/
)' $1 || exit 77 )' $1
])dnl ])
]) ])

View File

@@ -39,14 +39,16 @@ AT_DATA_GRAMMAR([[input.y]], [$2])
# For some reason, literal ^M in the input are removed and don't end # For some reason, literal ^M in the input are removed and don't end
# in `input.y`. So use the two-character ^M represent it, and let # in `input.y`. So use the two-character ^M represent it, and let
# Perl insert real CR characters. # Perl insert real CR characters.
AT_CHECK([$PERL -pi -e 's{\^M}{\r}gx' input.y || exit 77]) if grep '\^M' input.y >/dev/null; then
AT_PERL_REQUIRE([-pi -e 's{\^M}{\r}gx' input.y])
fi
AT_DATA([experr], [$4]) AT_DATA([experr], [$4])
AT_CHECK([LC_ALL=en_US.UTF-8 $5 bison -fcaret --color=debug -Wall input.y], [$3], [], [experr]) AT_CHECK([LC_ALL=en_US.UTF-8 $5 bison -fcaret --color=debug -Wall input.y], [$3], [], [experr])
# When no style, same messages, but without style. # When no style, same messages, but without style.
AT_CHECK(["$PERL" -pi -e 's{(</?(-|\w)+>)}{ $[]1 eq "<tag>" ? $[]1 : "" }ge' experr || exit 77]) AT_PERL_REQUIRE([-pi -e 's{(</?(-|\w)+>)}{ $[]1 eq "<tag>" ? $[]1 : "" }ge' experr])
# Cannot use AT_BISON_CHECK easily as we need to change the # Cannot use AT_BISON_CHECK easily as we need to change the
# environment. # environment.

View File

@@ -314,7 +314,7 @@ AT_TEST([x9], [%locations %code requires {#include "location.hh"} %define api.lo
# Ignore comments, YYChar (template parameter), YYPUSH_MORE(_DEFINED)? # Ignore comments, YYChar (template parameter), YYPUSH_MORE(_DEFINED)?
# (constant definition), YY_\w+_INCLUDED (header guards). # (constant definition), YY_\w+_INCLUDED (header guards).
# YYDEBUG (not renamed) can be read, but not changed. # YYDEBUG (not renamed) can be read, but not changed.
AT_CHECK([["$PERL" -n -0777 -e ' AT_PERL_CHECK([[-n -0777 -e '
s{/\*.*?\*/}{}gs; s{/\*.*?\*/}{}gs;
s{//.*}{}g; s{//.*}{}g;
s{\b((defined|if)\ YYDEBUG s{\b((defined|if)\ YYDEBUG
@@ -347,7 +347,7 @@ AT_CHECK([["$PERL" -n -0777 -e '
print "$ARGV: invalid exported yy: $1\n"; print "$ARGV: invalid exported yy: $1\n";
} }
} }
' -- *.hh *.h || exit 77]]) ' -- *.hh *.h]])
# Do this late, so that other checks have been performed. # Do this late, so that other checks have been performed.
AT_SKIP_IF_CANNOT_LINK_C_AND_CXX AT_SKIP_IF_CANNOT_LINK_C_AND_CXX

View File

@@ -90,7 +90,7 @@ default: 'a' }
%- %-
%{ %{
]]) ]])
AT_CHECK([["$PERL" -pi -e 's/\\(\d{3})/chr(oct($1))/ge' input.y || exit 77]]) AT_PERL_REQUIRE([[-pi -e 's/\\(\d{3})/chr(oct($1))/ge' input.y]])
AT_BISON_CHECK([input.y], [1], [], AT_BISON_CHECK([input.y], [1], [],
[[input.y:1.1-2: error: invalid characters: '\0\001\002\377?' [[input.y:1.1-2: error: invalid characters: '\0\001\002\377?'
@@ -2184,7 +2184,7 @@ AT_DATA([empty.y],
start: ''; start: '';
start: ' start: '
]]) ]])
AT_CHECK([["$PERL" -e "print 'start: \'';" >> empty.y || exit 77]]) AT_PERL_REQUIRE([[-e "print 'start: \'';" >> empty.y]])
AT_BISON_CHECK([-fcaret empty.y], [1], [], AT_BISON_CHECK([-fcaret empty.y], [1], [],
[[empty.y:2.8-9: warning: empty character literal [-Wother] [[empty.y:2.8-9: warning: empty character literal [-Wother]
@@ -2209,7 +2209,7 @@ AT_DATA([two.y],
start: 'ab'; start: 'ab';
start: 'ab start: 'ab
]]) ]])
AT_CHECK([["$PERL" -e "print 'start: \'ab';" >> two.y || exit 77]]) AT_PERL_REQUIRE([[-e "print 'start: \'ab';" >> two.y]])
AT_BISON_CHECK([two.y], [1], [], AT_BISON_CHECK([two.y], [1], [],
[[two.y:2.8-11: warning: extra characters in character literal [-Wother] [[two.y:2.8-11: warning: extra characters in character literal [-Wother]
@@ -2224,7 +2224,7 @@ AT_DATA([three.y],
start: 'abc'; start: 'abc';
start: 'abc start: 'abc
]]) ]])
AT_CHECK([["$PERL" -e "print 'start: \'abc';" >> three.y || exit 77]]) AT_PERL_REQUIRE([[-e "print 'start: \'abc';" >> three.y]])
AT_BISON_CHECK([three.y], [1], [], AT_BISON_CHECK([three.y], [1], [],
[[three.y:2.8-12: warning: extra characters in character literal [-Wother] [[three.y:2.8-12: warning: extra characters in character literal [-Wother]
@@ -2254,8 +2254,7 @@ start: '\777' '\0' '\xfff' '\x0'
# Beside we cannot even expect "echo '\0'" to output two characters # Beside we cannot even expect "echo '\0'" to output two characters
# (well three with \n): at least Bash 3.2 converts the two-character # (well three with \n): at least Bash 3.2 converts the two-character
# sequence "\0" into a single NUL character. # sequence "\0" into a single NUL character.
AT_CHECK([["$PERL" -e 'print "start: \"\\\t\\\f\\\0\\\1\" ;";' >> input.y \ AT_PERL_REQUIRE([[-e 'print "start: \"\\\t\\\f\\\0\\\1\" ;";' >> input.y]])
|| exit 77]])
AT_BISON_CHECK([input.y], [1], [], AT_BISON_CHECK([input.y], [1], [],
[[input.y:2.9-12: error: invalid number after \-escape: 777 [[input.y:2.9-12: error: invalid number after \-escape: 777

View File

@@ -29,6 +29,7 @@ m4_define([m4_null_if],
[], [$2], [], [$2],
[$3])]) [$3])])
# AT_SETUP_STRIP(TITLE) # AT_SETUP_STRIP(TITLE)
# --------------------- # ---------------------
# Abbreviate the TITLE to be passed to AT_SETUP. Remove new-lines # Abbreviate the TITLE to be passed to AT_SETUP. Remove new-lines
@@ -50,15 +51,40 @@ m4_define([AT_SETUP_STRIP],
## Basic tests. ## ## Basic tests. ##
## ------------- ## ## ------------- ##
# AT_PERL_CHECK(PERL-ARGS, ...)
# -----------------------------
# If Perl is available, run this test.
m4_define([AT_PERL_CHECK],
[if test x"$PERL" != x; then
AT_CHECK(["$PERL" $1], [$2], [$3], [$4])
fi
])
# AT_REQUIRE(CMD, ...)
# --------------------
# Same as AT_CHECK(...) but skip this test if we failed.
m4_define([AT_REQUIRE],
[AT_CHECK([$1 || exit 77], [$2], [$3], [$4])])
# AT_PERL_REQUIRE(PERL-ARGS, ...)
# -------------------------------
# Run this Perl program, or skip the test if Perl is not available.
m4_define([AT_PERL_REQUIRE],
[AT_REQUIRE(["$PERL" $1], [$2], [$3], [$4])])
# AT_MATCHES_CHECK(FILE, PERL-REGEXP, COUNT) # AT_MATCHES_CHECK(FILE, PERL-REGEXP, COUNT)
# ------------------------------------------ # ------------------------------------------
# Expect COUNT matches of the PERL-REGEXP in FILE. The file is # Expect COUNT matches of the PERL-REGEXP in FILE. The file is
# taken in "slurp" mode, i.e., one can match end-of-lines. # taken in "slurp" mode, i.e., one can match end-of-lines.
m4_define([AT_MATCHES_CHECK], m4_define([AT_MATCHES_CHECK],
[AT_CHECK(["$PERL" -0777 -ne ' [AT_PERL_CHECK([-0777 -ne '
my $count = 0; my $count = 0;
s{$2}{ ++$count; "" }gem; s{$2}{ ++$count; "" }gem;
printf "$count\n";' $1 || exit 77], [0], [$3 printf "$count\n";' $1], [0], [$3
])]) ])])

View File

@@ -77,7 +77,7 @@ AUTOTESTFLAGS = -I $(top_srcdir)/%D%
$(TESTSUITE): $(TESTSUITE_AT) $(TESTSUITE): $(TESTSUITE_AT)
$(AM_V_GEN) \ $(AM_V_GEN) \
$(AUTOTEST) $(AUTOTESTFLAGS) $(srcdir)/%D%/testsuite.at -o $@.tmp $(AUTOTEST) $(AUTOTESTFLAGS) $(srcdir)/%D%/testsuite.at -o $@.tmp
$(AM_V_at)$(PERL) -pi -e 's/\@tb\@/\t/g' $@.tmp $(AM_V_at)"$(PERL)" -pi -e 's/\@tb\@/\t/g' $@.tmp
$(AM_V_at)mv $@.tmp $@ $(AM_V_at)mv $@.tmp $@

View File

@@ -604,7 +604,7 @@ AT_DATA_GRAMMAR([test.y],
start: foo[ % /* aaa */ *&-.+\000\001\002\377 ] bar start: foo[ % /* aaa */ *&-.+\000\001\002\377 ] bar
{ s = $foo; } { s = $foo; }
]]) ]])
AT_CHECK([["$PERL" -pi -e 's/\\(\d{3})/chr(oct($1))/ge' test.y || exit 77]]) AT_PERL_REQUIRE([[-pi -e 's/\\(\d{3})/chr(oct($1))/ge' test.y]])
AT_BISON_CHECK([-o test.c test.y], 1, [], AT_BISON_CHECK([-o test.c test.y], 1, [],
[[test.y:11.13: error: invalid character in bracketed name: '%' [[test.y:11.13: error: invalid character in bracketed name: '%'
test.y:11.25-27: error: invalid characters in bracketed name: '*&-' test.y:11.25-27: error: invalid characters in bracketed name: '*&-'

View File

@@ -22,11 +22,11 @@ AT_BANNER([[Output file names.]])
# ----------------------------------------------- # -----------------------------------------------
# Check that the current directory contains FILE... (sorted). # Check that the current directory contains FILE... (sorted).
m4_define([AT_CHECK_FILES], m4_define([AT_CHECK_FILES],
[AT_CHECK([[find . -type f | [AT_REQUIRE([[find . -type f |
"$PERL" -ne ' "$PERL" -ne '
s,\./,,; chomp; s,\./,,; chomp;
push @file, $_ unless m{^($2|testsuite.log)$}; push @file, $_ unless m{^($2|testsuite.log)$};
END { print join (" ", sort @file), "\n" }' || exit 77]], END { print join (" ", sort @file), "\n" }']],
[], [$1 [], [$1
])]) ])])
@@ -48,7 +48,7 @@ foo: '0' {};
]]) ]])
# There is not AT_DATA_UNQUOTED. # There is not AT_DATA_UNQUOTED.
AT_CHECK(["$PERL" -pi -e 's{\$at_dir}'"{$at_group_dir}g" $1 || exit 77]) AT_PERL_REQUIRE([-pi -e 's{\$at_dir}'"{$at_group_dir}g" $1])
AT_BISON_CHECK([$3 $1], [$5], [], [ignore])[ AT_BISON_CHECK([$3 $1], [$5], [], [ignore])[
@@ -257,7 +257,7 @@ m4_define([AT_CHECK_OUTPUT_FILE_NAME],
AT_BISON_OPTION_PUSHDEFS AT_BISON_OPTION_PUSHDEFS
# Skip if platform doesn't support file name. For example, Cygwin # Skip if platform doesn't support file name. For example, Cygwin
# doesn't support file names containing ":" or "\". # doesn't support file names containing ":" or "\".
AT_CHECK([[touch "]AS_ESCAPE([$1[.tmp]])[" || exit 77]]) AT_REQUIRE([[touch "]AS_ESCAPE([$1[.tmp]])["]])
AT_DATA_GRAMMAR([glr.y], AT_DATA_GRAMMAR([glr.y],
[[%glr-parser [[%glr-parser

View File

@@ -1352,19 +1352,18 @@ AT_CHECK([[grep 'syntax error,' stderr.txt]], [[0]],
# Check number of default reductions in inconsistent states to be sure # Check number of default reductions in inconsistent states to be sure
# syntax error is detected before unnecessary reductions are performed. # syntax error is detected before unnecessary reductions are performed.
AT_CHECK([["$PERL" -0777 -ne 'print s/inconsistent default reduction//g;' \ AT_PERL_CHECK([[-0777 -ne 'print s/inconsistent default reduction//g;' stdout.txt]],
< stdout.txt || exit 77]], [[0]], [[14]]) [[0]], [[14]])
# Check number of default reductions in consistent states to be sure # Check number of default reductions in consistent states to be sure
# it is performed before the syntax error is detected. # it is performed before the syntax error is detected.
AT_CHECK([["$PERL" -0777 -ne 'print s/\bconsistent default reduction//g;' \ AT_PERL_CHECK([[-0777 -ne 'print s/\bconsistent default reduction//g;' stdout.txt]],
< stdout.txt || exit 77]], [[0]], [[2]]) [[0]], [[2]])
]AT_C_IF([[ ]AT_C_IF([[
# Check number of reallocs to be sure reallocated memory isn't somehow # Check number of reallocs to be sure reallocated memory isn't somehow
# lost between LAC invocations. # lost between LAC invocations.
AT_CHECK([["$PERL" -0777 -ne 'print s/\(realloc//g;' < stderr.txt \ AT_PERL_CHECK([[-0777 -ne 'print s/\(realloc//g;' < stderr.txt]], [[0]], [[3]])
|| exit 77]], [[0]], [[3]])
]])[ ]])[
AT_BISON_OPTION_POPDEFS AT_BISON_OPTION_POPDEFS

View File

@@ -311,7 +311,7 @@ print '@output(@,@,@)', "\n";
(print "garbage"x10, "\n") for (1..1000); (print "garbage"x10, "\n") for (1..1000);
print "${M4}_divert_pop(0)\n"; print "${M4}_divert_pop(0)\n";
]]) ]])
AT_CHECK([["$PERL" gen-skel.pl > skel.c || exit 77]]) AT_PERL_REQUIRE([[gen-skel.pl > skel.c]])
AT_DATA([[input.y]], AT_DATA([[input.y]],
[[%skeleton "./skel.c" [[%skeleton "./skel.c"

View File

@@ -162,7 +162,7 @@ void foo (void)
]]) ]])
_AT_SYNCLINES_COMPILE([syncline.c]) _AT_SYNCLINES_COMPILE([syncline.c])
AT_CHECK([[test "`cat stdout`" = 'syncline.c:4: @%:@error "4"' || exit 77]]) AT_REQUIRE([[test "`cat stdout`" = 'syncline.c:4: @%:@error "4"']])
# Then work for real. # Then work for real.
_AT_SYNCLINES_COMPILE([$1]) _AT_SYNCLINES_COMPILE([$1])
@@ -409,8 +409,8 @@ AT_DATA([\"\\\"\".AT_LANG_EXT],
[[int main (void) { return 0; } [[int main (void) { return 0; }
]]) ]])
AT_CHECK([AT_CXX_IF([$CXX $CXXFLAGS], [$CC $CFLAGS]) $CPPFLAGS \"\\\"\".]AT_LANG_EXT[ -o \"\\\"\" || AT_REQUIRE([AT_CXX_IF([$CXX $CXXFLAGS], [$CC $CFLAGS]) $CPPFLAGS \"\\\"\".]AT_LANG_EXT[ -o \"\\\"\"],
exit 77], [0], [ignore], [ignore]) [0], [ignore], [ignore])
AT_DATA_GRAMMAR([\"\\\"\".y], AT_DATA_GRAMMAR([\"\\\"\".y],
[[%skeleton "$1" [[%skeleton "$1"

View File

@@ -27,7 +27,7 @@ m4_define([AT_INCREASE_DATA_SIZE],
case $data_limit in case $data_limit in
[[0-9]]*) [[0-9]]*)
if test "$data_limit" -lt $1; then if test "$data_limit" -lt $1; then
AT_CHECK([ulimit -S -d $1 || exit 77]) AT_REQUIRE([ulimit -S -d $1])
ulimit -S -d $1 ulimit -S -d $1
fi fi
esac]) esac])
@@ -120,7 +120,7 @@ EOF
]]) ]])
AT_BISON_OPTION_POPDEFS AT_BISON_OPTION_POPDEFS
AT_CHECK(["$PERL" -w ./gengram.pl $2 || exit 77], 0, [stdout]) AT_PERL_REQUIRE([-w ./gengram.pl $2], 0, [stdout])
mv stdout $1 mv stdout $1
]) ])
@@ -203,7 +203,7 @@ yylex (void)
EOF EOF
]]) ]])
AT_CHECK(["$PERL" -w ./gengram.pl $2 || exit 77], 0, [stdout]) AT_PERL_REQUIRE([-w ./gengram.pl $2], 0, [stdout])
mv stdout $1 mv stdout $1
AT_BISON_OPTION_POPDEFS AT_BISON_OPTION_POPDEFS
]) ])
@@ -255,7 +255,7 @@ m4_pushdef([AT_TEST],
AT_BISON_OPTION_PUSHDEFS AT_BISON_OPTION_PUSHDEFS
AT_CHECK([ruby $abs_top_srcdir/tests/linear $1 >input.y || { echo "ruby does not work"; exit 77; }]) AT_REQUIRE([ruby $abs_top_srcdir/tests/linear $1 >input.y])
# Old versions of GCC reject large values given to #line. # Old versions of GCC reject large values given to #line.
AT_FULL_COMPILE([input], [], [], [], [--no-line]) AT_FULL_COMPILE([input], [], [], [], [--no-line])
AT_CHECK([grep 'define YYNSTATES *$1' input.c], [], [ignore]) AT_CHECK([grep 'define YYNSTATES *$1' input.c], [], [ignore])
@@ -375,7 +375,7 @@ yylex (void)
EOF EOF
]]) ]])
AT_CHECK(["$PERL" -w ./gengram.pl $2 || exit 77], 0, [stdout]) AT_PERL_REQUIRE([-w ./gengram.pl $2], 0, [stdout])
mv stdout $1 mv stdout $1
AT_BISON_OPTION_POPDEFS AT_BISON_OPTION_POPDEFS
]) ])