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

describe librestage


before() {
	tmpdir=$(mktemp -d --tmpdir test-librestage.XXXXXXXXXXXX)
	stat=0

	mkdir -p $XDG_CONFIG_HOME/libretools
	echo "WORKDIR='$tmpdir/workdir'" >$XDG_CONFIG_HOME/libretools/libretools.conf

	export HOME=$XDG_CONFIG_HOME
	echo 'PKGEXT=.pkg.tar.gz' > $HOME/.makepkg.conf
	echo "PKGDEST='$tmpdir/workdir/pkgdest'" >> $HOME/.makepkg.conf
	mkdir -p "$tmpdir/workdir/pkgdest"
}

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

it_displays_usage_text() {
	librestage -h >$tmpdir/stdout 2>$tmpdir/stderr

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

it_fails_with_0_args() {
	librestage >$tmpdir/stdout 2>$tmpdir/stderr || stat=$?

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

it_fails_with_invalid_args() {
	librestage -q >$tmpdir/stdout 2>$tmpdir/stderr || stat=$?

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

# This was an actual bug I hit with md/emacs-mdmua a long time ago; solution was
# to use $(get_full_version)
it_stages_split_packages_with_different_versions() {
	cp librestage.d/PKGBUILD-split "$tmpdir/PKGBUILD"
	cd "$tmpdir"

	makepkg
	librestage '~lukeshu'

	# peak at the PKGBUILD to get this info
	[[ -f $tmpdir/workdir/staging/~lukeshu/md-0.81-4-any.pkg.tar.gz ]]
	[[ -f $tmpdir/workdir/staging/~lukeshu/emacs-mdmua-0.72-4-any.pkg.tar.gz ]]
}

it_stages_packages_to_multiple_repos() {
	cp librestage.d/PKGBUILD-hello "$tmpdir/PKGBUILD"
	cd "$tmpdir"

	makepkg
	librestage repo1 repo2 repo3

	[[ -f $tmpdir/workdir/staging/repo1/libretools-hello-1.0-1-any.pkg.tar.gz ]]
	[[ -f $tmpdir/workdir/staging/repo2/libretools-hello-1.0-1-any.pkg.tar.gz ]]
	[[ -f $tmpdir/workdir/staging/repo3/libretools-hello-1.0-1-any.pkg.tar.gz ]]
}