bison-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

tests: refactor the handling of Perl


From: Akim Demaille
Subject: tests: refactor the handling of Perl
Date: Sun, 13 Oct 2019 09:23:19 +0200

Now that Perl is indeed no longer required, we need to take more care in the 
test suite.

commit c483b6593fba38b4b1637e946f496eb0c8edfdb2
Author: Akim Demaille <address@hidden>
Date:   Sat Oct 12 12:34:10 2019 +0200

    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.

diff --git a/tests/c++.at b/tests/c++.at
index be9fa10a..84735d8d 100644
--- a/tests/c++.at
+++ b/tests/c++.at
@@ -760,7 +760,7 @@ EXTRACT_PRIVATE        = 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_BISON_OPTION_POPDEFS
diff --git a/tests/calc.at b/tests/calc.at
index 6355a5b4..4d15b732 100644
--- a/tests/calc.at
+++ b/tests/calc.at
@@ -619,7 +619,7 @@ AT_CHECK([cat stderr], 0, [expout])
 # Make sure we did not introduce bad spaces.  Checked here because all
 # the skeletons are (or should be) exercized here.
 m4_define([AT_CHECK_SPACES],
-[AT_CHECK(["$PERL" -ne '
+[AT_PERL_CHECK([-ne '
   chomp;
   print "$ARGV:$.: {$_}\n"
     if (# No starting/ending empty lines.
@@ -628,8 +628,8 @@ m4_define([AT_CHECK_SPACES],
         || /\s$/
         # No tabs.
         || /\t/
-        )' $1 || exit 77
-])dnl
+        )' $1
+])
 ])
 
 
diff --git a/tests/diagnostics.at b/tests/diagnostics.at
index a1754ab3..96d7e224 100644
--- a/tests/diagnostics.at
+++ b/tests/diagnostics.at
@@ -39,14 +39,16 @@ AT_DATA_GRAMMAR([[input.y]], [$2])
 # 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
 # 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_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.
-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
 # environment.
diff --git a/tests/headers.at b/tests/headers.at
index 8103d592..d1e75bf8 100644
--- a/tests/headers.at
+++ b/tests/headers.at
@@ -314,7 +314,7 @@ AT_TEST([x9], [%locations %code requires {#include 
"location.hh"} %define api.lo
 #   Ignore comments, YYChar (template parameter), YYPUSH_MORE(_DEFINED)?
 #   (constant definition), YY_\w+_INCLUDED (header guards).
 #   YYDEBUG (not renamed) can be read, but not changed.
-AT_CHECK([["$PERL" -n -0777 -e '
+AT_PERL_CHECK([[-n -0777 -e '
   s{/\*.*?\*/}{}gs;
   s{//.*}{}g;
   s{\b((defined|if)\ YYDEBUG
@@ -347,7 +347,7 @@ AT_CHECK([["$PERL" -n -0777 -e '
       print "$ARGV: invalid exported yy: $1\n";
     }
   }
-' -- *.hh *.h || exit 77]])
+' -- *.hh *.h]])
 
 # Do this late, so that other checks have been performed.
 AT_SKIP_IF_CANNOT_LINK_C_AND_CXX
diff --git a/tests/input.at b/tests/input.at
index 881938c1..f3d1578d 100644
--- a/tests/input.at
+++ b/tests/input.at
@@ -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], [],
 [[input.y:1.1-2: error: invalid characters: '\0\001\002\377?'
@@ -2184,7 +2184,7 @@ AT_DATA([empty.y],
 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], [],
 [[empty.y:2.8-9: warning: empty character literal [-Wother]
@@ -2209,7 +2209,7 @@ AT_DATA([two.y],
 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], [],
 [[two.y:2.8-11: warning: extra characters in character literal [-Wother]
@@ -2224,7 +2224,7 @@ AT_DATA([three.y],
 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], [],
 [[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
 # (well three with \n): at least Bash 3.2 converts the two-character
 # sequence "\0" into a single NUL character.
-AT_CHECK([["$PERL" -e 'print "start: \"\\\t\\\f\\\0\\\1\" ;";' >> input.y \
-           || exit 77]])
+AT_PERL_REQUIRE([[-e 'print "start: \"\\\t\\\f\\\0\\\1\" ;";' >> input.y]])
 
 AT_BISON_CHECK([input.y], [1], [],
 [[input.y:2.9-12: error: invalid number after \-escape: 777
diff --git a/tests/local.at b/tests/local.at
index 8193d93c..12443d44 100644
--- a/tests/local.at
+++ b/tests/local.at
@@ -29,6 +29,7 @@ m4_define([m4_null_if],
          [],  [$2],
          [$3])])
 
+
 # AT_SETUP_STRIP(TITLE)
 # ---------------------
 # Abbreviate the TITLE to be passed to AT_SETUP.  Remove new-lines
@@ -50,15 +51,40 @@ m4_define([AT_SETUP_STRIP],
 ## 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)
 # ------------------------------------------
 # Expect COUNT matches of the PERL-REGEXP in FILE.  The file is
 # taken in "slurp" mode, i.e., one can match end-of-lines.
 m4_define([AT_MATCHES_CHECK],
-[AT_CHECK(["$PERL" -0777 -ne '
-my $count = 0;
-s{$2}{ ++$count; "" }gem;
-printf "$count\n";' $1 || exit 77], [0], [$3
+[AT_PERL_CHECK([-0777 -ne '
+    my $count = 0;
+    s{$2}{ ++$count; "" }gem;
+    printf "$count\n";' $1], [0], [$3
 ])])
 
 
diff --git a/tests/local.mk b/tests/local.mk
index 550328ea..91fd324d 100644
--- a/tests/local.mk
+++ b/tests/local.mk
@@ -77,7 +77,7 @@ AUTOTESTFLAGS = -I $(top_srcdir)/%D%
 $(TESTSUITE): $(TESTSUITE_AT)
        $(AM_V_GEN) \
          $(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 $@
 
 
diff --git a/tests/named-refs.at b/tests/named-refs.at
index e4c3d38f..e6a36560 100644
--- a/tests/named-refs.at
+++ b/tests/named-refs.at
@@ -604,7 +604,7 @@ AT_DATA_GRAMMAR([test.y],
 start: foo[ % /* aaa */ *&-.+\000\001\002\377 ] bar
   { 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, [],
 [[test.y:11.13: error: invalid character in bracketed name: '%'
 test.y:11.25-27: error: invalid characters in bracketed name: '*&-'
diff --git a/tests/output.at b/tests/output.at
index 5f0ca876..54214eaa 100644
--- a/tests/output.at
+++ b/tests/output.at
@@ -22,11 +22,11 @@ AT_BANNER([[Output file names.]])
 # -----------------------------------------------
 # Check that the current directory contains FILE... (sorted).
 m4_define([AT_CHECK_FILES],
-[AT_CHECK([[find . -type f |
+[AT_REQUIRE([[find . -type f |
            "$PERL" -ne '
       s,\./,,; chomp;
       push @file, $_ unless m{^($2|testsuite.log)$};
-      END { print join (" ", sort @file), "\n" }' || exit 77]],
+      END { print join (" ", sort @file), "\n" }']],
           [], [$1
 ])])
 
@@ -48,7 +48,7 @@ foo: '0' {};
 ]])
 
 # 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])[
@@ -257,7 +257,7 @@ m4_define([AT_CHECK_OUTPUT_FILE_NAME],
 AT_BISON_OPTION_PUSHDEFS
 # Skip if platform doesn't support file name.  For example, Cygwin
 # 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],
 [[%glr-parser
diff --git a/tests/regression.at b/tests/regression.at
index 76f7a580..a1a85e1f 100644
--- a/tests/regression.at
+++ b/tests/regression.at
@@ -1352,19 +1352,18 @@ AT_CHECK([[grep 'syntax error,' stderr.txt]], [[0]],
 
 # Check number of default reductions in inconsistent states to be sure
 # syntax error is detected before unnecessary reductions are performed.
-AT_CHECK([["$PERL" -0777 -ne 'print s/inconsistent default reduction//g;' \
-           < stdout.txt || exit 77]], [[0]], [[14]])
+AT_PERL_CHECK([[-0777 -ne 'print s/inconsistent default reduction//g;' 
stdout.txt]],
+              [[0]], [[14]])
 
 # Check number of default reductions in consistent states to be sure
 # it is performed before the syntax error is detected.
-AT_CHECK([["$PERL" -0777 -ne 'print s/\bconsistent default reduction//g;' \
-           < stdout.txt || exit 77]], [[0]], [[2]])
+AT_PERL_CHECK([[-0777 -ne 'print s/\bconsistent default reduction//g;' 
stdout.txt]],
+              [[0]], [[2]])
 
 ]AT_C_IF([[
   # Check number of reallocs to be sure reallocated memory isn't somehow
   # lost between LAC invocations.
-  AT_CHECK([["$PERL" -0777 -ne 'print s/\(realloc//g;' < stderr.txt \
-             || exit 77]], [[0]], [[3]])
+  AT_PERL_CHECK([[-0777 -ne 'print s/\(realloc//g;' < stderr.txt]], [[0]], 
[[3]])
 ]])[
 
 AT_BISON_OPTION_POPDEFS
diff --git a/tests/skeletons.at b/tests/skeletons.at
index 6cb52497..7dbf2ba3 100644
--- a/tests/skeletons.at
+++ b/tests/skeletons.at
@@ -311,7 +311,7 @@ print '@output(@,@,@)', "\n";
 (print "garbage"x10, "\n") for (1..1000);
 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]],
 [[%skeleton "./skel.c"
diff --git a/tests/synclines.at b/tests/synclines.at
index bc63ea8b..9b585602 100644
--- a/tests/synclines.at
+++ b/tests/synclines.at
@@ -162,7 +162,7 @@ void foo (void)
 ]])
 
 _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.
 _AT_SYNCLINES_COMPILE([$1])
@@ -409,8 +409,8 @@ AT_DATA([\"\\\"\".AT_LANG_EXT],
 [[int main (void) { return 0; }
 ]])
 
-AT_CHECK([AT_CXX_IF([$CXX $CXXFLAGS], [$CC $CFLAGS]) $CPPFLAGS 
\"\\\"\".]AT_LANG_EXT[ -o \"\\\"\" ||
-          exit 77], [0], [ignore], [ignore])
+AT_REQUIRE([AT_CXX_IF([$CXX $CXXFLAGS], [$CC $CFLAGS]) $CPPFLAGS 
\"\\\"\".]AT_LANG_EXT[ -o \"\\\"\"],
+                 [0], [ignore], [ignore])
 
 AT_DATA_GRAMMAR([\"\\\"\".y],
 [[%skeleton "$1"
diff --git a/tests/torture.at b/tests/torture.at
index eeb586cd..f01871ab 100644
--- a/tests/torture.at
+++ b/tests/torture.at
@@ -27,7 +27,7 @@ m4_define([AT_INCREASE_DATA_SIZE],
 case $data_limit in
 [[0-9]]*)
   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
   fi
 esac])
@@ -120,7 +120,7 @@ EOF
 ]])
 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
 ])
 
@@ -203,7 +203,7 @@ yylex (void)
 EOF
 ]])
 
-AT_CHECK(["$PERL" -w ./gengram.pl $2 || exit 77], 0, [stdout])
+AT_PERL_REQUIRE([-w ./gengram.pl $2], 0, [stdout])
 mv stdout $1
 AT_BISON_OPTION_POPDEFS
 ])
@@ -255,7 +255,7 @@ m4_pushdef([AT_TEST],
 
 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.
 AT_FULL_COMPILE([input], [], [], [], [--no-line])
 AT_CHECK([grep 'define YYNSTATES  *$1' input.c], [], [ignore])
@@ -375,7 +375,7 @@ yylex (void)
 EOF
 ]])
 
-AT_CHECK(["$PERL" -w ./gengram.pl $2 || exit 77], 0, [stdout])
+AT_PERL_REQUIRE([-w ./gengram.pl $2], 0, [stdout])
 mv stdout $1
 AT_BISON_OPTION_POPDEFS
 ])




reply via email to

[Prev in Thread] Current Thread [Next in Thread]