aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/test/aedifex/command/build.lux
blob: 85231ae338e3e2b486e1306207a6dff82e33f5c0 (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
(.module:
  [lux #*
   ["_" test (#+ Test)]
   [abstract
    [monad (#+ do)]]
   [control
    [io (#+ IO)]
    ["." try]
    ["." exception]
    [concurrency
     ["." promise (#+ Promise)]]
    [parser
     ["." environment]]
    [security
     ["!" capability]]]
   [data
    ["." text ("#\." equivalence)]
    [collection
     ["." dictionary]]]
   [math
    ["." random]]
   [world
    ["." file]
    ["." shell (#+ Shell)]
    ["." program]]]
  ["." // #_
   ["@." version]
   ["$/#" // #_
    ["#." package]]]
  {#program
   ["." /
    ["//#" /// #_
     ["#" profile (#+ Profile)]
     ["#." action]
     ["#." artifact
      ["#/." type]]
     ["#." dependency
      ["#/." resolution]]]]})

(def: #export good_shell
  (-> Any (Shell IO))
  (shell.mock
   (function (_ [actual_environment actual_working_directory actual_command actual_arguments])
     (#try.Success
      (: (shell.Simulation [])
         (structure
          (def: (on_read state)
            (#try.Failure "on_read"))
          (def: (on_error state)
            (#try.Failure "on_error"))
          (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: #export bad_shell
  (-> Any (Shell IO))
  (shell.mock
   (function (_ [actual_environment actual_working_directory actual_command actual_arguments])
     (#try.Success
      (: (shell.Simulation [])
         (structure
          (def: (on_read state)
            (#try.Failure "on_read"))
          (def: (on_error state)
            (#try.Failure "on_error"))
          (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
  (do random.monad
    [lux_version (random.ascii/alpha 5)
     #let [jvm_compiler {#///dependency.artifact {#///artifact.group /.lux_group
                                                  #///artifact.name /.jvm_compiler_name
                                                  #///artifact.version lux_version}
                         #///dependency.type ///artifact/type.lux_library}
           js_compiler {#///dependency.artifact {#///artifact.group /.lux_group
                                                 #///artifact.name /.js_compiler_name
                                                 #///artifact.version lux_version}
                        #///dependency.type ///artifact/type.lux_library}]]
    (random.either (wrap jvm_compiler)
                   (wrap js_compiler))))

(def: #export resolution
  (do random.monad
    [dependency ..compiler
     [_ package] $///package.random]
    (wrap (|> ///dependency/resolution.empty
              (dictionary.put dependency package)))))

(def: #export test
  Test
  (<| (_.covering /._)
      (do {! random.monad}
        [#let [fs (file.mock (\ file.default separator))
               shell (shell.async (..good_shell []))]
         program (random.ascii/alpha 5)
         target (random.ascii/alpha 5)
         home (random.ascii/alpha 5)
         working_directory (random.ascii/alpha 5)
         #let [empty_profile (: Profile
                                (\ ///.monoid identity))
               with_target (: (-> Profile Profile)
                              (set@ #///.target (#.Some target)))
               with_program (: (-> Profile Profile)
                               (set@ #///.program (#.Some program)))
               
               profile (|> empty_profile
                           with_program
                           with_target)]]
        ($_ _.and
            (wrap (do promise.monad
                    [outcome (/.do! (@version.echo "") (program.async (program.mock environment.empty home working_directory)) fs shell ///dependency/resolution.empty
                                    (with_target empty_profile))]
                    (_.cover' [/.no_specified_program]
                              (case outcome
                                (#try.Success _)
                                false

                                (#try.Failure error)
                                (exception.match? /.no_specified_program error)))))
            (wrap (do promise.monad
                    [outcome (/.do! (@version.echo "") (program.async (program.mock environment.empty home working_directory)) fs shell ///dependency/resolution.empty
                                    (with_program empty_profile))]
                    (_.cover' [/.no_specified_target]
                              (case outcome
                                (#try.Success _)
                                false

                                (#try.Failure error)
                                (exception.match? /.no_specified_target error)))))
            (wrap (do promise.monad
                    [outcome (/.do! (@version.echo "") (program.async (program.mock environment.empty home working_directory)) fs shell ///dependency/resolution.empty profile)]
                    (_.cover' [/.Compiler /.no_available_compiler]
                              (case outcome
                                (#try.Success _)
                                false

                                (#try.Failure error)
                                (exception.match? /.no_available_compiler error)))))
            (do !
              [#let [console (@version.echo "")]
               resolution ..resolution]
              (wrap (do promise.monad
                      [verdict (do ///action.monad
                                 [_ (/.do! console (program.async (program.mock environment.empty home working_directory)) fs shell resolution profile)
                                  start (!.use (\ console read_line) [])
                                  end (!.use (\ console read_line) [])]
                                 (wrap (and (text\= /.start start)
                                            (text\= /.success end))))]
                      (_.cover' [/.do!
                                 /.lux_group /.jvm_compiler_name /.js_compiler_name
                                 /.start /.success]
                                (try.default false verdict)))))
            (do !
              [#let [console (@version.echo "")]
               resolution ..resolution]
              (wrap (do promise.monad
                      [verdict (do ///action.monad
                                 [_ (/.do! console (program.async (program.mock environment.empty home working_directory)) fs (shell.async (..bad_shell [])) resolution profile)
                                  start (!.use (\ console read_line) [])
                                  end (!.use (\ console read_line) [])]
                                 (wrap (and (text\= /.start start)
                                            (text\= /.failure end))))]
                      (_.cover' [/.failure]
                                (try.default false verdict)))))
            ))))