X-Git-Url: https://diplodocus.org/git/nmh/blobdiff_plain/1c8cf81caa1f8d56f8812b73d37cfc62a9815877..e546c4b5abbf2025a5e346887c6b20c1ad99dbe1:/test/common.sh.in diff --git a/test/common.sh.in b/test/common.sh.in index 1f52004a..1d55dff5 100644 --- a/test/common.sh.in +++ b/test/common.sh.in @@ -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 }