aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/test/lux/meta/compiler/meta/cache/archive.lux
blob: 61d35ef1dafcbb037f1bf3e36222930dad647248 (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
... This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
... If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.

(.require
 [library
  [lux (.except)
   [abstract
    [monad (.only do)]]
   [control
    ["[0]" try (.use "[1]#[0]" functor)]
    [concurrency
     ["[0]" async]]]
   [data
    ["[0]" binary (.use "[1]#[0]" equivalence)]
    [collection
     ["[0]" sequence]]]
   [math
    ["[0]" random]
    [number
     ["n" nat]]]
   [world
    ["[0]" file]]
   [test
    ["[0]" unit]
    ["_" property (.only Test)]]]]
 [\\library
  ["[0]" / (.only)
   ["/[1]" // (.only)
    ["/[1]" // (.only)
     ["[0]" archive (.only)
      ["[0]" signature]
      ["[0]" key]
      ["[0]" registry]
      ["[0]" module (.only)
       ["[0]" document]]]]]]]
 ["$" //
  [//
   ["[1][0]" archive (.only)
    ["[2][0]" signature]]
   [///
    ["[1][0]" configuration]]]])

(def .public test
  Test
  (<| (_.covering /._)
      (do [! random.monad]
        [.let [/ "/"
               fs (file.mock /)]
         module/0 (random.lower_cased 1)
         module/1 (random.lower_cased 2)
         content/0 random.nat
         content/1 (random.only (|>> (n.= content/0) not) random.nat)
         hash random.nat
         signature $signature.random
         configuration ($configuration.random 1)
         .let [key (key.key signature content/0)
               [archive expected] (|> (do try.monad
                                        [[@module/0 archive] (archive.reserve module/0 archive.empty)
                                         [@module/1 archive] (archive.reserve module/1 archive)
                                         .let [entry/0 [archive.#module [module.#id @module/0
                                                                         module.#descriptor ($archive.descriptor module/0 hash)
                                                                         module.#document (document.document key content/0)]
                                                        archive.#output sequence.empty
                                                        archive.#registry registry.empty]
                                               entry/1 [archive.#module [module.#id @module/1
                                                                         module.#descriptor ($archive.descriptor module/1 hash)
                                                                         module.#document (document.document key content/1)]
                                                        archive.#output sequence.empty
                                                        archive.#registry registry.empty]]
                                         archive (archive.has module/0 entry/0 archive)
                                         archive (archive.has module/1 entry/1 archive)]
                                        (in [archive (archive.export ///.version configuration archive)]))
                                      try.trusted)]]
        (all _.and
             (in (do [! async.monad]
                   [pre/0 (of fs file? (/.descriptor fs))
                    enabled? (//.enable! ! fs)
                    cached? (/.cache! fs configuration archive)
                    actual (of fs read (/.descriptor fs))
                    post/0 (of fs file? (/.descriptor fs))]
                   (unit.coverage [/.descriptor /.cache!]
                     (and (not pre/0)
                          (|> (do try.monad
                                [_ enabled?
                                 _ cached?]
                                actual)
                              (try#each (binary#= expected))
                              (try.else false))
                          post/0))))
             ))))