aboutsummaryrefslogtreecommitdiff
path: root/tests/cfg-unlink.testscript
blob: 2ca37832fc047b1209d11fbd5f76e0238633c162 (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
# file      : tests/cfg-link.testscript
# license   : MIT; see accompanying LICENSE file

.include common.testscript remote.testscript

# Source repository (see pkg-build for details):
#
# cfg-unlink
# `-- t7a

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

  cp -r $src/t7a $out/t7a && $rep_create $out/t7a &$out/t7a/packages.manifest
end

cfg_create +=             2>!
cfg_info   += --link
pkg_build  += --yes       2>!
pkg_drop   += --yes       2>!
rep_add    +=             2>!
rep_fetch  += --trust-yes 2>!

cfg1_uuid = '18f48b4b-b5d9-4712-b98c-1930df1c4228'
cfg2_uuid  ='28f48b4b-b5d9-4712-b98c-1930df1c4228'

+$cfg_create -d cfg1 --name 'main'   --uuid "$cfg1_uuid"             &cfg1/***
+$cfg_create -d cfg2 --name 'shared' --uuid "$cfg2_uuid" --type host &cfg2/***

+$cfg_link -d cfg1 cfg2 2>!

clone_root_cfgs = cp -r $~/cfg1 $~/cfg2 ./

: unlink
:
{
  : name-dir
  :
  {
    $clone_root_cfgs;

    $* -d cfg1 cfg2 --name 'host' 2>/'error: both --name and directory argument specified' != 0
  }

  : dir
  :
  {
    $clone_root_cfgs;

    $* -d cfg1 cfg1 2>/"error: no configuration with path $~/cfg1/ is linked with cfg1/" != 0;

    $* -d cfg1 cfg2 2>/"unlinked configuration $~/cfg2/";

    $cfg_info -d cfg1 >>/"EOO";
      path: $~/cfg1/
      uuid: $cfg1_uuid
      type: target
      name: main
      EOO

    $cfg_info -d cfg2 >>/"EOO"
      path: $~/cfg2/
      uuid: $cfg2_uuid
      type: host
      name: shared
      EOO
  }

  : name
  :
  {
    $clone_root_cfgs;

    $* -d cfg1 --name 'target' 2>/"error: no configuration with name 'target' is linked with cfg1/" != 0;

    $* -d cfg1 --name 'shared' 2>/"unlinked configuration $~/cfg2/";

    $cfg_info -d cfg1 >>/"EOO";
      path: $~/cfg1/
      uuid: $cfg1_uuid
      type: target
      name: main
      EOO

    $cfg_info -d cfg2 >>/"EOO"
      path: $~/cfg2/
      uuid: $cfg2_uuid
      type: host
      name: shared
      EOO
  }

  : id
  :
  {
    $clone_root_cfgs;

    $* -d cfg1 --id 2 2>/"error: no configuration with id 2 is linked with cfg1/" != 0;

    $* -d cfg1 --id 1 2>/"unlinked configuration $~/cfg2/";

    $cfg_info -d cfg1 >>/"EOO";
      path: $~/cfg1/
      uuid: $cfg1_uuid
      type: target
      name: main
      EOO

    $cfg_info -d cfg2 >>/"EOO"
      path: $~/cfg2/
      uuid: $cfg2_uuid
      type: host
      name: shared
      EOO
  }

  : uuid
  :
  {
    $clone_root_cfgs;

    $* -d cfg1 --uuid $cfg1_uuid 2>/"error: no configuration with uuid $cfg1_uuid is linked with cfg1/" != 0;

    $* -d cfg1 --uuid $cfg2_uuid 2>/"unlinked configuration $~/cfg2/";

    $cfg_info -d cfg1 >>/"EOO";
      path: $~/cfg1/
      uuid: $cfg1_uuid
      type: target
      name: main
      EOO

    $cfg_info -d cfg2 >>/"EOO"
      path: $~/cfg2/
      uuid: $cfg2_uuid
      type: host
      name: shared
      EOO
  }

  : mutual
  :
  {
    $clone_root_cfgs;

    $cfg_link -d cfg2 cfg1 2>!;

    $* -d cfg1 cfg2 2>>/"EOE";
      info: configurations cfg2/ and cfg1/ are mutually linked, turning the link to cfg2/ into implicit backlink
      unlinked configuration $~/cfg2/
      EOE

    $cfg_info -d cfg1 >>/"EOO";
      path: $~/cfg1/
      uuid: $cfg1_uuid
      type: target
      name: main
      EOO

    $cfg_info -d cfg2 >>/"EOO"
      path: $~/cfg2/
      uuid: $cfg2_uuid
      type: host
      name: shared

      path: $~/cfg1/
      uuid: $cfg1_uuid
      type: target
      name: main
      EOO
  }

  : dependency
  :
  {
    $clone_root_cfgs;

    $rep_add -d cfg1 $rep/t7a && $rep_fetch -d cfg1;

    $pkg_build -d cfg1 libbar &cfg2/.bpkg/build2/***;

    $* -d cfg1 cfg2 2>>/EOE != 0;
      error: configuration cfg1/ still depends on configuration cfg2/
        info: package foo [cfg2/] has dependents:
        info: package libbar on foo ^1.0.0
      EOE

    $pkg_drop -d cfg1 --keep-unused libbar;

    $* -d cfg1 cfg2 2>>/"EOE";
      unlinked configuration $~/cfg2/
      EOE

    $cfg_info -d cfg1 >>/"EOO";
      path: $~/cfg1/
      uuid: $cfg1_uuid
      type: target
      name: main
      EOO

    $cfg_info -d cfg2 >>/~"%EOO%";
      path: $~/cfg2/
      uuid: $cfg2_uuid
      type: host
      name: shared

      path: $~/cfg2/.bpkg/build2/
      %uuid: .{36}%
      type: build2
      name: build2
      EOO

    $pkg_drop -d cfg1 libbaz;
    $pkg_drop -d cfg2 foo
  }

  : dependency-private
  :
  {
    $clone_root_cfgs;

    $rep_add -d cfg2 $rep/t7a && $rep_fetch -d cfg2;

    $pkg_build -d cfg2 foo;

    $* -d cfg2 --name build2 2>>/EOE != 0;
      error: configuration cfg2/ still depends on private configuration cfg2/.bpkg/build2/
        info: package libbuild2-bar [cfg2/.bpkg/build2/] has dependents:
        info: package foo on libbuild2-bar ^1.0.0
      EOE

    $pkg_drop -d cfg2 --keep-unused foo;

    test -d cfg2/.bpkg/build2/;

    $* -d cfg2 --name build2 2>>/"EOE";
      unlinked and removed configuration $~/cfg2/.bpkg/build2/
      EOE

    $cfg_info -d cfg2 >>/"EOO";
      path: $~/cfg2/
      uuid: $cfg2_uuid
      type: host
      name: shared
      EOO

    test -d cfg2/.bpkg/build2/ == 1;

    $pkg_drop -d cfg2 libbaz
  }
}
: remove-dangling
:
{
  : success
  :
  {
    $clone_root_cfgs;

    mv cfg1 cfg3;

    $* -d cfg2 --dangling 2>'removed 1 dangling implicit backlink(s)';
    $* -d cfg2 --dangling 2>'removed 0 dangling implicit backlink(s)'
  }

  : error
  :
  {
    $clone_root_cfgs;

    $* -d cfg1 --dangling --name 'host' 2>'error: both --dangling and --name specified' != 0
  }
}