summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAkim Demaille <akim.demaille@gmail.com>2020-05-04 06:06:33 +0200
committerAkim Demaille <akim.demaille@gmail.com>2020-05-04 06:48:00 +0200
commitf1497356e8e24312f398f97337d85eb52d857b1a (patch)
treeb652b1d9f543cbb2faf8a5782a2b5a03e0214a2b
parent1429569362581712ab71ed0704da384301098b7d (diff)
downloadbison-f1497356e8e24312f398f97337d85eb52d857b1a.tar.gz
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.
-rw-r--r--tests/atlocal.in41
-rw-r--r--tests/existing.at9
-rw-r--r--tests/local.at10
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 <<EOF
+1
+2
+3
+4
+5
+6
+EOF
+
+cat >conftest.2 <<EOF
+1
+22
+3
+4
+55
+6
+EOF
+
+cat >conftest.expected <<EOF
+@@ -1,6 +1,6 @@
+ 1
+-2
++22
+ 3
+ 4
+-5
++55
+ 6
+EOF
+
+diff -u conftest.1 conftest.2 2>/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.