blob: 7923eb8c595665c9b391b0900e98ab4163e17277 (
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
|
(.module:
[lux (#- Type type)
["_" test (#+ Test)]
[abstract
["." monad (#+ do)]]
[control
["." try]
[concurrency
["." promise (#+ Promise)]]]
[data
[binary (#+ Binary)]
["." text]
[number
["n" nat]]
[format
[xml (#+ XML)]]
[collection
["." set]
["." dictionary]]]
[math
["." random (#+ Random) ("#\." monad)]]
[world
["." file]]]
[//
["@." profile]
["@." artifact]
[//
[lux
[data
["_." binary]]]]]
{#program
["." /
["/#" // #_
["#" profile (#+ Profile)]
["#." package (#+ Package)]
["#." pom]
["#." dependency (#+ Dependency)
["#/." resolution (#+ Resolution)]]
["#." artifact (#+ Artifact)
["#/." type (#+ Type)]]]]})
(def: type
(Random Type)
($_ random.either
(random\wrap //artifact/type.lux-library)
(random\wrap //artifact/type.jvm-library)))
(def: profile
(Random [Artifact Profile XML])
(random.one (function (_ profile)
(try.to-maybe
(do try.monad
[pom (//pom.write profile)
identity (try.from-maybe (get@ #//.identity profile))]
(wrap [identity profile pom]))))
@profile.random))
(def: content
(Random Binary)
(do {! random.monad}
[content-size (\ ! map (n.% 100) random.nat)]
(_binary.random content-size)))
(def: package
(Random [Dependency Package])
(do {! random.monad}
[[identity profile pom] ..profile
type ..type
content ..content]
(wrap [{#//dependency.artifact identity
#//dependency.type type}
(set@ #//package.origin #//package.Remote (//package.local pom content))])))
(def: resolution
(Random Resolution)
(do {! random.monad}
[[main-dependency main-package] ..package
dependencies (|> (//package.dependencies main-package)
(\ try.monad map set.to-list)
(try.default (list))
(monad.map ! (function (_ dependency)
(do !
[pom (random.one (function (_ [identity profile pom])
(|> profile
(set@ #//.dependencies (set.new //dependency.hash))
(set@ #//.identity (#.Some (get@ #//dependency.artifact dependency)))
//pom.write
try.to-maybe))
..profile)
content ..content]
(wrap [dependency
(set@ #//package.origin #//package.Remote (//package.local pom content))])))))]
(wrap (dictionary.from-list //dependency.hash (list& [main-dependency main-package] dependencies)))))
(def: singular
Test
(do {! random.monad}
[[dependency expected-package] ..package
#let [fs (: (file.System Promise)
(file.mock (\ file.default separator)))]]
(wrap (do promise.monad
[wrote! (/.write-one fs dependency expected-package)
read! (/.read-one fs dependency)]
(_.cover' [/.write-one /.read-one]
(<| (try.default false)
(do try.monad
[_ wrote!
actual-package read!]
(wrap (\ //package.equivalence =
(set@ #//package.origin #//package.Local expected-package)
actual-package)))))))))
(def: plural
Test
(do {! random.monad}
[expected ..resolution
#let [fs (: (file.System Promise)
(file.mock (\ file.default separator)))]]
(wrap (do promise.monad
[wrote! (/.write-all fs expected)
read! (/.read-all fs (dictionary.keys expected) //dependency/resolution.empty)]
(_.cover' [/.write-all /.read-all]
(<| (try.default false)
(do try.monad
[_ wrote!
actual read!]
(wrap (\ //dependency/resolution.equivalence =
(\ dictionary.functor map
(set@ #//package.origin #//package.Local)
expected)
actual)))))))))
(def: #export test
Test
(<| (_.covering /._)
($_ _.and
..singular
..plural
)))
|