blob: 2fe39286dc1efcc4dca1dda1f23bfe58e499dc45 (
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
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
|
(.module:
[library
[lux "*"
["_" test {"+" [Test]}]
[abstract
[monad {"+" [do]}]
["[0]" predicate]
[\\specification
["$[0]" equivalence]]]
[control
["[0]" try]
["[0]" exception]
[concurrency
["[0]" async]]]
[data
[binary {"+" [Binary]}]
["[0]" product]
["[0]" text
["%" format {"+" [format]}]
[encoding
["[0]" utf8]]]
[format
["[0]" xml]]
[collection
["[0]" dictionary]
["[0]" set]
["[0]" list]]]
[math
["[0]" random {"+" [Random]}]]]]
["$[0]" /// "_"
["[1][0]" package]
["[1][0]" repository]
["[1][0]" artifact]
[command
["[1][0]" version]]]
[\\program
["[0]" /
["//[1]" /// "_"
["[1]" profile]
["[1][0]" package {"+" [Package]}]
["[1][0]" hash]
["[1][0]" dependency {"+" [Dependency]} ("[1]\[0]" equivalence)
["[1]/[0]" status]]
["[1][0]" pom]
["[1][0]" artifact {"+" [Artifact]}
["[1]/[0]" type]
["[1]/[0]" extension]]
["[1][0]" repository {"+" [Mock]}
["[1]/[0]" origin]]]]])
(def: random
(Random /.Resolution)
(do [! random.monad]
[artifact $///artifact.random
[_ package] $///package.random]
(in (dictionary.has [#///dependency.artifact artifact
#///dependency.type ///artifact/type.lux_library]
package
/.empty))))
(def: lux_sha-1
Text
(format ///artifact/extension.lux_library ///artifact/extension.sha-1))
(def: lux_md5
Text
(format ///artifact/extension.lux_library ///artifact/extension.md5))
(def: pom_sha-1
Text
(format ///artifact/extension.pom ///artifact/extension.sha-1))
(def: pom_md5
Text
(format ///artifact/extension.pom ///artifact/extension.md5))
(def: sha-1
(-> Binary Binary)
(|>> ///hash.sha-1
(\ ///hash.sha-1_codec encoded)
(\ utf8.codec encoded)))
(def: md5
(-> Binary Binary)
(|>> ///hash.md5
(\ ///hash.md5_codec encoded)
(\ utf8.codec encoded)))
(def: .public nope
(Mock Any)
(implementation
(def: the_description
"[0]")
(def: (on_download uri state)
(#try.Failure "NOPE"))
(def: (on_upload uri binary state)
(#try.Failure "NOPE"))))
(def: .public (single artifact package)
(-> Artifact Package (Mock Any))
(let [expected (///artifact.uri (value@ #///artifact.version artifact) artifact)]
(implementation
(def: the_description
"[1]")
(def: (on_download uri state)
(if (text.contains? expected uri)
(let [library (: Binary
(|> package
(value@ #///package.library)
product.left))
pom (: Binary
(|> package
(value@ #///package.pom)
product.left
(\ xml.codec encoded)
(\ utf8.codec encoded)))]
(cond (text.ends_with? ///artifact/extension.lux_library uri)
(#try.Success [state library])
(text.ends_with? ..lux_sha-1 uri)
(#try.Success [state (..sha-1 library)])
(text.ends_with? ..lux_md5 uri)
(#try.Success [state (..md5 library)])
(text.ends_with? ///artifact/extension.pom uri)
(#try.Success [state pom])
(text.ends_with? ..pom_sha-1 uri)
(#try.Success [state (..sha-1 pom)])
(text.ends_with? ..pom_md5 uri)
(#try.Success [state (..md5 pom)])
... else
(#try.Failure "NOPE")))
(#try.Failure "NOPE")))
(def: (on_upload uri binary state)
(#try.Failure "NOPE")))))
(def: (bad_sha-1 expected_artifact expected_package dummy_package)
(-> Artifact Package Package (Mock Any))
(implementation
(def: the_description
"[~SHA-1]")
(def: (on_download uri state)
(if (text.contains? (///artifact.uri (value@ #///artifact.version expected_artifact) expected_artifact) uri)
(cond (text.ends_with? ///artifact/extension.lux_library uri)
(#try.Success [state (|> expected_package
(value@ #///package.library)
product.left)])
(text.ends_with? ..lux_sha-1 uri)
(#try.Success [state (|> expected_package
(value@ #///package.library)
product.left
..sha-1)])
(text.ends_with? ..lux_md5 uri)
(#try.Success [state (|> expected_package
(value@ #///package.library)
product.left
..md5)])
(text.ends_with? ///artifact/extension.pom uri)
(#try.Success [state (|> expected_package
(value@ #///package.pom)
product.left
(\ xml.codec encoded)
(\ utf8.codec encoded))])
(text.ends_with? ..pom_sha-1 uri)
(#try.Success [state (|> dummy_package
(value@ #///package.pom)
product.left
(\ xml.codec encoded)
(\ utf8.codec encoded)
..sha-1)])
(text.ends_with? ..pom_md5 uri)
(#try.Success [state (|> expected_package
(value@ #///package.pom)
product.left
(\ xml.codec encoded)
(\ utf8.codec encoded)
..md5)])
... else
(#try.Failure "NOPE"))
(#try.Failure "NOPE")))
(def: (on_upload uri binary state)
(#try.Failure "NOPE"))))
(def: (bad_md5 expected_artifact expected_package dummy_package)
(-> Artifact Package Package (Mock Any))
(implementation
(def: the_description
"[~MD5]")
(def: (on_download uri state)
(if (text.contains? (///artifact.uri (value@ #///artifact.version expected_artifact) expected_artifact) uri)
(cond (text.ends_with? ///artifact/extension.lux_library uri)
(#try.Success [state (|> expected_package
(value@ #///package.library)
product.left)])
(text.ends_with? ..lux_sha-1 uri)
(#try.Success [state (|> expected_package
(value@ #///package.library)
product.left
..sha-1)])
(text.ends_with? ..lux_md5 uri)
(#try.Success [state (|> dummy_package
(value@ #///package.library)
product.left
..md5)])
(text.ends_with? ///artifact/extension.pom uri)
(#try.Success [state (|> expected_package
(value@ #///package.pom)
product.left
(\ xml.codec encoded)
(\ utf8.codec encoded))])
(text.ends_with? ..pom_sha-1 uri)
(#try.Success [state (|> expected_package
(value@ #///package.pom)
product.left
(\ xml.codec encoded)
(\ utf8.codec encoded)
..sha-1)])
(text.ends_with? ..pom_md5 uri)
(#try.Success [state (|> dummy_package
(value@ #///package.pom)
product.left
(\ xml.codec encoded)
(\ utf8.codec encoded)
..md5)])
... else
(#try.Failure "NOPE"))
(#try.Failure "NOPE")))
(def: (on_upload uri binary state)
(#try.Failure "NOPE"))))
(def: one
Test
(do [! random.monad]
[expected_artifact $///artifact.random
[_ expected_package] $///package.random
[_ dummy_package] (random.only (|>> product.right
(with@ #///package.pom (value@ #///package.pom expected_package))
(\ ///package.equivalence = expected_package)
not)
$///package.random)
.let [good (..single expected_artifact expected_package)
bad_sha-1 (..bad_sha-1 expected_artifact expected_package dummy_package)
bad_md5 (..bad_md5 expected_artifact expected_package dummy_package)]]
(`` ($_ _.and
(in (do async.monad
[actual_package (/.one (///repository.mock good [])
[#///dependency.artifact expected_artifact
#///dependency.type ///artifact/type.lux_library])]
(_.cover' [/.one]
(case actual_package
(#try.Success actual_package)
(\ ///package.equivalence =
(with@ #///package.origin (#///repository/origin.Remote "") expected_package)
actual_package)
(#try.Failure _)
false))))
(~~ (template [<exception> <bad>]
[(in (do async.monad
[actual_package (/.one (///repository.mock <bad> [])
[#///dependency.artifact expected_artifact
#///dependency.type ///artifact/type.lux_library])]
(_.cover' [<exception>]
(case actual_package
(#try.Failure error)
(exception.match? <exception> error)
(#try.Success _)
false))))]
[/.sha-1_does_not_match bad_sha-1]
[/.md5_does_not_match bad_md5]
))
))))
(def: any
Test
(do [! random.monad]
[expected_artifact $///artifact.random
[_ expected_package] $///package.random
[_ dummy_package] (random.only (|>> product.right
(with@ #///package.pom (value@ #///package.pom expected_package))
(\ ///package.equivalence = expected_package)
not)
$///package.random)
.let [good (..single expected_artifact expected_package)
bad_sha-1 (..bad_sha-1 expected_artifact expected_package dummy_package)
bad_md5 (..bad_md5 expected_artifact expected_package dummy_package)]]
($_ _.and
(in (do async.monad
[.let [console ($///version.echo "")]
actual_package (/.any console
(list (///repository.mock bad_sha-1 [])
(///repository.mock bad_md5 [])
(///repository.mock good []))
[#///dependency.artifact expected_artifact
#///dependency.type ///artifact/type.lux_library])]
(_.cover' [/.any]
(case actual_package
(#try.Success actual_package)
(\ ///package.equivalence =
(with@ #///package.origin (#///repository/origin.Remote "") expected_package)
actual_package)
(#try.Failure _)
false))))
(in (do async.monad
[.let [console ($///version.echo "")]
actual_package (/.any console
(list (///repository.mock bad_sha-1 [])
(///repository.mock bad_md5 []))
[#///dependency.artifact expected_artifact
#///dependency.type ///artifact/type.lux_library])]
(_.cover' [/.cannot_resolve]
(case actual_package
(#try.Failure error)
(exception.match? /.cannot_resolve error)
(#try.Success _)
false))))
)))
(def: artifacts
(Random [Artifact Artifact Artifact])
(do random.monad
[dependee_artifact $///artifact.random
depender_artifact (random.only (predicate.complement
(\ ///artifact.equivalence = dependee_artifact))
$///artifact.random)
ignored_artifact (random.only (predicate.complement
(predicate.and (\ ///artifact.equivalence = dependee_artifact)
(\ ///artifact.equivalence = depender_artifact)))
$///artifact.random)]
(in [dependee_artifact depender_artifact ignored_artifact])))
(def: (packages [dependee_artifact depender_artifact ignored_artifact])
(-> [Artifact Artifact Artifact]
(Random [[Dependency Dependency Dependency]
[Package Package Package]]))
(do random.monad
[[_ dependee_package] $///package.random
[_ depender_package] $///package.random
[_ ignored_package] $///package.random
.let [dependee [#///dependency.artifact dependee_artifact
#///dependency.type ///artifact/type.lux_library]
depender [#///dependency.artifact depender_artifact
#///dependency.type ///artifact/type.lux_library]
ignored [#///dependency.artifact ignored_artifact
#///dependency.type ///artifact/type.lux_library]
dependee_pom (|> (\ ///.monoid identity)
(with@ #///.identity (#.Some dependee_artifact))
///pom.write
try.trusted)
depender_pom (|> (\ ///.monoid identity)
(with@ #///.identity (#.Some depender_artifact))
(with@ #///.dependencies (set.of_list ///dependency.hash (list dependee)))
///pom.write
try.trusted)
ignored_pom (|> (\ ///.monoid identity)
(with@ #///.identity (#.Some ignored_artifact))
///pom.write
try.trusted)
dependee_package (with@ #///package.pom
[dependee_pom
(|> dependee_pom (\ xml.codec encoded) (\ utf8.codec encoded))
#///dependency/status.Unverified]
dependee_package)
depender_package (with@ #///package.pom
[depender_pom
(|> depender_pom (\ xml.codec encoded) (\ utf8.codec encoded))
#///dependency/status.Unverified]
depender_package)
ignored_package (with@ #///package.pom
[ignored_pom
(|> ignored_pom (\ xml.codec encoded) (\ utf8.codec encoded))
#///dependency/status.Unverified]
ignored_package)]]
(in [[dependee depender ignored]
[dependee_package depender_package ignored_package]])))
(def: all
Test
(do [! random.monad]
[[dependee_artifact depender_artifact ignored_artifact] ..artifacts
[[dependee depender ignored]
[dependee_package depender_package ignored_package]]
(..packages [dependee_artifact depender_artifact ignored_artifact])]
($_ _.and
(in (do async.monad
[.let [console ($///version.echo "")]
[successes failures resolution] (/.all console
(list (///repository.mock (..single dependee_artifact dependee_package) [])
(///repository.mock (..single depender_artifact depender_package) [])
(///repository.mock (..single ignored_artifact ignored_package) []))
(function (_ url)
(///repository.mock ..nope []))
(list depender)
/.empty)]
(_.cover' [/.all]
(and (dictionary.key? resolution depender)
(list.any? (///dependency\= depender) successes)
(dictionary.key? resolution dependee)
(list.any? (///dependency\= dependee) successes)
(list.empty? failures)
(not (dictionary.key? resolution ignored))))))
)))
(def: .public test
Test
(<| (_.covering /._)
(_.for [/.Resolution])
($_ _.and
(_.for [/.equivalence]
($equivalence.spec /.equivalence ..random))
(_.cover [/.empty]
(dictionary.empty? /.empty))
..one
..any
..all
)))
|