aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/test/lux/meta/compiler/meta/cache/purge.lux
blob: e18c56e0503514566a51c556573ce5a4c47fe5fd (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
... 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]
    ["[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]]
   [test
    ["[0]" unit]
    ["_" property (.only Test)]]]]
 [\\library
  ["[0]" / (.only)
   ["/[1]" //
    ["[1][0]" module]
    ["[0]" dependency
     ["[1]" module]]
    ["/[1]" //
     ["[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_cased 1)
         name/0 (random.lower_cased 1)
         module/0 ($module.random random.nat)
         content/0 ($binary.random 1)
         name/1 (random.lower_cased 2)
         module/1 (|> ($module.random random.nat)
                      (of ! 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 /)]]
        (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 [true name/0 id/0 module/0 registry.empty]))]
                                         (dictionary.empty? (/.purge cache order)))
                                       (let [cache (is (List /.Cache)
                                                       (list [false 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 [true name/0 id/0 module/0 registry.empty]
                                                             [true name/1 id/1 module/1 registry.empty]))
                                             purge (/.purge cache order)]
                                         (dictionary.empty? purge))
                                       (let [cache (is (List /.Cache)
                                                       (list [true name/0 id/0 module/0 registry.empty]
                                                             [false 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 [false name/0 id/0 module/0 registry.empty]
                                                             [true 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 id/0)
                                .let [dir (//module.path fs id/0)
                                      file/0 (%.format dir / name/0)
                                      file/1 (%.format dir / name/1)]
                                _ (of fs write file/0 content/0)
                                _ (of fs write file/1 content/1)
                                pre (of fs directory_files dir)
                                _ (/.purge! fs id/0)
                                post (of fs directory_files dir)]
                               (unit.coverage [/.purge!]
                                 (<| (try.else false)
                                     (do try.monad
                                       [pre pre]
                                       (in (and (of set.equivalence =
                                                    (set.of_list text.hash pre)
                                                    (set.of_list text.hash (list file/0 file/1)))
                                                (when post
                                                  {try.#Failure error}
                                                  (exception.match? file.cannot_find_directory error)

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