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

# avoid carpel tunnel
pcn=pkgbuild-check-nonfree

describe $pcn

before() {
	tmpdir=$(mktemp -d --tmpdir test-pkgbuild-check-nonfree.XXXXXXXXXXXX)
	stat=0
	local blacklist=$XDG_CACHE_HOME/libretools/blacklist.txt
	mkdir -p "${blacklist%/*}"
	echo 'linux:linux-libre:nonfree blobs and firmwares' >$blacklist
	echo 'skype' >>$blacklist
}

after() {
	rm -rf -- "$tmpdir" "$XDG_CACHE_HOME" "$XDG_CONFIG_HOME"
}

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

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

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

	[[ -z "$(cat $tmpdir/stdout)" ]]
	[[ -n "$(cat $tmpdir/stderr)" ]]
	[[ $stat == 0 ]]
}

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

	[[ -z "$(cat $tmpdir/stdout)" ]]
	[[ -n "$(cat $tmpdir/stderr)" ]]
	[[ $stat == 0 ]]
}

it_fails_with_15_for_nonfree_depend() {
	$pcn $pcn.PKGBUILD.nonfree >$tmpdir/stdout 2>$tmpdir/stderr || stat=$?

	[[ -z "$(cat $tmpdir/stdout)" ]]
	[[ -n "$(cat $tmpdir/stderr)" ]]
	[[ $stat == 15 ]]
}

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

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

	[[ -z "$(cat $tmpdir/stdout)" ]]
	[[ -n "$(cat $tmpdir/stderr)" ]]
	[[ $stat != 0 ]] && [[ $stat != 15 ]]
}