From 3d213a17fac0a33d9845d1511d568a68ae2035ec Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Wed, 23 Nov 2011 08:43:18 +0100 Subject: [PATCH] build: update gnulib and tests/init.sh * gnulib: Update. * tests/init.sh: Update from gnulib. --- gnulib | 2 +- tests/init.sh | 92 +++++++++++++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 87 insertions(+), 7 deletions(-) diff --git a/gnulib b/gnulib index 17febe7..337977d 160000 --- a/gnulib +++ b/gnulib @@ -1 +1 @@ -Subproject commit 17febe7763c9ef38ed1ced5f08f022168e198929 +Subproject commit 337977d216e2759bc5b4dd3cbe223cbf8e6a9eb7 diff --git a/tests/init.sh b/tests/init.sh index 373d9d4..e2f6119 100644 --- a/tests/init.sh +++ b/tests/init.sh @@ -221,16 +221,96 @@ export MALLOC_PERTURB_ # a partition, or to undo any other global state changes. cleanup_ () { :; } -if ( diff -u "$0" "$0" < /dev/null ) > /dev/null 2>&1; then - compare () { diff -u "$@"; } -elif ( diff -c "$0" "$0" < /dev/null ) > /dev/null 2>&1; then - compare () { diff -c "$@"; } +# Emit a header similar to that from diff -u; Print the simulated "diff" +# command so that the order of arguments is clear. Don't bother with @@ lines. +emit_diff_u_header_ () +{ + printf '%s\n' "diff -u $*" \ + "--- $1 1970-01-01" \ + "+++ $2 1970-01-01" +} + +# Arrange not to let diff or cmp operate on /dev/null, +# since on some systems (at least OSF/1 5.1), that doesn't work. +# When there are not two arguments, or no argument is /dev/null, return 2. +# When one argument is /dev/null and the other is not empty, +# cat the nonempty file to stderr and return 1. +# Otherwise, return 0. +compare_dev_null_ () +{ + test $# = 2 || return 2 + + if test "x$1" = x/dev/null; then + test -s "$2" || return 0 + { emit_diff_u_header_ "$@"; sed 's/^/+/' -- "$2"; } >&2 + return 1 + fi + + if test "x$2" = x/dev/null; then + test -s "$1" || return 0 + { emit_diff_u_header_ "$@"; sed 's/^/-/' -- "$1"; } >&2 + return 1 + fi + + return 2 +} + +if diff_out_=`( diff -u "$0" "$0" < /dev/null ) 2>/dev/null`; then + if test -z "$diff_out_"; then + compare_ () { diff -u "$@"; } + else + compare_ () + { + if diff -u "$@" > diff.out; then + # No differences were found, but Solaris 'diff' produces output + # "No differences encountered". Hide this output. + rm -f diff.out + true + else + cat diff.out + rm -f diff.out + false + fi + } + fi +elif diff_out_=`( diff -c "$0" "$0" < /dev/null ) 2>/dev/null`; then + if test -z "$diff_out_"; then + compare_ () { diff -c "$@"; } + else + compare_ () + { + if diff -c "$@" > diff.out; then + # No differences were found, but AIX and HP-UX 'diff' produce output + # "No differences encountered" or "There are no differences between the + # files.". Hide this output. + rm -f diff.out + true + else + cat diff.out + rm -f diff.out + false + fi + } + fi elif ( cmp --version < /dev/null 2>&1 | grep GNU ) > /dev/null 2>&1; then - compare () { cmp -s "$@"; } + compare_ () { cmp -s "$@"; } else - compare () { cmp "$@"; } + compare_ () { cmp "$@"; } fi +# Usage: compare EXPECTED ACTUAL +# +# Given compare_dev_null_'s preprocessing, defer to compare_ if 2 or more. +# Otherwise, propagate $? to caller: any diffs have already been printed. +compare () +{ + compare_dev_null_ "$@" + case $? in + 0|1) return $?;; + *) compare_ "$@";; + esac +} + # An arbitrary prefix to help distinguish test directories. testdir_prefix_ () { printf gt; } -- 2.7.4