summaryrefslogtreecommitdiff
path: root/test/cases/lib-blacklist.bats
blob: 4dc30c976383b5afbeeacaa5800eb04405686bd7 (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
136
load ../lib/common

@test "libreblacklist 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'
}

@test "libreblacklist 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' ]]
}

@test "libreblacklist 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' ]]
}

@test "libreblacklist 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' ]]
}

@test "libreblacklist prints urls only for valid references" {
	libreblacklist get-url <<<package:::id: | equals $'\n'
	libreblacklist get-url <<<package::unknown:id: | equals $'\n'
}

@test "libreblacklist 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
}

@test "libreblacklist 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
}

@test "libreblacklist 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
}

@test "libreblacklist 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
}

# bats test_tags=network
@test "libreblacklist downloads the blacklist as needed" {
	libreblacklist cat >$tmpdir/stdout 2>$tmpdir/stderr

	not empty $tmpdir/stdout
}

# bats test_tags=network
@test "libreblacklist downloads the blacklist repeatedly" {
	libreblacklist update
	libreblacklist update
}

@test "libreblacklist 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 ' ]]
}

@test "libreblacklist displays help when given h" {
	LC_ALL=C libreblacklist -h >$tmpdir/stdout 2>$tmpdir/stderr

	[[ "$(sed 1q $tmpdir/stdout)" =~ 'Usage: libreblacklist ' ]]
	empty $tmpdir/stderr
}

@test "libreblacklist 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
}

@test "libreblacklist checks for replacements from the repos" {
	libreblacklist get-rep <<<'linux' >$tmpdir/stdout 2>$tmpdir/stderr
	[[ "$(cat $tmpdir/stdout)" == 'libre/linux-libre' ]]
	empty $tmpdir/stderr
}