From 610187907f67124f1ef7a94a605d39ac3d378852 Mon Sep 17 00:00:00 2001 From: Dennis Camera Date: Sat, 17 Feb 2024 14:50:38 +0100 Subject: [PATCH] Add fallback for cmp(1) to run tests Use diff(1) if cmp(1) is missing. diff is required for showing errors anyway. --- test/run.sh | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/test/run.sh b/test/run.sh index 2d29808..8321140 100755 --- a/test/run.sh +++ b/test/run.sh @@ -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 ;; @@ -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 @@ -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?}