From 9aed413b06212a4620641124164f6d1a7047c9c9 Mon Sep 17 00:00:00 2001 From: Thomas Beutlich Date: Tue, 13 Aug 2024 21:13:28 +0200 Subject: [PATCH] Fix diff command to only set --strip-trailing-cr if available --- tests/test1.sh | 14 +++++++++++++- tests/test2.sh | 15 ++++++++++++++- tests/test3.sh | 15 ++++++++++++++- 3 files changed, 41 insertions(+), 3 deletions(-) diff --git a/tests/test1.sh b/tests/test1.sh index c21ffbc..e73a333 100755 --- a/tests/test1.sh +++ b/tests/test1.sh @@ -34,7 +34,19 @@ echo ------------------------------------------------------------------------- } > s1.out -if result=$(diff --strip-trailing-cr "$EXPECT" "s1.out"); then +supports_strip_trailing_cr() { + diff --help 2>/dev/null | grep -q -- '--strip-trailing-cr' +} + +run_diff() { + if supports_strip_trailing_cr; then + diff --strip-trailing-cr "$EXPECT" "s1.out" + else + diff "$EXPECT" "s1.out" + fi +} + +if result=$(run_diff); then echo "******* Stream 1 Succeeded *********" exit 0 else diff --git a/tests/test2.sh b/tests/test2.sh index 9a906f9..5c3e1fb 100755 --- a/tests/test2.sh +++ b/tests/test2.sh @@ -12,7 +12,20 @@ for i in 0 1 2 3 4 5 6 7 8 9 10 11 12 13; do "${SHPDUMP:-./shpdump}" test${i}.shp done > "s2.out" -if result=$(diff --strip-trailing-cr "$EXPECT" "s2.out"); then + +supports_strip_trailing_cr() { + diff --help 2>/dev/null | grep -q -- '--strip-trailing-cr' +} + +run_diff() { + if supports_strip_trailing_cr; then + diff --strip-trailing-cr "$EXPECT" "s2.out" + else + diff "$EXPECT" "s2.out" + fi +} + +if result=$(run_diff); then echo "******* Stream 2 Succeeded *********" exit 0 else diff --git a/tests/test3.sh b/tests/test3.sh index 023dcdf..8067e58 100755 --- a/tests/test3.sh +++ b/tests/test3.sh @@ -27,7 +27,20 @@ readonly EXPECT="${1:-$SCRIPTDIR/expect3.out}" "${DBFDUMP:-./dbfdump}" test.dbf } > s3.out -if result=$(diff --strip-trailing-cr "$EXPECT" "s3.out"); then + +supports_strip_trailing_cr() { + diff --help 2>/dev/null | grep -q -- '--strip-trailing-cr' +} + +run_diff() { + if supports_strip_trailing_cr; then + diff --strip-trailing-cr "$EXPECT" "s3.out" + else + diff "$EXPECT" "s3.out" + fi +} + +if result=$(run_diff); then echo "******* Stream 3 Succeeded *********" exit 0 else