aboutsummaryrefslogtreecommitdiff
path: root/tests/pkg-unpack.testscript
blob: 8df34995f27d9f62d03b9b353554c523ad43184a (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
294
295
296
297
298
299
300
# file      : tests/pkg-unpack.testscript
# license   : MIT; see accompanying LICENSE file

.include common.testscript \
         auth.testscript   \
         config.testscript \
         remote.testscript \
         remote-git.testscript

# Source repository:
#
# pkg-unpack
# |-- hello
# |   |-- libhello-1.0.0.tar.gz
# |   `-- repositories.manifest
# |-- libfoo-1.1.0
# |   |-- build
# |   |   `-- bootstrap.build
# |   |-- buildfile
# |   `-- manifest
# |-- t1
# |   |-- libfoo-1.0.0.tar.gz
# |   |-- libfoo-1.1.0.tar.gz
# |   `-- repositories.manifest
# |
# `-- git
#     `-- style-basic.git

# Prepare repositories used by tests if running in the local mode.
#
+if ($remote != true)
  rep_create += 2>!

  # Create the signed 'hello' repository.
  #
  cp -r $src/hello $out/hello
  cat <<<$cert_manifest >+$out/hello/repositories.manifest

  $rep_create --key $key $out/hello &$out/hello/packages.manifest \
                                    &$out/hello/signature.manifest

  # Create the 't1' repository.
  #
  cp -r $src/t1 $out/t1 && $rep_create $out/t1 &$out/t1/packages.manifest

  # Create git repositories.
  #
  $git_extract $src/git/style-basic.tar &$out_git/state0/***
end

pkg_fetch     += -d cfg 2>!
pkg_purge     += -d cfg
pkg_status    += -d cfg
rep_add       += -d cfg 2>!
rep_fetch     += -d cfg --auth all 2>!
pkg_configure += -d cfg
pkg_disfigure += -d cfg

: replace-with-existing
:
$clone_cfg;
$* foo -r 2>>EOE != 0
  error: --replace|-r can only be specified with external package
  EOE

: no-dir
:
$clone_cfg;
$* -e 2>>EOE != 0
  error: package directory argument expected
    info: run 'bpkg help pkg-unpack' for more information
  EOE

: not-package-dir
:
$clone_cfg;
$* -e ./ 2>>/EOE != 0
  error: no manifest file in package directory ./
  EOE

: dir-not-exist
:
$clone_cfg;
$* -e ./no-such-dir 2>>/EOE != 0
  error: package directory ./no-such-dir/ does not exist
  EOE

: no-name
:
$clone_cfg;
$* 2>>EOE != 0
  error: package name argument expected
    info: run 'bpkg help pkg-unpack' for more information
  EOE

: fetched-rep
:
{
  +$clone_cfg && $rep_add $rep/t1 && $rep_fetch --trust-yes

  : package-exists
  :
  {
    $clone_cfg && $pkg_fetch libfoo/1.0.0;

    $* -e $src/libfoo-1.1.0 2>>/EOE != 0;
      error: package libfoo already exists in configuration cfg/
        info: version: 1.0.0, state: fetched, substate: none
        info: use 'pkg-unpack --replace|-r' to replace
      EOE

    $pkg_purge  libfoo       2>'purged libfoo/1.0.0';
    $*  -e $src/libfoo-1.1.0 2>'using libfoo/1.1.0 (external)';
    $pkg_status libfoo/1.1.0 1>'libfoo unpacked 1.1.0';

    $pkg_configure libfoo  2>'configured libfoo/1.1.0';
    test    -d cfg/libfoo;
    $pkg_disfigure libfoo  2>'disfigured libfoo/1.1.0';

    $pkg_purge libfoo 2>'purged libfoo/1.1.0'
  }

  : replace-fetched
  :
  {
    $clone_cfg && $pkg_fetch libfoo/1.0.0;

    $* -e $src/libfoo-1.1.0 2>>/EOE != 0;
      error: package libfoo already exists in configuration cfg/
        info: version: 1.0.0, state: fetched, substate: none
        info: use 'pkg-unpack --replace|-r' to replace
      EOE

    $* --replace --existing $src/libfoo-1.1.0 2>'using libfoo/1.1.0 (external)';
    $pkg_status libfoo/1.1.0 1>'libfoo unpacked 1.1.0';

    $pkg_purge libfoo 2>'purged libfoo/1.1.0'
  }

  : replace-unpacked
  :
  {
    $clone_cfg && $pkg_fetch libfoo/1.0.0;

    $* libfoo 2>'unpacked libfoo/1.0.0';

    $* -e $src/libfoo-1.1.0 2>>/EOE != 0;
      error: package libfoo already exists in configuration cfg/
        info: version: 1.0.0, state: unpacked, substate: none
        info: use 'pkg-unpack --replace|-r' to replace
      EOE

    $* --replace --existing $src/libfoo-1.1.0 2>'using libfoo/1.1.0 (external)';
    $pkg_status libfoo/1.1.0 1>'libfoo unpacked 1.1.0';

    $pkg_purge libfoo 2>'purged libfoo/1.1.0'
  }

  : wrong-state
  :
  {
    $clone_cfg;

    $* libfoo 2>>/EOE != 0;
      error: package libfoo does not exist in configuration cfg/
      EOE

    $* -e $src/libfoo-1.1.0 2>'using libfoo/1.1.0 (external)';

    $* libfoo 2>>EOE != 0;
      error: package libfoo is unpacked
        info: expected it to be fetched
      EOE

    $pkg_purge libfoo 2>'purged libfoo/1.1.0'
  }

  : right-state
  :
  {
    $clone_cfg && $pkg_fetch libfoo/1.0.0;

    $pkg_status libfoo/1.0.0 1>'libfoo fetched 1.0.0';
    $*          libfoo       2>'unpacked libfoo/1.0.0';
    $pkg_status libfoo/1.0.0 1>'libfoo unpacked 1.0.0';

    $pkg_configure libfoo        2>'configured libfoo/1.0.0';
    test    -d cfg/libfoo-1.0.0;
    $pkg_disfigure libfoo        2>'disfigured libfoo/1.0.0';

    $pkg_purge libfoo 2>'purged libfoo/1.0.0'
  }

  : purge-existing
  :
  {
    $clone_cfg;
    cp --no-cleanup -r $src/libfoo-1.1.0 ./;

    $* --purge --existing libfoo-1.1.0 2>'using libfoo/1.1.0 (external)';

    $pkg_purge libfoo 2>'purged libfoo/1.1.0'
  }
}

: dir-rep
:
{
  rep_add += --type dir

  : no-repos
  :
  {
    $clone_root_cfg;

    $* libfoo/1.1.0 2>>/EOE != 0
      error: configuration cfg/ has no repositories
        info: use 'bpkg rep-add' to add a repository
      EOE
  }

  : unfetched
  :
  {
    $clone_root_cfg && $rep_add $src/libfoo-1.1.0;

    $* libfoo/1.1.0 2>>/EOE != 0
      error: configuration cfg/ has no available packages
        info: use 'bpkg rep-fetch' to fetch available packages list
      EOE
  }

  : unavailable
  :
  {
    $clone_root_cfg && $rep_add $src/libfoo-1.1.0 && $rep_fetch;

    $* libfoo/1.0.0 2>>EOE != 0
      error: package libfoo 1.0.0 is not available
      EOE
  }

  : unavailable-dir-based
  :
  {
    $clone_root_cfg && $rep_add $rep/t1 --type pkg && $rep_fetch --trust-yes;

    $* libfoo/1.0.0 2>>EOE != 0
      error: package libfoo 1.0.0 is not available from a directory-based repository
      EOE
  }

  : available
  :
  {
    $clone_root_cfg && $rep_add $src/libfoo-1.1.0 && $rep_fetch;

    $* libfoo/1.1.0 2>>EOE;
      using libfoo/1.1.0 (external)
      EOE

    $pkg_status libfoo 1>'libfoo unpacked 1.1.0';

    $pkg_configure libfoo  2>'configured libfoo/1.1.0';
    test    -d cfg/libfoo;
    $pkg_disfigure libfoo  2>'disfigured libfoo/1.1.0'
  }
}

: existing
:
{
  : version-fixup
  :
  : Test that the version is populated with the snapshot information for the
  : package directory that is under the version control.
  :
  if ($remote != true)
  {
    $clone_root_cfg;

    rep = $canonicalize([dir_path] $out_git/state0);

    $* -e $rep/style-basic.git 2>>~%EOE%
      %using style-basic/1\.1\.0-a\.0\.\d+\..+ \(external\)%
      EOE
  }
}

: hello
:
{
  $clone_cfg;
  $rep_add $rep/hello && $rep_fetch --trust $cert_fp &cfg/.bpkg/certs/**;
  $pkg_fetch libhello/1.0.0;

  $* libhello 2>'unpacked libhello/1.0.0';

  $pkg_purge libhello 2>'purged libhello/1.0.0'
}