From f1497356e8e24312f398f97337d85eb52d857b1a Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Mon, 4 May 2020 06:06:33 +0200 Subject: [PATCH] tests: beware of portability issues with diff -u AIX 7.1 supports diff -u, but its output does not match the expected one. Reported by Bruno Haible. https://lists.gnu.org/r/bug-bison/2020-05/msg00049.html * tests/atlocal.in (DIFF_U_WORKS): New. * tests/local.at (AT_DIFF_U_CHECK): New. * tests/existing.at (_AT_TEST_EXISTING_GRAMMAR): Use AT_DIFF_U_CHECK. --- tests/atlocal.in | 41 +++++++++++++++++++++++++++++++++++++++++ tests/existing.at | 9 ++------- tests/local.at | 10 ++++++++++ 3 files changed, 53 insertions(+), 7 deletions(-) diff --git a/tests/atlocal.in b/tests/atlocal.in index 71579802..38efc2a7 100644 --- a/tests/atlocal.in +++ b/tests/atlocal.in @@ -144,3 +144,44 @@ export LC_CTYPE # Empty if no xsltproc was found : ${XSLTPROC='@XSLTPROC@'} + + +# Some tests expect a precise diff format. See AT_DIFF_U_CHECK. +# See https://lists.gnu.org/r/bug-bison/2020-05/msg00049.html. +cat >conftest.1 <conftest.2 <conftest.expected </dev/null | sed -n '/^@@/,$p' | sed 's/^ $//' >conftest.diff +if diff conftest.expected conftest.diff >/dev/null; then + DIFF_U_WORKS=true +else + DIFF_U_WORKS=false +fi +rm conftest.* diff --git a/tests/existing.at b/tests/existing.at index 672beecb..da6287d5 100644 --- a/tests/existing.at +++ b/tests/existing.at @@ -35,14 +35,9 @@ dnl time comes, just use sed to drop the line numbers. For now, as LR(1) dnl support is rapidly evolving, let's keep that information to be careful. dnl However, we don't do diffs for canonical LR(1) because the diff is huge. m4_pushdef([AT_LALR1_DIFF_CHECK], -[dnl We need diff -u, which is not portable. -AT_CHECK([diff -u /dev/null /dev/null || exit 77], [0], [ignore]) - -AT_CHECK([[sed 's/^%define lr.type .*$//' input.y > input-lalr.y]]) +[AT_CHECK([[sed 's/^%define lr.type .*$//' input.y > input-lalr.y]]) AT_BISON_CHECK([[--report=all input-lalr.y]], [[0]], [ignore], [ignore]) -AT_CHECK([[diff -u input-lalr.output input.output \ - | sed -n '/^@@/,$p' | sed 's/^ $//']], - [[0]], [$1])]) +AT_DIFF_U_CHECK([[input-lalr.output input.output]], [$1])]) AT_TEST_TABLES_AND_PARSE([$2[: LALR(1)]], [[LALR]], [[last-state]], [[%define lr.type lalr diff --git a/tests/local.at b/tests/local.at index 97ff0e8b..11d367fc 100644 --- a/tests/local.at +++ b/tests/local.at @@ -83,6 +83,16 @@ set x `LC_ALL=C ls -l '$1'` && ## ------------- ## +# AT_DIFF_U_CHECK(DIFF-ARGS, EXPECTED-DIFF) +# ----------------------------------------- +# If diff -u works as we expect, use it, with headers stripped. +m4_define([AT_DIFF_U_CHECK], +[if $DIFF_U_WORKS; then + AT_CHECK([diff -u $1 | sed -n '/^@@/,$p' | sed 's/^ $//'], [0], [$2]) +fi +]) + + # AT_PERL_CHECK(PERL-ARGS, ...) # ----------------------------- # If Perl is available, run this test.