summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorP. J. McDermott <pj@pehjota.net>2014-08-20 20:04:20 (EDT)
committer P. J. McDermott <pj@pehjota.net>2014-08-20 20:04:20 (EDT)
commite053b211e8fa684e2bb06c90e7003ed09bed79ea (patch)
treec98c872940849d0eddc337d3e9bd182da69bb976
parente3ebc888bf8ccdc0c43abca3030ded378d8da389 (diff)
tests/common.sh: test_diff(): New function
-rw-r--r--tests/common.sh50
1 files changed, 50 insertions, 0 deletions
diff --git a/tests/common.sh b/tests/common.sh
index 5f8b24f..525aeb7 100644
--- a/tests/common.sh
+++ b/tests/common.sh
@@ -66,3 +66,53 @@ else
mgn='' # Magenta.
std='' # No color.
fi
+
+test_diff()
+{
+ local good_results="${1}"
+ local test_results="${2}"
+
+ printf 'Diff:\n'
+ exec 3<<-EOF
+ ${good_results}
+ EOF
+ exec 4<<-EOF
+ ${test_results}
+ EOF
+ line_no=0
+ while :; do
+ line_no=$(($line_no + 1))
+ errors=0
+ read -r good_line <&3 || errors=$(($errors + 1))
+ read -r test_line <&4 || errors=$(($errors + 1))
+ [ ${errors} -eq 2 ] && break
+ if [ "x${good_line}" = "x${test_line}" ]; then
+ printf '%3d %s\n' ${line_no} "${good_line}"
+ else
+ printf '%3d %s-%s%s\n' ${line_no} "${red}" \
+ "${good_line}" "${std}"
+ printf '%3d %s+%s%s\n' ${line_no} "${grn}" \
+ "${test_line}" "${std}"
+ tests_es=1
+ fi
+ done
+ exec 3<&-
+ exec 4<&-
+
+ printf '\nExpected results:\n'
+ line_no=0
+ while read -r line; do
+ line_no=$(($line_no + 1))
+ printf '%3d %s\n' ${line_no} "${line}"
+ done <<-EOF
+ ${good_results}
+ EOF
+ printf '\nTest results:\n'
+ line_no=0
+ while read -r line; do
+ line_no=$(($line_no + 1))
+ printf '%3d %s\n' ${line_no} "${line}"
+ done <<-EOF
+ ${test_results}
+ EOF
+}