]> diplodocus.org Git - nmh/blobdiff - test/common.sh.in
Removed a bunch of unreachable break statements found by
[nmh] / test / common.sh.in
index 1d55dff5656aead7f891d1f634bc8fd466b8f0db..6c9652ced8c6370fa4a238f3ae1009a3f739e99e 100644 (file)
@@ -35,7 +35,7 @@ output_md5()
   #### the same line, the caller needs to add it.  This avoids
   #### differences due to a leading '*' binary file indicator, for
   #### text files, on some platforms (Cygwin).
-  @MD5SUM@ $* | @MD5FMT@ | cut -d ' ' -f 1
+  @MD5SUM@ $* | @MD5FMT@ | awk '{print $1}'
 }
 
 #### Use built-in $((...)) in test suite if shell supports it.
@@ -126,14 +126,28 @@ check_for_hard_links () {
   set -e
 }
 
+#### Filter that squeezes blank lines, partially emulating GNU cat -s,
+#### but sufficient for our purpose.
+#### From http://www-rohan.sdsu.edu/doc/sed.html, compiled by Eric Pement.
+squeeze_lines() {
+  sed '/^$/N;/\n$/D'
+}
+
+#### Filter that converts non-breakable space U+00A0 to an ASCII space.
+prepare_space() {
+  sed 's/'"`printf '\\302\\240'`"'/ /g'
+}
+
 #### check() requires two arguments, each the name of a file to be
 #### diff'ed.
 #### If the same, the second file is removed.  And the first file is
 ####   removed unless there's an optional argument with a value of
 ####   'keep first'.
 #### If different, global variable "failed" is incremented.
-#### If there's an optional 'ignore space' argument, diff -b will
-####   be used instead of cmp to compare the files.
+#### If there's an optional 'ignore space' argument, spacing differences
+####   will not be considered signficant, emulating GNU diff -w.  It
+####   is assumed that the first file has already been run through
+####   prepare_space.
 check() {
     first=$1; shift
     second=$1; shift
@@ -151,7 +165,7 @@ check() {
     success=
     if [ "$ignorespace" ]; then
         #### POSIX diff should support -b.
-        diff -b "$first" "$second" >/dev/null  &&  success=1
+        prepare_space <"$second" | diff -b "$first" - >/dev/null  &&  success=1
     else
         cmp -s "$first" "$second"  &&  success=1
     fi