X-Git-Url: https://diplodocus.org/git/nmh/blobdiff_plain/1c8cf81caa1f8d56f8812b73d37cfc62a9815877..70a3fbf967717678e2edd0fb2c992e5a2c59a2b0:/test/common.sh.in diff --git a/test/common.sh.in b/test/common.sh.in index 1f52004a..70214127 100644 --- a/test/common.sh.in +++ b/test/common.sh.in @@ -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. @@ -129,20 +129,45 @@ check_for_hard_links () { #### 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 the optional third argument has a value of +#### 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. check() { - #### POSIX diff should support -c. - if cmp -s "$1" "$2"; then - test $# -lt 3 -o "$3" != 'keep first' && rm -f "$1" - rm -f "$2" + first=$1; shift + second=$1; shift + keepfirst= + ignorespace= + while [ $# -gt 0 ]; do + case $1 in + 'keep first') keepfirst=1 ;; + 'ignore space') ignorespace=1 ;; + *) echo "$0: invalid check() argument \"$1\" in test suite" >&2 ;; + esac + shift + done + + success= + if [ "$ignorespace" ]; then + #### POSIX diff should support -b. + diff -b "$first" "$second" >/dev/null && success=1 + else + cmp -s "$first" "$second" && success=1 + fi + + if [ "$success" ]; then + [ "$keepfirst" ] || rm -f "$first" + rm -f "$second" else - echo - diff -c "$1" "$2" || true - echo - echo "$0: test failed, outputs are in $1 and $2." - failed=`expr ${failed:-0} + 1` + echo + #### POSIX diff should support -c. + diff -c "$first" "$second" || true + echo + echo "$0: test failed, outputs are in $first and $second." + failed=`expr ${failed:-0} + 1` + #### Set return status of the function. + [ $failed -eq 0 ] fi }