summaryrefslogtreecommitdiff
path: root/test/main
blob: b98c65e7b4d61cb25f3085e038223eac99c779ef (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
#!/usr/bin/env zsh
setopt err_exit

trap "print -P '\n%N:%i: %B%F{red}Test faild!%F{default}%b'" ZERR

function stringcmp {
	diff -u <(echo $1) <(echo $2)
}

test_pdir=$(mktemp -dt pkgdir.XXXXXX)
test_proot=$(mktemp -dt pkgroot.XXXXXX)
test_home=$(mktemp -dt pkghome.XXXXXX)

cat << meow
test directories:
	PDIR = $test_pdir
	PKG_ROOT = $test_proot
	HOME = $test_home
meow

echo "# setting up PKG_ROOT"
cd $test_proot
git clone ${1-git://git.tabularazor.org/~derf/pkg} core
cp core/include/pkglist pkglist
for repo in ra rb rc; (
	mkdir $repo
	cd $repo
	git init
	touch foo
	mkdir bin
	touch bin/$repo
	mkdir -p man/2
	echo "=head1 WASTED SPACE\n\nhuhu" > man/2/$repo
	chmod 755 bin/$repo
	git add .
	git commit -m 'initial commit'
	cd ..
	mkdir ${repo}-bare
	cd ${repo}-bare
	git --bare init
	cd ../$repo
	git push ../${repo}-bare master
)

echo "# bootstrapping PDIR"
cd $test_home
export HOME=$test_home
$test_proot/core/include/bootstrap $test_proot $test_pdir

echo "# checking for success"
[[ -e $test_home/.pkg.conf ]]
[[ -d $test_proot/core ]]
[[ -d $test_pdir/core ]]
[[ -L $test_home/bin/pkg ]]
[[ -L $test_home/bin/checklinks ]]
[[ -x $(readlink $test_home/bin/pkg) ]]
[[ -x $(readlink $test_home/bin/checklinks) ]]
[[ -e $test_pdir/.collected/man/man1/pkg.1 ]]
[[ -e $test_pdir/.collected/man/man5/pkg.conf.5 ]]
[[ -e $test_pdir/.collected/man/man7/pkg.7 ]]

echo "# pkg list local"
stringcmp "core" "$(pkg list)"
stringcmp "core" "$(pkg list local)"

echo "# pkg list not-installed"
stringcmp "ra\nra-bare\nrb\nrb-bare\nrc\nrc-bare" "$(pkg list not-installed)"

echo "# pkg list all"
stringcmp "core\nra\nra-bare\nrb\nrb-bare\nrc\nrc-bare" "$(pkg list all)"

echo "# pkg add (no such repo)"
! pkg add weltfrieden

echo "# pkg add (already installed)"
! pkg add core

for repo in ra ra-bare; {
	file=${repo%-*}
	if [[ $repo == *-bare ]] {
		echo "## bare repository"
		complement=$file
	} else {
		echo "## non-bare repository"
		complement=${repo}-bare
	}
	echo "# pkg add (ok)"
	pkg add $repo
	[[ -e $test_pdir/$repo/foo ]]
	[[ -d $test_pdir/$repo/.git ]]

	echo "# pkg add (already installed)"
	! pkg add $repo

	echo "# populate_collected"
	[[ -L $test_home/bin/$file ]]
	[[ -x $(readlink $test_home/bin/$file) ]]
	[[ -e $test_pdir/.collected/man/man2/$file.2 ]]

	repeat 2 {
		echo "# pkg list"
		stringcmp "core\n$repo" "$(pkg list local)"
		stringcmp "$complement\nrb\nrb-bare\nrc\nrc-bare" "$(pkg list not-installed)"
		stringcmp "core\nra\nra-bare\nrb\nrb-bare\nrc\nrc-bare" "$(pkg list remote)"
		pkg update
	}

	echo "# pkg remove (not installed/nonexistent)"
	! pkg remove suckage
	! pkg remove rb

	echo "# pkg remove (ok)"
	pkg remove $repo

	echo "# genocide_collected (~/bin)"
	[[ ! -L $test_home/bin/$file ]]
	[[ ! -e $test_pdir/.collected/man/man2/$file.2 ]]

	repeat 2 {
		echo "# pkg list"
		stringcmp "core" "$(pkg list local)"
		stringcmp "ra\nra-bare\nrb\nrb-bare\nrc\nrc-bare" "$(pkg list not-installed)"
		stringcmp "core\nra\nra-bare\nrb\nrb-bare\nrc\nrc-bare" "$(pkg list remote)"
		pkg update
	}
}

rm -rf $test_pdir $test_proot $test_home

print -P '%F{green} test passed%F{default}'