diff options
author | Isaac David <isacdaavid@isacdaavid.info> | 2017-10-13 01:10:06 -0500 |
---|---|---|
committer | Isaac David <isacdaavid@isacdaavid.info> | 2017-10-13 01:10:06 -0500 |
commit | 2a7b161e6aa234aa5d434f47d3aedbe48ff7b251 (patch) | |
tree | 3ae4a263bcd7b8d5fa0ef5b41798404cc5613ca4 | |
parent | ce4bc72dbd590231186267c064ae1679c2ba1241 (diff) |
blacklist test: distinguish between empty string and empty line proper
Plenty of functions in libreblacklist are expected to print empty
lines, so as to signify that the archpkg at that line in the input has
an empty accompanying field.
Printing no newline and skipping to the next archpkg is therefore a
bug; one that would pass unnoticed by current tests. This is because
command substitution removes trailing whitespace. I.e. the following
is true:
[[ $(libreblacklist get-rep <<<'') == $(libreblacklist get-rep <<<$'\n') ]]
Process substitution and pipes preserve whitespace, but only the
latter work with #!/usr/bin/env roundup, so we use that.
-rwxr-xr-x | test/lib-blacklist-test.sh | 12 | ||||
-rwxr-xr-x[-rw-r--r--] | test/test-common.sh | 8 |
2 files changed, 14 insertions, 6 deletions
diff --git a/test/lib-blacklist-test.sh b/test/lib-blacklist-test.sh index 202a2e2..1f8c518 100755 --- a/test/lib-blacklist-test.sh +++ b/test/lib-blacklist-test.sh @@ -8,9 +8,9 @@ _blacklist_url=https://projects.parabola.nu/blacklist.git/plain/blacklist.txt it_works_with_just_pkgname() { v="$(libreblacklist normalize <<<skype)"; [[ $v == 'skype::::' ]] v="$(libreblacklist get-pkg <<<skype)"; [[ $v == skype ]] - v="$(libreblacklist get-rep <<<skype)"; [[ -z $v ]] - v="$(libreblacklist get-url <<<skype)"; [[ -z $v ]] - v="$(libreblacklist get-reason <<<skype)"; [[ -z $v ]] + libreblacklist get-rep <<<skype | equals $'\n' + libreblacklist get-url <<<skype | equals $'\n' + libreblacklist get-reason <<<skype | equals $'\n' } it_works_with_everything_set() { @@ -23,7 +23,7 @@ it_works_with_everything_set() { } it_normalizes_correctly() { - v="$(libreblacklist normalize <<<'#comment')"; [[ -z $v ]] + libreblacklist normalize <<<'#comment' | equals '' v="$(libreblacklist normalize <<<pkg)"; [[ $v == 'pkg::::' ]] v="$(libreblacklist normalize <<<pkg:)"; [[ $v == 'pkg::::' ]] v="$(libreblacklist normalize <<<pkg::)"; [[ $v == 'pkg::::' ]] @@ -46,8 +46,8 @@ it_works_with_colons_in_reason() { } it_prints_urls_only_for_valid_references() { - v="$(libreblacklist get-url <<<package:::id:)"; [[ -z $v ]] - v="$(libreblacklist get-url <<<package::unknown:id:)"; [[ -z $v ]] + libreblacklist get-url <<<package:::id: | equals $'\n' + libreblacklist get-url <<<package::unknown:id: | equals $'\n' } it_fails_update_with_no_blacklist_or_network() { diff --git a/test/test-common.sh b/test/test-common.sh index 7dd8128..c0e8634 100644..100755 --- a/test/test-common.sh +++ b/test/test-common.sh @@ -109,3 +109,11 @@ not() ( } ! eval "$@" ) + +# Plain command substitution would remove trailing whitespace, despite +# being significant when testing for newline-terminated lines. +equals() { + local stdin + IFS= read -rd '' stdin || : + [[ $1 == $stdin ]] +} |