blob: 32d700d52812f6de9c600dfe5b7d905a006c4791 (
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
135
|
#!/usr/bin/env roundup
describe libreblacklist
. ./test-common.sh
it_works_with_just_pkgname() {
v="$(libreblacklist normalize <<<skype)"; [[ $v == 'skype::::' ]]
v="$(libreblacklist get-pkg <<<skype)"; [[ $v == skype ]]
libreblacklist get-rep <<<irreplaceable | equals $'\n'
libreblacklist get-url <<<skype | equals $'\n'
libreblacklist get-reason <<<skype | equals $'\n'
}
it_works_with_everything_set() {
line='linux:conflict:parabola:id:[semifree] blobs and firmware'
v="$(libreblacklist normalize <<<"$line")"; [[ $v == "$line" ]]
v="$(libreblacklist get-pkg <<<"$line")"; [[ $v == 'linux' ]]
v="$(libreblacklist get-rep <<<"$line")"; [[ $v == 'libre/linux-libre' ]]
v="$(libreblacklist get-url <<<"$line")"; [[ $v == 'https://labs.parabola.nu/issues/id' ]]
v="$(libreblacklist get-reason <<<"$line")"; [[ $v == '[semifree] blobs and firmware' ]]
}
it_normalizes_correctly() {
libreblacklist normalize <<<'#comment' | equals ''
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:conflict:parabola:id:my:reason'
v="$(libreblacklist normalize <<<"$line")"; [[ $v == "$line" ]]
v="$(libreblacklist get-pkg <<<"$line")"; [[ $v == 'package' ]]
libreblacklist get-rep <<<"$line" | equals $'\n'
v="$(libreblacklist get-url <<<"$line")"; [[ $v == 'https://labs.parabola.nu/issues/id' ]]
v="$(libreblacklist get-reason <<<"$line")"; [[ $v == 'my:reason' ]]
}
it_prints_urls_only_for_valid_references() {
libreblacklist get-url <<<package:::id: | equals $'\n'
libreblacklist get-url <<<package::unknown:id: | equals $'\n'
}
it_fails_update_with_no_blacklist_or_network() {
cat >> "$XDG_CONFIG_HOME/libretools/libretools.conf" <<-eot
BLACKLIST='phony://example.com'
eot
libreblacklist update >$tmpdir/stdout 2>$tmpdir/stderr || status=$?
[[ $status != 0 ]]
empty $tmpdir/stdout
not empty $tmpdir/stderr
}
it_fails_cat_with_no_blacklist_or_network() {
cat >> "$XDG_CONFIG_HOME/libretools/libretools.conf" <<-eot
BLACKLIST='phony://example.com'
eot
libreblacklist cat >$tmpdir/stdout 2>$tmpdir/stderr || status=$?
[[ $status != 0 ]]
empty $tmpdir/stdout
not empty $tmpdir/stderr
}
it_fails_update_when_BLACKLIST_is_unset() {
cat >> "$XDG_CONFIG_HOME/libretools/libretools.conf" <<-eot
BLACKLIST=
eot
libreblacklist update >$tmpdir/stdout 2>$tmpdir/stderr || status=$?
[[ $status != 0 ]]
empty $tmpdir/stdout
not empty $tmpdir/stderr
}
it_fails_cat_when_syntax_error_in_conf() {
# there is a stray single quote in there
cat >> "$XDG_CONFIG_HOME/libretools/libretools.conf" <<-eot
BLACKLIST='https://git.parabola.nu/blacklist.git/plain/blacklist.txt
eot
libreblacklist cat >$tmpdir/stdout 2>$tmpdir/stderr || status=$?
[[ $status != 0 ]]
empty $tmpdir/stdout
not empty $tmpdir/stderr
}
it_downloads_the_blacklist_as_needed() {
require network || return 0
libreblacklist cat >$tmpdir/stdout 2>$tmpdir/stderr
not empty $tmpdir/stdout
}
it_downloads_the_blacklist_repeatedly() {
require network || return 0
libreblacklist update
libreblacklist update
}
it_displays_help_and_fails_with_no_args() {
LC_ALL=C libreblacklist >$tmpdir/stdout 2>$tmpdir/stderr || status=$?
[[ $status != 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
}
|