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

(def: #export test
  Test
  (<| (_.covering /._)
      (do {! random.monad}
        [#let [fs (file.mock (:: file.default separator))
               shell (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]))))))
                      [])]
         program (random.ascii/alpha 5)
         target (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)
               
               no-working-directory environment.empty
               
               environment (dictionary.put "user.dir" working-directory environment.empty)]]
        ($_ _.and
            (_.cover [/.working-directory]
                     (and (case (/.working-directory no-working-directory)
                            (#try.Success _)
                            false

                            (#try.Failure error)
                            true)
                          (case (/.working-directory environment)
                            (#try.Success _)
                            true

                            (#try.Failure error)
                            false)))
            (wrap (do promise.monad
                    [outcome (/.do! environment 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! environment 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! environment 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 !
              [lux-version (random.ascii/alpha 5)
               [_ compiler-package] $///package.random
               #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}]
               compiler-dependency (random.either (wrap jvm-compiler)
                                                  (wrap js-compiler))]
              (wrap (do promise.monad
                      [verdict (do ///action.monad
                                 [#let [resolution (|> ///dependency/resolution.empty
                                                       (dictionary.put compiler-dependency compiler-package))]
                                  _ (/.do! environment fs shell resolution profile)]
                                 (wrap true))]
                      (_.cover' [/.do!
                                 /.lux-group /.jvm-compiler-name /.js-compiler-name]
                                (try.default false verdict)))))
            ))))