aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/test/lux/tool/compiler/meta/cache/artifact.lux
blob: 679bdfc47c726be505c99a56053578f08c8b7733 (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
(.using
 [library
  [lux (.except)
   ["_" test (.only Test)]
   [abstract
    [monad (.only do)]]
   [control
    ["[0]" try]
    [concurrency
     ["[0]" async (.only Async) (.open: "[1]#[0]" monad)]]]
   [data
    ["[0]" binary (.open: "[1]#[0]" equivalence)
     ["$[1]" \\test]]]
   [math
    ["[0]" random (.only Random)]
    [number
     ["n" nat]]]
   [world
    ["[0]" file]]]]
 [\\library
  ["[0]" / (.only)
   ["/[1]" //
    ["[1][0]" module]]]]
 ["$[0]" ///
  ["[1][0]" context]])

(def .public test
  Test
  (<| (_.covering /._)
      (do [! random.monad]
        [.let [/ "/"
               fs (file.mock /)]
         context $///context.random
         @module random.nat
         @artifact random.nat
         expected ($binary.random 1)]
        (all _.and
             (in (do [! async.monad]
                   [pre (at fs file? (/.path fs context @module @artifact))
                    _ (//module.enable! ! fs context @module)
                    write! (/.cache! fs context @module @artifact expected)
                    post (at fs file? (/.path fs context @module @artifact))
                    read! (/.cache fs context @module @artifact)]
                   (_.coverage' [/.path /.cache! /.cache]
                     (and (not pre)
                          (case write!
                            {try.#Success _} true
                            {try.#Failure _} false)
                          post
                          (case read!
                            {try.#Success actual} (binary#= expected actual)
                            {try.#Failure _} false)))))
             ))))