summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIsaac David <isacdaavid@isacdaavid.info>2017-10-07 19:34:01 -0500
committerIsaac David <isacdaavid@isacdaavid.info>2017-10-07 19:34:01 -0500
commita5de5ff031412c0319dc292d40ee60898d90e064 (patch)
tree93ebaab6d278d3f5eed7aeff2ec2e12aae0f8dcc
parent23abe8b1b17e9fc0236d40e9b6e5106a81af5ff3 (diff)
blacklist.sh: update `normalize` and `get-reason` to reflect blacklist.txt
the blacklist has had a couple extra fields (ref, id) for some time, but `libreblacklist` was never made aware of the change. this updates test/lib-blacklist-test.sh for the same reason, and adds a test for comment stripping under `it_normalizes_correctly()`.
-rwxr-xr-x[-rw-r--r--]src/lib/blacklist.sh8
-rwxr-xr-x[-rw-r--r--]test/lib-blacklist-test.sh26
2 files changed, 21 insertions, 13 deletions
diff --git a/src/lib/blacklist.sh b/src/lib/blacklist.sh
index 249ee89..6c507f4 100644..100755
--- a/src/lib/blacklist.sh
+++ b/src/lib/blacklist.sh
@@ -24,7 +24,11 @@
# Usage: blacklist-normalize <$file
# Normalizes the syntax of the blacklist on stdin.
blacklist-normalize() {
- sed -e '/^#/d' -e 's/^[^:]*$/&::/' -e 's/^[^:]*:[^:]*$/&:/'
+ sed -r -e '/^#/d' \
+ -e 's/^[^:]*$/&::::/' \
+ -e 's/^[^:]*:[^:]*$/&:::/' \
+ -e 's/^[^:]*(:[^:]*){2}$/&::/' \
+ -e 's/^[^:]*(:[^:]*){3}$/&:/'
}
# Usage: blacklist-cat
@@ -91,5 +95,5 @@ blacklist-get-rep() {
# Usage: blacklist-cat | blacklist-get-reason
# Prints only the reason field of the blacklist line(s) on stdin.
blacklist-get-reason() {
- blacklist-normalize | cut -d: -f3-
+ blacklist-normalize | cut -d: -f5-
}
diff --git a/test/lib-blacklist-test.sh b/test/lib-blacklist-test.sh
index 49c756e..ef99f91 100644..100755
--- a/test/lib-blacklist-test.sh
+++ b/test/lib-blacklist-test.sh
@@ -6,32 +6,36 @@ describe libreblacklist
_blacklist_url=https://projects.parabola.nu/blacklist.git/plain/blacklist.txt
it_works_with_just_pkgname() {
- v="$(libreblacklist normalize <<<skype)"; [[ $v == 'skype::' ]]
+ v="$(libreblacklist normalize <<<skype)"; [[ $v == 'skype::::' ]]
v="$(libreblacklist get-pkg <<<skype)"; [[ $v == skype ]]
v="$(libreblacklist get-rep <<<skype)"; [[ -z $v ]]
v="$(libreblacklist get-reason <<<skype)"; [[ -z $v ]]
}
it_works_with_everything_set() {
- line='linux:linux-libre:nonfree blobs and firmwares'
+ line='linux:linux-libre:fsf:id:[semifree] blobs and firmware'
v="$(libreblacklist normalize <<<"$line")"; [[ $v == "$line" ]]
v="$(libreblacklist get-pkg <<<"$line")"; [[ $v == 'linux' ]]
v="$(libreblacklist get-rep <<<"$line")"; [[ $v == 'linux-libre' ]]
- v="$(libreblacklist get-reason <<<"$line")"; [[ $v == 'nonfree blobs and firmwares' ]]
+ v="$(libreblacklist get-reason <<<"$line")"; [[ $v == '[semifree] blobs and firmware' ]]
}
it_normalizes_correctly() {
- v="$(libreblacklist normalize <<<pkg)"; [[ $v == 'pkg::' ]]
- v="$(libreblacklist normalize <<<pkg:)"; [[ $v == 'pkg::' ]]
- v="$(libreblacklist normalize <<<pkg::)"; [[ $v == 'pkg::' ]]
- v="$(libreblacklist normalize <<<pkg:rep)"; [[ $v == 'pkg:rep:' ]]
- v="$(libreblacklist normalize <<<pkg:rep:)"; [[ $v == 'pkg:rep:' ]]
- v="$(libreblacklist normalize <<<pkg:rep:reason)"; [[ $v == 'pkg:rep:reason' ]]
- v="$(libreblacklist normalize <<<pkg:rep:reason:)"; [[ $v == 'pkg:rep:reason:' ]]
+ v="$(libreblacklist normalize <<<'#comment')"; [[ -z $v ]]
+ v="$(libreblacklist normalize <<<pkg)"; [[ $v == 'pkg::::' ]]
+ v="$(libreblacklist normalize <<<pkg:)"; [[ $v == 'pkg::::' ]]
+ v="$(libreblacklist normalize <<<pkg::)"; [[ $v == 'pkg::::' ]]
+ v="$(libreblacklist normalize <<<pkg:rep)"; [[ $v == 'pkg:rep:::' ]]
+ v="$(libreblacklist normalize <<<pkg:rep:)"; [[ $v == 'pkg:rep:::' ]]
+ v="$(libreblacklist normalize <<<pkg:rep:ref)"; [[ $v == 'pkg:rep:ref::' ]]
+ v="$(libreblacklist normalize <<<pkg:rep:ref:)"; [[ $v == 'pkg:rep:ref::' ]]
+ v="$(libreblacklist normalize <<<pkg:rep:ref:id)"; [[ $v == 'pkg:rep:ref:id:' ]]
+ v="$(libreblacklist normalize <<<pkg:rep:ref:id:)"; [[ $v == 'pkg:rep:ref:id:' ]]
+ v="$(libreblacklist normalize <<<pkg:rep:ref:id:reason)"; [[ $v == 'pkg:rep:ref:id:reason' ]]
}
it_works_with_colons_in_reason() {
- line='package:replacement:my:reason'
+ line='package:replacement:ref:id:my:reason'
v="$(libreblacklist normalize <<<"$line")"; [[ $v == "$line" ]]
v="$(libreblacklist get-pkg <<<"$line")"; [[ $v == 'package' ]]
v="$(libreblacklist get-rep <<<"$line")"; [[ $v == 'replacement' ]]