-
Notifications
You must be signed in to change notification settings - Fork 11
/
test.bats
executable file
·154 lines (130 loc) · 4.48 KB
/
test.bats
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#!/usr/bin/env bats
APACMAN="./apacman"
RPCURL="https://aur.archlinux.org/rpc/?v=5&type"
fakedir="${TMPDIR:-/tmp}/testing"
testing="--testing"
noconfirm="--noconfirm"
buildonly="--buildonly"
nofail="--nofail"
skipcache="--skipcache"
goodpkg="apacman"
badpkg="afuse"
fakepkg="xxxxxx"
corepkg="filesystem"
grouppkg="ladspa-plugins"
virtualpkg="ttf-font"
histpkg="jbxkb"
@test "test command is found" {
run $APACMAN
[ "$status" -ne 127 ]
}
@test "invoking without arguments prints usage" {
run $APACMAN
[ "$status" -eq 0 ]
[ "${lines[0]}" = "usage: apacman <operation> [option] [package] [package] [...]" ]
}
@test "invoke with nonexistent parameter returns 1" {
run $APACMAN $nofail --falseflag
[ "$status" -eq 2 ]
}
@test "invoking with '--help' parameter prints usage" {
run $APACMAN -h
[ "$status" -eq 0 ]
[ "${lines[0]}" = "usage: apacman <operation> [option] [package] [package] [...]" ]
}
@test "invoke with '--version' parameter prints ascii art" {
result="$($APACMAN -V | tr -dc '=' | wc -c)"
[ "$result" -eq 40 ]
}
@test "invoke with '--verbose' parameter without package argument" {
run $APACMAN -v
[ "$status" -eq 3 ]
[ "${lines[-1]}" = "error: must specify a package." ]
}
@test "test internet connectivity" {
run timeout 5 curl -LfGs --data-urlencode "arg=$goodpkg" "$RPCURL=info"
[ "$status" -eq 0 ]
}
@test "interactive search install package" {
run $APACMAN $testing $noconfirm $buildonly $skipcache $goodpkg <<< $(echo -e "0\n")
[ "$status" -eq 0 ]
}
@test "interactive search install nonexistant package" {
run $APACMAN $testing $noconfirm $buildonly $skipcache $fakepkg <<< $(echo -e "0\n")
[ "$status" -eq 4 ]
}
@test "invoke with '-S' parameter installs package from AUR" {
run $APACMAN $testing $noconfirm $buildonly $skipcache -S $goodpkg
[ "$status" -eq 0 ]
}
@test "invoke with '-S' parameter fails to build broken package from AUR" {
run $APACMAN $testing $noconfirm $buildonly $skipcache -S $badpkg
[ "$status" -eq 8 ]
}
@test "invoke with '-S' parameter installs cached AUR package" {
run $APACMAN $testing $noconfirm $buildonly -S $goodpkg
[ "$status" -eq 0 ]
}
@test "invoke with '-S' parameter installs non-AUR package" {
run $APACMAN $testing $noconfirm -S $corepkg
[ "$status" -eq 0 ]
}
@test "invoke with '-S' parameter fails to install nonexistant package" {
run $APACMAN $testing $noconfirm $buildonly $skipcache -S $fakepkg
[ "$status" -eq 5 ]
}
@test "invoke with '-G' parameter download AUR package source" {
run proot -w ${fakedir} -b ${fakedir}:$HOME $(readlink -e $APACMAN) $testing -G ${histpkg}
status=$?
[ "$status" -eq 0 ]
pattern="$histpkg/PKGBUILD"
[ ${lines[-1]} = "$pattern" ]
}
@test "invoke with '-G' parameter download old AUR package source" {
run proot -w ${fakedir} -b ${fakedir}:$HOME $(readlink -e $APACMAN) $testing -G ${histpkg}==0.7-1
status=$?
[ "$status" -eq 0 ]
pattern="0.7-1"
match=$(grep -o -e pkgver.* -e pkgrel.* ${fakedir}/${histpkg}/.SRCINFO | awk '{printf $NF"-"}' | sed 's/-$//' | grep -o "$pattern")
[ "$match" = "$pattern" ]
}
@test "invoke with '-G' parameter choose download old AUR package source" {
run proot -w ${fakedir} -b ${fakedir}:$HOME $(readlink -e $APACMAN) $testing -G ${histpkg}~ <<< $(echo -e "2\n") 2>&1
status=$?
[ "$status" -eq 0 ]
pattern=":: There are 2 releases for $histpkg:"
[ ${lines[2]} = "$pattern" ]
}
@test "prepare proot environment" {
rm -rf "$fakedir"
run mkdir -p ${fakedir}/var/lib/pacman
[ "$status" -eq 0 ]
run fakeroot proot -b ${fakedir}/var:/var pacman -Sy
[ "$status" -eq 0 ]
}
@test "invoke with '-S' parameter install package group" {
skip
result=$(proot -b "${fakedir}/var:/var" $APACMAN $testing -S $grouppkg --noconfirm --buildonly <<< $(echo -e "\n") 2>&1)
status=$?
[ "$status" -eq 0 ]
pattern="There are 13 members in group $grouppkg"
match=$(echo "$result" | grep -o "$pattern")
[ "$match" = "$pattern" ]
}
@test "invoke with '-S' parameter install virtual package" {
result=$(proot -b "${fakedir}/var:/var" $APACMAN $testing -S $virtualpkg --noconfirm --buildonly <<< $(echo -e "\n") 2>&1)
status=$?
[ "$status" -eq 0 ]
pattern="There are 9 packages that provide $virtualpkg"
match=$(echo "$result" | grep -o "$pattern")
[ "$match" = "$pattern" ]
}
@test "clean proot environment" {
run rm -rf "$fakedir"
[ "$status" -eq 0 ]
}
###########
@test "invoke with '-L' parameter lists installed packages by size" {
result="$($APACMAN -L | grep '\B[0-9][BKMG][ \t]*[a-z]' | awk NR==1)"
[ ! -z "$result" ]
}