Skip to content

Commit

Permalink
Add fallback for cmp(1) to run tests
Browse files Browse the repository at this point in the history
Use diff(1) if cmp(1) is missing.
diff is required for showing errors anyway.
  • Loading branch information
sideeffect42 committed Feb 17, 2024
1 parent 56b4fa8 commit 6101879
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions test/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,19 @@ set -e -u
: "${AWK:=awk}"
: "${YGPP:=$(cd "${0%/*}/.." && pwd -P)/ygpp}"

tests_dir=${0%/*}

if command -v cmp >/dev/null 2>&1
then
check_same() { cmp -s "$1" "$2"; }
elif command -v diff >/dev/null 2>&1
then
check_same() { diff -q "$1" "$2" >/dev/null; }
else
echo 'Missing diff(1) on this system.' >&2
exit 1
fi

case ${NOCOLOR+0}
in
(0) coloured_output=false ;;
Expand Down Expand Up @@ -37,8 +50,6 @@ else
showdiff() { dodiff "$@"; }
fi

tests_dir=${0%/*}

tmpdir=$(mktemp -d)
test -d "${tmpdir-}" || exit 1
trap 'rm -R -f "${tmpdir}"' EXIT
Expand Down Expand Up @@ -99,8 +110,8 @@ do

if
test $((test_rc)) -eq $((expect_status)) \
&& cmp -s "${expect_out}" "${test_out}" \
&& cmp -s "${expect_err}" "${test_err}"
&& check_same "${expect_out}" "${test_out}" \
&& check_same "${expect_err}" "${test_err}"
then
${STDOUT_ISATTY?} && printf '\r'
if ${coloured_output?}
Expand Down

0 comments on commit 6101879

Please sign in to comment.