aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/test/aedifex/command/test.lux
blob: 0a18b2ead16289858454f0d0c0c8d85a39a4787f (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
... 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 (.use "[1]#[0]" equivalence)]
    [collection
     ["[0]" dictionary]
     ["[0]" list]]]
   [math
    ["[0]" random]]
   [world
    ["[0]" file]
    ["[0]" shell]
    ["[0]" environment
     ["program" /]
     ["[1]" \\parser]]]
   [test
    ["[0]" unit]
    ["_" property (.only Test)]]]]
 ["[0]" //
  ["@[0]" version]
  ["@[0]" build]
  ["$/[1]" //
   ["[1][0]" package]]]
 [\\program
  ["[0]" / (.only)
   ["/[1]" //
    ["[1][0]" build]
    ["/[1]" //
     ["[1]" profile (.only Profile)]
     ["[1][0]" action]
     ["[1][0]" artifact
      ["[1]/[0]" type]]
     ["[1][0]" dependency (.only)
      ["[1]/[0]" resolution]]]]]])

(def .public test
  Test
  (<| (_.covering /._)
      (do [! random.monad]
        [test (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
                                 (of ///.monoid identity))
               with_target (is (-> Profile Profile)
                               (has ///.#target target))
               with_test (is (-> Profile Profile)
                             (has ///.#test {.#Some test}))
               
               profile (|> empty_profile
                           with_test
                           with_target)]
         [compiler resolution] @build.resolution]
        (all _.and
             (let [fs (file.mock (of file.default separator))
                   console (@version.echo "")]
               (in (do async.monad
                     [verdict (do ///action.monad
                                [_ (/.do! console (program.async (program.mock environment.empty home working_directory))
                                          fs (shell.async (@build.good_shell [])) resolution
                                          (has ///.#lux compiler profile))
                                 build_start (of console read_line [])
                                 build_end (of console read_line [])
                                 test_start (of console read_line [])
                                 test_end (of console read_line [])]
                                (in (and (and (text#= //build.start build_start)
                                              (text#= //build.success build_end))
                                         (and (text#= /.start test_start)
                                              (text#= /.success test_end)))))]
                     (unit.coverage [/.do!
                                     /.start /.success]
                       (try.else false verdict)))))
             (let [fs (file.mock (of file.default separator))
                   console (@version.echo "")]
               (in (do async.monad
                     [verdict (do ///action.monad
                                [.let [bad_shell (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 (if (list.any? (text#= "build") actual_arguments)
                                                                                   shell.normal
                                                                                   shell.error)]})))})
                                                  [])]
                                 _ (/.do! console (program.async (program.mock environment.empty home working_directory))
                                          fs (shell.async bad_shell) resolution
                                          (has ///.#lux compiler profile))
                                 build_start (of console read_line [])
                                 build_end (of console read_line [])
                                 test_start (of console read_line [])
                                 test_end (of console read_line [])]
                                (in (and (and (text#= //build.start build_start)
                                              (text#= //build.success build_end))
                                         (and (text#= /.start test_start)
                                              (text#= /.failure test_end)))))]
                     (unit.coverage [/.failure]
                       (try.else false verdict)))))
             ))))