summaryrefslogtreecommitdiff
path: root/test/main
blob: 317058a55106e6178c16d5ce24dd9f796fb9878e (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
#!/usr/bin/env zsh
unset -m 'GIT_*' 'XDG_*'
setopt err_exit

trap "print -P '\n%N:%i: %B%F{red}Test faild!%F{default}%b'" ZERR
alias ct='ct --quiet --no-colours'

source test/documentation

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

mkdir -p /tmp/cttest
tests=$PWD/test
test_pdir=$(mktemp -d /tmp/cttest/pkgdir.XXXXXX)
test_proot=$(mktemp -d /tmp/cttest/pkgroot.XXXXXX)
test_home=$(mktemp -d /tmp/cttest/pkghome.XXXXXX)

export PATH=$PWD/bin:$PATH

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

cd $test_home
export HOME=$test_home
source $tests/checklinks
(source $tests/setup)

echo "# bootstrapping PKG_DIR"
$test_proot/caretaker/examples/bootstrap file '' '' $test_proot $test_pdir

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

echo "# ct list local"
stringcmp "caretaker" "$(ct list)"
stringcmp "caretaker" "$(ct list local)"

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

echo "# ct list all"
stringcmp "caretaker\nra\nra-bare\nrb\nrb-bare\nrc\nrc-bare" "$(ct list all)"

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

echo "# ct add (already installed)"
! ct add caretaker

for repo in ra ra-bare; {
	file=${repo%-*}
	if [[ $repo == *-bare ]] {
		echo "## bare repository"
		complement=$file
	} else {
		echo "## non-bare repository"
		complement=${repo}-bare
	}
	source $tests/add
	source $tests/prereqs
	cd $test_pdir/$repo
	source $tests/push
	cd $test_pdir
	source $tests/pull-prepare
	source $tests/remove
}

rm -rf $test_pdir $test_proot $test_home

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