aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/test/aedifex/cache.lux
blob: 33dab1686f5510d2cd48954d337cac9062dfc9a3 (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
(.module:
  [library
   [lux {"-" Type type}
    ["_" test {"+" Test}]
    [abstract
     ["[0]" monad {"+" do}]]
    [control
     ["[0]" try]
     [concurrency
      ["[0]" async {"+" Async}]]
     [parser
      ["[0]" environment]]]
    [data
     [binary {"+" Binary}]
     ["[0]" text]
     [format
      [xml {"+" XML}]]
     [collection
      ["[0]" set]
      ["[0]" dictionary]]]
    [math
     ["[0]" random {"+" Random} ("[1]#[0]" monad)]
     [number
      ["n" nat]]]
    [world
     ["[0]" file]
     ["[0]" program]]]]
  [//
   ["@[0]" profile]
   ["@[0]" artifact]
   [//
    [lux
     [data
      ["_[0]" binary]]]]]
  [\\program
   ["[0]" /
    ["/[1]" // "_"
     ["[1]" profile {"+" Profile}]
     ["[1][0]" package {"+" Package}]
     ["[1][0]" pom]
     ["[1][0]" dependency {"+" Dependency}
      ["[1]/[0]" resolution {"+" Resolution}]]
     ["[1][0]" artifact {"+" Artifact}
      ["[1]/[0]" type {"+" Type}]]
     ["[1][0]" repository "_"
      ["[1]/[0]" origin]]]]])

(def: type
  (Random Type)
  ($_ random.either
      (random#in //artifact/type.lux_library)
      (random#in //artifact/type.jvm_library)))

(def: profile
  (Random [Artifact Profile XML])
  (random.one (function (_ profile)
                (try.maybe
                 (do try.monad
                   [pom (//pom.write profile)
                    identity (try.of_maybe (value@ //.#identity profile))]
                   (in [identity profile pom]))))
              @profile.random))

(def: content
  (Random Binary)
  (do [! random.monad]
    [content_size (# ! each (n.% 100) random.nat)]
    (_binary.random content_size)))

(def: package
  (Random [Dependency Package])
  (do [! random.monad]
    [[identity profile pom] ..profile
     type ..type
     content ..content]
    (in [[//dependency.#artifact identity
          //dependency.#type type]
         (with@ //package.#origin {//repository/origin.#Remote ""} (//package.local pom content))])))

(def: resolution
  (Random Resolution)
  (do [! random.monad]
    [[main_dependency main_package] ..package
     dependencies (|> (//package.dependencies main_package)
                      (# try.monad each set.list)
                      (try.else (list))
                      (monad.each ! (function (_ dependency)
                                      (do !
                                        [pom (random.one (function (_ [identity profile pom])
                                                           (|> profile
                                                               (with@ //.#dependencies (set.empty //dependency.hash))
                                                               (with@ //.#identity {.#Some (value@ //dependency.#artifact dependency)})
                                                               //pom.write
                                                               try.maybe))
                                                         ..profile)
                                         content ..content]
                                        (in [dependency
                                             (with@ //package.#origin {//repository/origin.#Remote ""} (//package.local pom content))])))))]
    (in (dictionary.of_list //dependency.hash (list& [main_dependency main_package] dependencies)))))

(def: singular
  Test
  (do [! random.monad]
    [[dependency expected_package] ..package
     home (random.ascii/alpha 5)
     working_directory (random.ascii/alpha 5)
     .let [fs (: (file.System Async)
                 (file.mock (# file.default separator)))
           program (program.async (program.mock environment.empty home working_directory))]]
    (in (do async.monad
          [wrote! (/.write_one program fs dependency expected_package)
           read! (/.read_one program fs dependency)]
          (_.cover' [/.write_one /.read_one]
                    (<| (try.else false)
                        (do try.monad
                          [_ wrote!
                           actual_package read!]
                          (in (# //package.equivalence =
                                 (with@ //package.#origin {//repository/origin.#Local ""} expected_package)
                                 actual_package)))))))))

(def: plural
  Test
  (do [! random.monad]
    [expected ..resolution
     home (random.ascii/alpha 5)
     working_directory (random.ascii/alpha 5)
     .let [fs (: (file.System Async)
                 (file.mock (# file.default separator)))
           program (program.async (program.mock environment.empty home working_directory))]]
    (in (do async.monad
          [wrote! (/.write_all program fs expected)
           read! (/.read_all program fs (dictionary.keys expected) //dependency/resolution.empty)]
          (_.cover' [/.write_all /.read_all]
                    (<| (try.else false)
                        (do try.monad
                          [_ wrote!
                           actual read!]
                          (in (# //dependency/resolution.equivalence =
                                 (# dictionary.functor each
                                    (with@ //package.#origin {//repository/origin.#Local ""})
                                    expected)
                                 actual)))))))))

(def: .public test
  Test
  (<| (_.covering /._)
      ($_ _.and
          ..singular
          ..plural
          )))