bug-gnulib
[Top][All Lists]
Advanced

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

[PATCH] init.sh: make "compare /dev/null FILE" output more readable


From: Jim Meyering
Subject: [PATCH] init.sh: make "compare /dev/null FILE" output more readable
Date: Wed, 23 Nov 2011 08:42:47 +0100

No feedback probably just means no review, but that's ok.
I've gone ahead and pushed this:

>From 337977d216e2759bc5b4dd3cbe223cbf8e6a9eb7 Mon Sep 17 00:00:00 2001
From: Jim Meyering <address@hidden>
Date: Tue, 22 Nov 2011 14:51:45 +0100
Subject: [PATCH] init.sh: make "compare /dev/null FILE" output more readable

* tests/init.sh (compare_): Document the preferred order of arguments.
(emit_diff_u_header_): New function.
(compare_dev_null_): Emit a simulated diff, rather than just the
contents of the unexpected file.  Suggestion from Bruno Haible.
---
 ChangeLog     |    8 ++++++++
 tests/init.sh |   28 ++++++++++++++++++++--------
 2 files changed, 28 insertions(+), 8 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 0fbcf89..b9e5d59 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2011-11-22  Jim Meyering  <address@hidden>
+
+       init.sh: make "compare /dev/null FILE" output more readable
+       * tests/init.sh (compare_): Document the preferred order of arguments.
+       (emit_diff_u_header_): New function.
+       (compare_dev_null_): Emit a simulated diff, rather than just the
+       contents of the unexpected file.  Suggestion from Bruno Haible.
+
 2011-11-21  Jim Meyering  <address@hidden>
            Eric Blake  <address@hidden>

diff --git a/tests/init.sh b/tests/init.sh
index 5079010..e2f6119 100644
--- a/tests/init.sh
+++ b/tests/init.sh
@@ -221,6 +221,15 @@ export MALLOC_PERTURB_
 # a partition, or to undo any other global state changes.
 cleanup_ () { :; }

+# 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.
@@ -232,17 +241,18 @@ compare_dev_null_ ()
   test $# = 2 || return 2

   if test "x$1" = x/dev/null; then
-    set dummy "$2" "$1"; shift
+    test -s "$2" || return 0
+    { emit_diff_u_header_ "$@"; sed 's/^/+/' -- "$2"; } >&2
+    return 1
   fi

-  test "x$2" = x/dev/null || return 2
-
-  test -s "$1" || return 0
+  if test "x$2" = x/dev/null; then
+    test -s "$1" || return 0
+    { emit_diff_u_header_ "$@"; sed 's/^/-/' -- "$1"; } >&2
+    return 1
+  fi

-  cat - "$1" <<EOF >&2
-Unexpected contents of $1:
-EOF
-  return 1
+  return 2
 }

 if diff_out_=`( diff -u "$0" "$0" < /dev/null ) 2>/dev/null`; then
@@ -288,6 +298,8 @@ else
   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 ()
--
1.7.8.rc3.23.ge14d6



reply via email to

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