summaryrefslogtreecommitdiff
path: root/test/pkgbuild-check-nonfree-test.sh
blob: e6679edd5753e68c41d2328992b5be9c49f5d236 (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
#!/usr/bin/env roundup

# avoid carpel tunnel
pcn=pkgbuild-check-nonfree
psn=pkgbuild-summarize-nonfree

describe $pcn
. ./test-common.sh

common_before() {
	mkdir -p $XDG_CONFIG_HOME/libretools
	echo "BLACKLIST='phony://example.com'" >$XDG_CONFIG_HOME/libretools/libretools.conf

	local blacklist=$XDG_CACHE_HOME/libretools/blacklist.txt
	mkdir -p "${blacklist%/*}"
	echo 'linux:linux-libre:nonfree blobs and firmwares' >$blacklist
	echo 'skype' >>$blacklist
}

it_displays_usage_text() {
	# This test seems silly, but it makes sure that it is executable,
	# syntactically correct,  and loading libraries works.
	LC_ALL=C $pcn -h >$tmpdir/stdout 2>$tmpdir/stderr
	stat=$?

	[[ "$(sed 1q $tmpdir/stdout)" =~ Usage:.* ]]
	empty $tmpdir/stderr
	[[ $stat == 0 ]]
}

it_succeeds_for_free_depends() {
	$pcn $pcn.d/PKGBUILD.free >$tmpdir/stdout 2>$tmpdir/stderr || stat=$?

	empty $tmpdir/stdout
	not empty $tmpdir/stderr
	[[ $stat == 0 ]]
}

it_succeeds_for_nonfree_depend_with_replacement() {
	$pcn $pcn.d/PKGBUILD.nonfree-replacement >$tmpdir/stdout 2>$tmpdir/stderr || stat=$?

	empty $tmpdir/stdout
	not empty $tmpdir/stderr
	[[ $stat == 0 ]]
}

it_fails_for_nonfree_depend() {
	$pcn $pcn.d/PKGBUILD.nonfree >$tmpdir/stdout 2>$tmpdir/stderr || stat=$?
	[[ $stat != 0 ]]
	empty $tmpdir/stdout
	not empty $tmpdir/stderr

	local pcn_stat=$stat

	$psn $pcn_stat >$tmpdir/stdout 2>$tmpdir/stderr || stat=$?
	[[ $stat != 0 ]]
	empty $tmpdir/stdout
	not empty $tmpdir/stderr
}

it_fails_when_there_is_no_blacklist() {
	mkdir -p $XDG_CONFIG_HOME/libretools
	echo "BLACKLIST='phony://example.com'" >$XDG_CONFIG_HOME/libretools/libretools.conf
	rm $XDG_CACHE_HOME/libretools/blacklist.txt

	$pcn $pcn.d/PKGBUILD.free >$tmpdir/stdout 2>$tmpdir/stderr || stat=$?

	empty $tmpdir/stdout
	not empty $tmpdir/stderr
	[[ $stat != 0 ]] && [[ $stat != 15 ]]
}