diff options
author | Bryan Drewery <bryan@shatow.net> | 2022-11-08 02:34:18 +0300 |
---|---|---|
committer | Bryan Drewery <bryan@shatow.net> | 2022-11-08 03:00:37 +0300 |
commit | 8b85bbe642d3f77d512e9d27111ae29aa16d2811 (patch) | |
tree | 0d0434ed7c368653b83ca0285b90f7b22d9a8e9f | |
parent | 3b5effefb202faea901b677e1d53cf258dc4effb (diff) |
tests: Make the long list failures easier to understand
-rw-r--r-- | test/common.bulk.sh | 12 | ||||
-rw-r--r-- | test/common.sh | 40 |
2 files changed, 41 insertions, 11 deletions
diff --git a/test/common.bulk.sh b/test/common.bulk.sh index 5041e5bf..57ce05f3 100644 --- a/test/common.bulk.sh +++ b/test/common.bulk.sh @@ -507,26 +507,22 @@ assert_bulk_queue_and_stats() { # Assert the listed which are ignored is right # This is testing the test framework - assert "$(sorted ${EXPECTED_LISTPORTS_IGNORED})" \ - "$(sorted ${LISTPORTS_IGNORED-null})" \ + assert_list EXPECTED_LISTPORTS_IGNORED LISTPORTS_IGNORED \ "(test framework) LISTPORTS_IGNORED should match" # Assert the non-ignored ports list is right # This is testing the test framework - assert "$(sorted ${EXPECTED_LISTPORTS_NOIGNORED})" \ - "$(sorted ${LISTPORTS_NOIGNORED-null})" \ + assert_list EXPECTED_LISTPORTS_NOIGNORED LISTPORTS_NOIGNORED \ "(test framework) LISTPORTS_NOIGNORED should match" # Assert that IGNOREDPORTS was populated by the framework right. # This is testing the test framework - assert "$(sorted ${EXPECTED_IGNORED-})" \ - "$(sorted ${IGNOREDPORTS-null})" \ + assert_list EXPECTED_IGNORED IGNOREDPORTS \ "(test framework) IGNOREDPORTS should match" # Assert that skipped ports are right # This is testing the test framework - assert "$(sorted ${EXPECTED_SKIPPED-})" \ - "$(sorted ${SKIPPEDPORTS-null})" \ + assert_list EXPECTED_SKIPPED SKIPPEDPORTS \ "(test framework) SKIPPEDPORTS should match" ### Now do tests against the output of the bulk run. ### diff --git a/test/common.sh b/test/common.sh index 644207ee..0e61b4fb 100644 --- a/test/common.sh +++ b/test/common.sh @@ -22,7 +22,6 @@ write_atomic_cmp() { fi } - CMD="${0##*/}" IN_TEST=1 SCRIPTPATH="${SCRIPTPREFIX}/${CMD}" @@ -125,6 +124,40 @@ _assert_not() { } alias assert_not='_assert_not "$0:$LINENO"' +_assert_list() { + local lineinfo="$1" + local expected_name="$2" + local actual_name="$3" + local reason="$4" + local have_tmp=$(mktemp -t actual.${actual_name}) + local expected_tmp=$(mktemp -t expected.${expected_name}) + local ret=0 + local expected actual + + getvar "${expected_name}" expected || expected="null" + getvar "${actual_name}" actual || actual="null" + + echo "${expected}" | + tr ' ' '\n' | env LC_ALL=C sort | + sed -e '/^$/d' > "${expected_tmp}" + echo "${actual}" | + tr ' ' '\n' | env LC_ALL=C sort | + sed -e '/^$/d' > "${have_tmp}" + cmp -s "${have_tmp}" "${expected_tmp}" || ret=$? + if [ "${ret}" -ne 0 ]; then + diff -u "${expected_tmp}" "${have_tmp}" >&2 + fi + + rm -f "${have_tmp}" "${expected_tmp}" + if [ "${ret}" -ne 0 ]; then + aecho FAIL "${lineinfo}" "${reason}" + exit ${EXITVAL} + fi + aecho OK "${lineinfo}" #"${msg}: expected: '${expected}', actual: '${actual}'" +} +alias assert_list='_assert_list "$0:$LINENO"' + + _assert_ret() { local lineinfo="$1" local expected="$2" @@ -153,7 +186,7 @@ aecho() { local result="$1" local lineinfo="$2" - if [ $# -gt 2 ]; then + if [ "$#" -gt 3 ]; then # Failure local expected="$3" local actual="$4" @@ -165,8 +198,9 @@ aecho() { "$(echo "$@" | cat -ev | sed '2,$s,^, ,')" \ "$(echo "${expected}" | cat -ev | sed '2,$s,^, ,')" \ "$(echo "${actual}" | cat -ev | sed '2,$s,^, ,')" + elif [ "$#" -eq 3 ]; then + printf "> %-4s %s: %s\n" "${result}" "${lineinfo}" "${3}" else - # Success printf "> %-4s %s\n" "${result}" "${lineinfo}" fi >&2 } |