summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJim Meyering <meyering@redhat.com>2011-11-23 08:43:18 +0100
committerJim Meyering <meyering@redhat.com>2011-11-23 08:56:56 +0100
commit3d213a17fac0a33d9845d1511d568a68ae2035ec (patch)
tree4465b3d7b8b5ffe6d6a70eede91bf61ecd433011
parentda38f12d6f0cfcf0c990c2b8ca7e982f655540d8 (diff)
downloadcoreutils-3d213a17fac0a33d9845d1511d568a68ae2035ec.tar.xz
build: update gnulib and tests/init.sh
* gnulib: Update. * tests/init.sh: Update from gnulib.
m---------gnulib0
-rw-r--r--tests/init.sh92
2 files changed, 86 insertions, 6 deletions
diff --git a/gnulib b/gnulib
-Subproject 17febe7763c9ef38ed1ced5f08f022168e19892
+Subproject 337977d216e2759bc5b4dd3cbe223cbf8e6a9eb
diff --git a/tests/init.sh b/tests/init.sh
index 373d9d4fe..e2f61190f 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; }