aboutsummaryrefslogtreecommitdiff
path: root/bpkg/test.sh
blob: b7282b67b5955531bd41ea22db813bc1a6b32fb3 (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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
#! /usr/bin/env bash

trap 'exit 1' ERR

bpkg="./bpkg $*"
#bpkg="valgrind -q ./bpkg $*"
cfg=/tmp/conf
pkg=libhello
ver=1.0.0
pkga=../../hello/dist/$pkg-$ver.tar.bz2
pkgd=../../hello/dist/$pkg-$ver
out=$cfg/`basename $pkgd`

function error ()
{
  echo "$*" 1>&2
  exit 1
}

function test ()
{
  local cmd=$1
  shift

  $bpkg $cmd -d $cfg $*

  if [ $? -ne 0 ]; then
    error "failed: $bpkg $cmd -d $cfg $*"
  fi
}

function fail ()
{
  local cmd=$1
  shift

  $bpkg $cmd -d $cfg $*

  if [ $? -eq 0 ]; then
    error "succeeded: $bpkg $cmd -d $cfg $*"
  fi

  return 0
}

# Verify package status.
#
function stat ()
{
  local s=`$bpkg pkg-status -d $cfg $pkg $ver`

  if [ "$s" != "$1" ]; then
    error "status: $s, expected: $1"
  fi
}

# Verify path is gone (no longer exists)
#
function gone ()
{
  if [ -e "$1" ]; then
    error "path $1 still exists"
  fi
}

##
## cfg-create
##

test cfg-create --wipe config.cxx=g++-4.9 cxx config.install.root=/tmp/install
stat unknown

##
## pkg-fetch
##

# fetch existing archive
#
stat unknown
test pkg-fetch -e $pkga
stat fetched
test pkg-purge $pkg
stat unknown


##
## pkg-purge
##

fail pkg-purge
fail pkg-purge $pkg

# purge fetched
#
test pkg-fetch -e $pkga
test pkg-purge $pkg
stat unknown

# --keep
#
test pkg-fetch -e $pkga
test pkg-purge -k $pkg
stat fetched
test pkg-purge $pkg

# archive --purge
#
cp $pkga $cfg/
test pkg-fetch -e -p $cfg/`basename $pkga`
test pkg-purge $pkg
stat unknown
gone $cfg/`basename $pkga`

# no archive but --keep
#
test pkg-unpack -e $pkgd
fail pkg-purge --keep $pkg
stat unpacked
test pkg-purge $pkg

# purge unpacked directory
#
test pkg-unpack -e $pkgd
test pkg-purge $pkg
stat unknown

# purge unpacked archive
#
test pkg-fetch -e $pkga
test pkg-unpack $pkg
test pkg-purge $pkg
stat unknown
gone $out

# purge unpacked archive but --keep
#
test pkg-fetch -e $pkga
test pkg-unpack $pkg
test pkg-purge --keep $pkg
stat fetched
gone $out
test pkg-purge $pkg

# directory --purge
#
cp -r $pkgd $cfg/
test pkg-unpack -e -p $out
test pkg-purge $pkg
stat unknown
gone $out

# archive --purge
#
cp $pkga $cfg/
test pkg-fetch -e -p $cfg/`basename $pkga`
test pkg-unpack $pkg
test pkg-purge $pkg
stat unknown
gone $out
gone $cfg/`basename $pkga`

# broken
#
cp $pkga $cfg/
test pkg-fetch -e -p $cfg/`basename $pkga`
test pkg-unpack $pkg
chmod 000 $out
fail pkg-purge $pkg
stat broken
fail pkg-purge $pkg        # need --force
fail pkg-purge -f -k $pkg  # can't keep broken
fail pkg-purge -f $pkg     # directory still exists
chmod 755 $out
rm -r $out
fail pkg-purge -f $pkg     # archive still exists
rm $cfg/`basename $pkga`
test pkg-purge -f $pkg
stat unknown

##
## pkg-configure/pkg-disfigure
##

fail pkg-configure                        # package name expected
fail pkg-configure config.dist.root=/tmp  # ditto
fail pkg-configure $pkg $pkg              # unexpected argument
fail pkg-configure $pkg                   # no such package

fail pkg-disfigure                        # package name expected
fail pkg-disfigure $pkg                   # no such package

test pkg-fetch -e $pkga

fail pkg-configure $pkg                   # wrong package state
fail pkg-disfigure $pkg                   # wrong package state

test pkg-purge $pkg

# src == out
#
test pkg-fetch -e $pkga
test pkg-unpack $pkg
test pkg-configure $pkg
stat configured
test pkg-disfigure $pkg
stat unpacked
test pkg-purge $pkg
stat unknown

# src != out
#
test pkg-unpack -e $pkgd
test pkg-configure $pkg
stat configured
test pkg-disfigure $pkg
stat unpacked
test pkg-purge $pkg
stat unknown
gone $out

# out still exists after disfigure
#
test pkg-unpack -e $pkgd
test pkg-configure $pkg
touch $out/stray
fail pkg-disfigure $pkg
stat broken
rm -r $out
test pkg-purge -f $pkg
stat unknown

# disfigure failed
#
test pkg-unpack -e $pkgd
test pkg-configure $pkg
chmod 555 $out
fail pkg-disfigure $pkg
stat broken
chmod 755 $out
rm -r $out
test pkg-purge -f $pkg
stat unknown

# configure failed but disfigure succeeds
#
test pkg-unpack -e $pkgd
mkdir -p $out/build
chmod 555 $out/build
fail pkg-configure $pkg
stat unpacked
test pkg-purge $pkg
stat unknown

# configure and disfigure both failed
#
test pkg-unpack -e $pkgd
mkdir -p $out/build
chmod 555 $out $out/build # Both to trip configure and disfigure.
fail pkg-configure $pkg
stat broken
chmod 755 $out $out/build
rm -r $out
test pkg-purge -f $pkg
stat unknown

##
## pkg-update
##

fail pkg-update           # package name expected
fail pkg-update $pkg      # no such package
test pkg-fetch -e $pkga
fail pkg-update $pkg      # wrong package state
test pkg-purge $pkg

# src == out
#
test pkg-fetch -e $pkga
test pkg-unpack $pkg
test pkg-configure $pkg
test pkg-update $pkg
test pkg-update $pkg
test pkg-disfigure $pkg
test pkg-purge $pkg

# src != out
#
test pkg-unpack -e $pkgd
test pkg-configure $pkg
test pkg-update $pkg
test pkg-update $pkg
test pkg-disfigure $pkg
test pkg-purge $pkg