aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/test/aedifex/command/build.lux
blob: 674a04e93660d6dec280f1a56f9d2ec323267bc5 (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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
(.require
 [library
  [lux (.except)
   [abstract
    [monad (.only do)]]
   [control
    [io (.only IO)]
    ["[0]" pipe]
    ["[0]" try]
    ["[0]" exception]
    [concurrency
     ["[0]" async (.only Async)]]]
   [data
    ["[0]" text (.use "[1]#[0]" equivalence)]
    [collection
     ["[0]" dictionary]]]
   [math
    ["[0]" random (.only Random)]]
   [world
    ["[0]" file]
    ["[0]" shell (.only Shell)]
    ["[0]" environment
     ["program" /]
     ["[1]" \\parser]]]
   [test
    ["[0]" unit]
    ["_" property (.only Test)]]]]
 ["[0]" //
  ["@[0]" version]
  ["$/[1]" //
   ["[1][0]" package]]]
 [\\program
  ["[0]" / (.only)
   ["//[1]" ///
    ["[1]" profile (.only Profile)]
    ["[1][0]" action]
    ["[1][0]" artifact (.only)
     ["[1]/[0]" type]]
    ["[1][0]" dependency (.only Dependency)
     ["[1]/[0]" resolution (.only Resolution)]]]]])

(def .public good_shell
  (-> Any (Shell IO))
  (shell.mock
   (function (_ [actual_environment actual_working_directory actual_command actual_arguments])
     {try.#Success
      (is (shell.Mock [])
          (implementation
           (def (on_read state)
             (exception.except shell.no_more_output []))
           (def (on_fail state)
             (exception.except shell.no_more_output []))
           (def (on_write input state)
             {try.#Failure "on_write"})
           (def (on_destroy state)
             {try.#Failure "on_destroy"})
           (def (on_await state)
             {try.#Success [state shell.normal]})))})))

(def .public bad_shell
  (-> Any (Shell IO))
  (shell.mock
   (function (_ [actual_environment actual_working_directory actual_command actual_arguments])
     {try.#Success
      (is (shell.Mock [])
          (implementation
           (def (on_read state)
             (exception.except shell.no_more_output []))
           (def (on_fail state)
             (exception.except shell.no_more_output []))
           (def (on_write input state)
             {try.#Failure "on_write"})
           (def (on_destroy state)
             {try.#Failure "on_destroy"})
           (def (on_await state)
             {try.#Success [state shell.error]})))})))

(def .public (reader_shell error?)
  (-> Bit (-> (List Text) (Shell IO)))
  (shell.mock
   (function (_ [actual_environment actual_working_directory actual_command actual_arguments])
     {try.#Success
      (is (shell.Mock (List Text))
          (implementation
           (def (on_read state)
             (if error?
               (exception.except shell.no_more_output [])
               (when state
                 {.#Item head tail}
                 {try.#Success [tail head]}
                 
                 {.#End}
                 (exception.except shell.no_more_output []))))
           (def (on_fail state)
             (if error?
               (when state
                 {.#Item head tail}
                 {try.#Success [tail head]}
                 
                 {.#End}
                 (exception.except shell.no_more_output []))
               (exception.except shell.no_more_output [])))
           (def (on_write input state)
             {try.#Failure "on_write"})
           (def (on_destroy state)
             {try.#Failure "on_destroy"})
           (def (on_await state)
             {try.#Success [state shell.error]})))})))

(def compiler
  (Random Dependency)
  (do random.monad
    [lux_version (random.alphabetic 5)
     .let [js_compiler [///dependency.#artifact [///artifact.#group /.lux_group
                                                 ///artifact.#name /.js_lux_name
                                                 ///artifact.#version lux_version]
                        ///dependency.#type ///artifact/type.js_library]]]
    (`` (all random.either
             (in js_compiler)
             (,, (with_template [<compiler>]
                   [(in [///dependency.#artifact [///artifact.#group /.lux_group
                                                  ///artifact.#name <compiler>
                                                  ///artifact.#version lux_version]
                         ///dependency.#type ///artifact/type.lux_library])]

                   [/.jvm_lux_name]
                   [/.python_lux_name]
                   [/.lua_lux_name]
                   [/.ruby_lux_name]
                   ))))))

(def .public resolution
  (Random [Dependency Resolution])
  (do random.monad
    [dependency ..compiler
     [_ package] $///package.random]
    (in [dependency
         (|> ///dependency/resolution.empty
             (dictionary.has dependency package))])))

(def .public test
  Test
  (<| (_.covering /._)
      (do [! random.monad]
        [last_read (random.alphabetic 5)
         last_error (random.alphabetic 5)
         .let [fs (file.mock (at file.default separator))
               shell (shell.async (..good_shell []))]
         program (random.and (random.alphabetic 5)
                             (random.alphabetic 5))
         target (random.alphabetic 5)
         home (random.alphabetic 5)
         working_directory (random.alphabetic 5)
         .let [empty_profile (is Profile
                                 (at ///.monoid identity))
               with_target (is (-> Profile Profile)
                               (has ///.#target target))
               with_program (is (-> Profile Profile)
                                (has ///.#program {.#Some program}))
               
               profile (|> empty_profile
                           with_program
                           with_target)]]
        (all _.and
             (in (do async.monad
                   [outcome (/.do! (@version.echo "") (program.async (program.mock environment.empty home working_directory)) fs shell ///dependency/resolution.empty
                                   (with_target empty_profile))]
                   (unit.coverage [/.no_specified_program]
                     (when outcome
                       {try.#Success _}
                       false

                       {try.#Failure error}
                       (exception.match? /.no_specified_program error)))))
             (in (do async.monad
                   [outcome (/.do! (@version.echo "") (program.async (program.mock environment.empty home working_directory)) fs shell ///dependency/resolution.empty profile)]
                   (unit.coverage [/.Lux /.no_available_lux]
                     (when outcome
                       {try.#Success _}
                       false

                       {try.#Failure error}
                       (exception.match? /.no_available_lux error)))))
             (do !
               [.let [console (@version.echo "")]
                [compiler resolution] ..resolution]
               (in (do async.monad
                     [verdict (do ///action.monad
                                [_ (/.do! console (program.async (program.mock environment.empty home working_directory))
                                          fs shell resolution
                                          (has ///.#lux compiler profile))
                                 start (at console read_line [])
                                 end (at console read_line [])]
                                (in (and (text#= /.start start)
                                         (text#= /.success end))))]
                     (unit.coverage [/.do!
                                     /.lux_group
                                     /.jvm_lux_name
                                     /.js_lux_name
                                     /.python_lux_name
                                     /.lua_lux_name
                                     /.ruby_lux_name
                                     /.start
                                     /.success]
                       (try.else false verdict)))))
             (do !
               [.let [console (@version.echo "")]
                [compiler resolution] ..resolution]
               (in (do async.monad
                     [verdict (do ///action.monad
                                [_ (/.do! console (program.async (program.mock environment.empty home working_directory))
                                          fs (shell.async (..bad_shell [])) resolution
                                          (has ///.#lux compiler profile))
                                 start (at console read_line [])
                                 end (at console read_line [])]
                                (in (and (text#= /.start start)
                                         (text#= /.failure end))))]
                     (unit.coverage [/.failure]
                       (try.else false verdict)))))
             (do !
               [expected/0 (random.alphabetic 5)
                expected/1 (random.alphabetic 5)
                expected/2 (random.alphabetic 5)]
               (`` (all _.and
                        (,, (with_template [<error?> <log!>]
                              [(let [console (@version.echo "")
                                     shell (|> (list expected/0 expected/1 expected/2)
                                               (..reader_shell <error?>)
                                               shell.async)]
                                 (in (do [! async.monad]
                                       [verdict (do ///action.monad
                                                  [process (shell [environment.empty working_directory "" (list "")])
                                                   _ (<log!> console process)
                                                   actual/0 (at console read_line [])
                                                   actual/1 (at console read_line [])
                                                   actual/2 (at console read_line [])
                                                   end! (|> (at console read_line [])
                                                            (at ! each (|>> (pipe.when
                                                                              {try.#Failure error}
                                                                              true
                                                                              
                                                                              {try.#Success _}
                                                                              false)
                                                                            {try.#Success})))]
                                                  (in (and (text#= expected/0 actual/0)
                                                           (text#= expected/1 actual/1)
                                                           (text#= expected/2 actual/2)
                                                           end!)))]
                                       (unit.coverage [<log!>]
                                         (try.else false verdict)))))]

                              [#0 /.log_output!]
                              [#1 /.log_error!]
                              ))
                        )))
             ))))