From e053b211e8fa684e2bb06c90e7003ed09bed79ea Mon Sep 17 00:00:00 2001 From: P. J. McDermott Date: Wed, 20 Aug 2014 20:04:20 -0400 Subject: tests/common.sh: test_diff(): New function --- 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 +} -- cgit v0.9.1