aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/test/lux/tool/compiler/meta/cache/purge.lux
blob: 47582d841c1370f1486ab916ef937b018010a5df (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
(.using
 [library
  [lux (.except)
   ["_" test (.only Test)]
   [abstract
    [monad (.only do)]]
   [control
    ["[0]" try]
    ["[0]" exception]
    [concurrency
     ["[0]" async]]]
   [data
    ["[0]" text (.only)
     ["%" \\format]]
    ["[0]" binary
     ["$[1]" \\test]]
    [collection
     ["[0]" dictionary]
     ["[0]" sequence]
     ["[0]" set]]]
   [math
    ["[0]" random (.only Random)]
    [number
     ["n" nat]]]
   [world
    ["[0]" file]]]]
 [\\library
  ["[0]" / (.only)
   ["/[1]" //
    ["[1][0]" module]
    ["[0]" dependency
     ["[1]" module]]
    ["/[1]" //
     ["[0]" context (.only)
      ["$[1]" \\test]]
     ["[0]" archive (.only)
      ["[0]" registry]
      ["[0]" module (.only)
       ["$[1]" \\test]
       ["[0]" descriptor (.only)
        ["$[1]" \\test]]]]
     ["/[1]" //]]]]])

(def: .public test
  Test
  (<| (_.covering /._)
      (do [! random.monad]
        [descriptor ($descriptor.random 0)
         source_code (random.upper_case 1)
         name/0 (random.lower_case 1)
         module/0 ($module.random random.nat)
         content/0 ($binary.random 1)
         name/1 (random.lower_case 2)
         module/1 (|> ($module.random random.nat)
                      (at ! each (has [module.#descriptor descriptor.#references]
                                      (set.of_list text.hash (list name/0)))))
         content/1 ($binary.random 2)
         .let [id/0 (the module.#id module/0)
               id/1 (the module.#id module/1)
               input [////.#module (the descriptor.#name descriptor)
                      ////.#file (the descriptor.#file descriptor)
                      ////.#hash (the descriptor.#hash descriptor)
                      ////.#code source_code]
               / "/"
               fs (file.mock /)]
         context $context.random]
        (all _.and
             (_.for [/.Cache]
                    (all _.and
                         (_.coverage [/.valid?]
                           (and (/.valid? descriptor input)
                                (not (/.valid? descriptor (has ////.#module source_code input)))
                                (not (/.valid? descriptor (has ////.#file source_code input)))
                                (not (/.valid? descriptor (revised ////.#hash ++ input)))))
                         ))
             (_.for [/.Purge]
                    (all _.and
                         (_.coverage [/.purge]
                           (and (dictionary.empty? (/.purge (list) (list)))
                                (let [order (is (dependency.Order Nat)
                                                (list [name/0 id/0
                                                       [archive.#module module/0
                                                        archive.#output (sequence.sequence)
                                                        archive.#registry registry.empty]]))]
                                  (and (let [cache (is (List /.Cache)
                                                       (list [#1 name/0 id/0 module/0 registry.empty]))]
                                         (dictionary.empty? (/.purge cache order)))
                                       (let [cache (is (List /.Cache)
                                                       (list [#0 name/0 id/0 module/0 registry.empty]))]
                                         (dictionary.key? (/.purge cache order) name/0))))
                                (let [order (is (dependency.Order Nat)
                                                (list [name/0 id/0
                                                       [archive.#module module/0
                                                        archive.#output (sequence.sequence)
                                                        archive.#registry registry.empty]]
                                                      [name/1 id/1
                                                       [archive.#module module/1
                                                        archive.#output (sequence.sequence)
                                                        archive.#registry registry.empty]]))]
                                  (and (let [cache (is (List /.Cache)
                                                       (list [#1 name/0 id/0 module/0 registry.empty]
                                                             [#1 name/1 id/1 module/1 registry.empty]))
                                             purge (/.purge cache order)]
                                         (dictionary.empty? purge))
                                       (let [cache (is (List /.Cache)
                                                       (list [#1 name/0 id/0 module/0 registry.empty]
                                                             [#0 name/1 id/1 module/1 registry.empty]))
                                             purge (/.purge cache order)]
                                         (and (not (dictionary.key? (/.purge cache order) name/0))
                                              (dictionary.key? (/.purge cache order) name/1)))
                                       (let [cache (is (List /.Cache)
                                                       (list [#0 name/0 id/0 module/0 registry.empty]
                                                             [#1 name/1 id/1 module/1 registry.empty]))
                                             purge (/.purge cache order)]
                                         (and (dictionary.key? (/.purge cache order) name/0)
                                              (dictionary.key? (/.purge cache order) name/1)))))))
                         (in (do [! async.monad]
                               [_ (//module.enable! ! fs context id/0)
                                .let [dir (//module.path fs context id/0)
                                      file/0 (%.format dir / name/0)
                                      file/1 (%.format dir / name/1)]
                                _ (at fs write file/0 content/0)
                                _ (at fs write file/1 content/1)
                                pre (at fs directory_files dir)
                                _ (/.purge! fs context id/0)
                                post (at fs directory_files dir)]
                               (_.coverage' [/.purge!]
                                 (<| (try.else false)
                                     (do try.monad
                                       [pre pre]
                                       (in (and (at set.equivalence =
                                                    (set.of_list text.hash pre)
                                                    (set.of_list text.hash (list file/0 file/1)))
                                                (case post
                                                  {try.#Failure error}
                                                  (exception.match? file.cannot_find_directory error)

                                                  success
                                                  false))))))))
                         ))
             ))))