blob: 7b06f843cce2e0363018bc6fb517787ec7ea5abf (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
|
#!/usr/bin/env roundup
describe libreblacklist
. ./test-common.sh
_blacklist_url=https://projects.parabola.nu/blacklist.git/plain/blacklist.txt
before() {
_before
}
after() {
_after
}
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-reason <<<skype)"; [[ -z $v ]]
}
it_works_with_everything_set() {
line='linux:linux-libre:nonfree blobs and firmwares'
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' ]]
}
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:' ]]
}
it_works_with_colons_in_reason() {
line='package:replacement:my:reason'
v="$(libreblacklist normalize <<<"$line")"; [[ $v == "$line" ]]
v="$(libreblacklist get-pkg <<<"$line")"; [[ $v == 'package' ]]
v="$(libreblacklist get-rep <<<"$line")"; [[ $v == 'replacement' ]]
v="$(libreblacklist get-reason <<<"$line")"; [[ $v == 'my:reason' ]]
}
it_fails_update_with_no_blacklist_or_network() {
mkdir -p $XDG_CONFIG_HOME/libretools
echo "BLACKLIST='phony://example.com'" >$XDG_CONFIG_HOME/libretools/libretools.conf
libreblacklist update >$tmpdir/stdout 2>$tmpdir/stderr || stat=$?
[[ $stat != 0 ]]
empty $tmpdir/stdout
not empty $tmpdir/stderr
}
it_fails_cat_with_no_blacklist_or_network() {
mkdir -p $XDG_CONFIG_HOME/libretools
echo "BLACKLIST='phony://example.com'" >$XDG_CONFIG_HOME/libretools/libretools.conf
libreblacklist cat >$tmpdir/stdout 2>$tmpdir/stderr || stat=$?
[[ $stat != 0 ]]
empty $tmpdir/stdout
not empty $tmpdir/stderr
}
it_fails_update_when_BLACKLIST_is_unset() {
mkdir -p $XDG_CONFIG_HOME/libretools
echo "BLACKLIST=" >$XDG_CONFIG_HOME/libretools/libretools.conf
libreblacklist update >$tmpdir/stdout 2>$tmpdir/stderr || stat=$?
[[ $stat != 0 ]]
empty $tmpdir/stdout
not empty $tmpdir/stderr
}
it_fails_cat_when_syntax_error_in_conf() {
mkdir -p $XDG_CONFIG_HOME/libretools
# there is a stray single quote in there
printf "BLACKLIST='%q\n" "${_blacklist_url}" >$XDG_CONFIG_HOME/libretools/libretools.conf
libreblacklist cat >$tmpdir/stdout 2>$tmpdir/stderr || stat=$?
[[ $stat != 0 ]]
empty $tmpdir/stdout
not empty $tmpdir/stderr
}
it_downloads_the_blacklist_as_needed() {
require network || return 0
mkdir -p $XDG_CONFIG_HOME/libretools
printf 'BLACKLIST=%q\n' "${_blacklist_url}" >$XDG_CONFIG_HOME/libretools/libretools.conf
libreblacklist cat >$tmpdir/stdout 2>$tmpdir/stderr
not empty $tmpdir/stdout
}
it_downloads_the_blacklist_repeatedly() {
require network || return 0
mkdir -p $XDG_CONFIG_HOME/libretools
printf 'BLACKLIST=%q\n' "${_blacklist_url}" >$XDG_CONFIG_HOME/libretools/libretools.conf
libreblacklist update
libreblacklist update
}
it_displays_help_and_fails_with_no_args() {
LC_ALL=C libreblacklist >$tmpdir/stdout 2>$tmpdir/stderr || stat=$?
[[ $stat != 0 ]]
empty $tmpdir/stdout
[[ "$(sed 1q $tmpdir/stderr)" =~ 'Usage: libreblacklist ' ]]
}
it_displays_help_when_given_h() {
LC_ALL=C libreblacklist -h >$tmpdir/stdout 2>$tmpdir/stderr
[[ "$(sed 1q $tmpdir/stdout)" =~ 'Usage: libreblacklist ' ]]
empty $tmpdir/stderr
}
it_displays_help_when_given_h_cat() {
LC_ALL=C libreblacklist -h cat >$tmpdir/stdout 2>$tmpdir/stderr
[[ "$(sed 1q $tmpdir/stdout)" == 'Usage: libreblacklist cat' ]]
empty $tmpdir/stderr
}
|