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

describe librefetch

. ./test-common.sh

before() {
	_before

	mkdir -p "$XDG_CONFIG_HOME"/{pacman,libretools} "$tmpdir/srcdest"

	cat <<EOF > "$XDG_CONFIG_HOME/pacman/makepkg.conf"
DLAGENTS=('ftp::/usr/bin/curl -fC - --ftp-pasv --retry 3 --retry-delay 3 -o %o %u'
          'http::/usr/bin/curl -fLC - --retry 3 --retry-delay 3 -o %o %u'
          'https::/usr/bin/curl -fLC - --retry 3 --retry-delay 3 -o %o %u'
          'rsync::/usr/bin/rsync --no-motd -z %u %o'
          'scp::/usr/bin/scp -C %u %o')
BUILDDIR=""
SRCDEST=$tmpdir/srcdest
. ${_librelib_conf_sh_pkgconfdir}/librefetch-makepkg.conf
EOF
	sed -i 's,/usr/bin/librefetch,$(which librefetch),' \
	    "${_librelib_conf_sh_pkgconfdir}/librefetch-makepkg.conf"

	export MAKEPKG_CONF="$XDG_CONFIG_HOME/pacman/makepkg.conf"

	printf '%s\n' \
		'MIRRORS=("phony://example.com/dir/")' \
		'DOWNLOADER=/usr/bin/false' \
		> "$XDG_CONFIG_HOME/libretools/librefetch.conf"
}

after() {
	_after
}

it_displays_help() {
	LC_ALL=C librefetch -h >$tmpdir/stdout 2>$tmpdir/stderr

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

# This test also does a rough test of file order in the PKGBUILD, as
# well as making sure that it correctly keeps track of $BUILDDIR,
# $startdir, and $SRCDEST.
it_cleans_src_libre_first() {
	cp librefetch.d/* "$tmpdir/"
	cd "$tmpdir"

	# create garbage
	mkdir -p src-libre/foo
	touch src-libre/foo/file

	# run librefetch
	makepkg -g

	srcball=testpkg-1.0.tar.gz
	bsdtar tf "$tmpdir/srcdest/$srcball" > list-pkg.txt
	diff -u list.txt list-pkg.txt
}