summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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
+}