blob: effc808716d0fabed985eda0bc773e0ae8bf99d4 (
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
|
(.module:
[lux #*
["_" test (#+ Test)]
[abstract
[monad (#+ do)]]
[control
[pipe (#+ case>)]
["." try]
[parser
["." environment]]
[concurrency
["." atom (#+ Atom)]
["." promise (#+ Promise)]]]
[data
["." binary]
["." text
["%" format (#+ format)]
[encoding
["." utf8]]]
[collection
["." set]]]
[math
["." random]
[number
["n" nat]]]
[time
["." instant]]
[world
[console (#+ Console)]
["." shell (#+ Shell)]
["." program (#+ Program)]
["." file
["." watch]]]]
["." // #_
["$." version]
["$." build]]
{#program
["." /
["//#" /// #_
[command (#+ Command)]
["#" profile (#+ Profile)]
["#." action]
[dependency
[resolution (#+ Resolution)]]]]})
(def: (command expected_runs end_signal fs dummy_file)
(-> Nat Text (file.System Promise) file.Path
[(Atom Nat)
(-> (Console Promise) (Program Promise) (file.System Promise) (Shell Promise) Resolution (Command Any))])
(let [@runs (: (Atom Nat)
(atom.atom 0))]
[@runs
(function (_ console program fs shell resolution profile)
(do {! promise.monad}
[[_ actual_runs] (promise.future (atom.update inc @runs))]
(if (n.= expected_runs actual_runs)
(wrap (#try.Failure end_signal))
(do (try.with !)
[_ (\ fs write (\ utf8.codec encode (%.nat actual_runs)) dummy_file)]
(\ fs modify
(|> actual_runs .int instant.from_millis)
dummy_file)))))]))
(def: #export test
Test
(<| (_.covering /._)
(do {! random.monad}
[end_signal (random.ascii/alpha 5)
#let [/ (\ file.default separator)
[fs watcher] (watch.mock /)]
program (random.ascii/alpha 5)
target (random.ascii/alpha 5)
source (random.ascii/alpha 5)
#let [empty_profile (: Profile
(\ ///.monoid identity))
with_target (: (-> Profile Profile)
(set@ #///.target target))
with_program (: (-> Profile Profile)
(set@ #///.program (#.Some program)))
profile (|> empty_profile
with_program
with_target
(set@ #///.sources (set.from_list text.hash (list source))))]
home (random.ascii/alpha 5)
working_directory (random.ascii/alpha 5)
expected_runs (\ ! map (|>> (n.% 10) (n.max 2)) random.nat)
dummy_path (\ ! map (|>> (format source /)) (random.ascii/alpha 5))
resolution $build.resolution]
($_ _.and
(wrap (do promise.monad
[verdict (do ///action.monad
[_ (\ fs make_directory source)
_ (\ fs write (binary.create 0) dummy_path)
#let [[@runs command] (..command expected_runs end_signal fs dummy_path)]
_ (\ watcher poll [])]
(do {! promise.monad}
[no_dangling_process! (|> profile
((/.do! 1 watcher command)
($version.echo "")
(program.async (program.mock environment.empty home working_directory))
fs
(shell.async ($build.good_shell []))
resolution)
(\ ! map (|>> (case> (#try.Failure error)
(is? end_signal error)
(#try.Success _)
false))))
correct_number_of_runs! (|> @runs
atom.read
promise.future
(\ ! map (n.= expected_runs)))]
(wrap (#try.Success (and correct_number_of_runs!
no_dangling_process!)))))]
(_.cover' [/.do!]
(try.default false verdict))))
))))
|