aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/test/aedifex/command/install.lux
blob: b50de837ff5795a826a2b81cf369ee5fa4713a5e (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
... 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
    ["[0]" monad (.only do)]]
   [control
    ["[0]" try (.only Try) (.use "[1]#[0]" functor)]
    ["[0]" exception]
    [concurrency
     ["[0]" async (.only Async)]]]
   [data
    ["[0]" binary]
    ["[0]" text (.use "[1]#[0]" equivalence)
     ["%" \\format (.only format)]]
    [collection
     ["[0]" set (.only Set)]]]
   [math
    ["[0]" random]]
   [world
    ["[0]" file]
    ["[0]" environment
     ["program" / (.only Environment)]
     ["[1]" \\parser]]]
   [test
    ["[0]" unit]
    ["_" property (.only Test)]]]]
 [//
  ["$[0]" version]
  [//
   ["$[0]" profile]
   ["$[0]" artifact]]]
 [\\program
  ["[0]" / (.only)
   ["//[1]" ///
    ["[1]" profile]
    ["[1][0]" action (.only Action)]
    ["[1][0]" local]
    ["[1][0]" artifact (.only)
     ["[1]/[0]" extension]]
    ["[1][0]" repository
     ["[1]/[0]" local]]]]])

(def .public (make_sources! fs sources)
  (-> (file.System Async) (Set file.Path) (Action (List Any)))
  (let [/ (of fs separator)
        ! ///action.monad]
    (|> sources
        set.list
        (monad.each ! (function (_ head)
                        (do !
                          [_ (is (Async (Try Any))
                                 (file.make_directories async.monad fs head))]
                          (is (Async (Try Any))
                              (file.make_file async.monad fs (binary.empty 0) (format head / head ".lux")))))))))

(def (execute! program fs sample)
  (-> (Environment Async) (file.System Async) ///.Profile (Async (Try Text)))
  (do ///action.monad
    [.let [console ($version.echo "")]
     _ (..make_sources! fs (the ///.#sources sample))
     _ (/.do! console fs (///repository/local.repository program fs) sample)]
    (of console read_line [])))

(def .public test
  Test
  (<| (_.covering /._)
      (do [! random.monad]
        [identity $artifact.random
         sample (of ! each (has ///.#identity {.#Some identity})
                    $profile.random)
         home (random.alphabetic 5)
         working_directory (random.alphabetic 5)
         .let [/ (of file.default separator)]]
        (all _.and
             (in (do [! async.monad]
                   [.let [fs (file.mock /)
                          program (program.async (program.mock environment.empty home working_directory))

                          artifact_path (///local.uri (the ///artifact.#version identity) identity)
                          library_path (format artifact_path ///artifact/extension.lux_library)
                          pom_path (format artifact_path ///artifact/extension.pom)]
                    verdict (do [! ///action.monad]
                              [succeeded! (of ! each (text#= /.success)
                                              (..execute! program fs sample))
                               library_exists! (|> library_path
                                                   (format home /)
                                                   (of fs file?)
                                                   (of async.monad each (|>> {try.#Success})))
                               pom_exists! (|> pom_path
                                               (format home /)
                                               (of fs file?)
                                               (of async.monad each (|>> {try.#Success})))]
                              (in (and succeeded!
                                       library_exists!
                                       pom_exists!)))]
                   (unit.coverage [/.do! /.success]
                     (try.else false verdict))))
             (in (do [! async.monad]
                   [.let [fs (file.mock /)
                          program (program.async (program.mock environment.empty home working_directory))]
                    logging (..execute! program fs (has ///.#identity {.#None} sample))]
                   (unit.coverage [/.failure]
                     (|> logging
                         (try#each (text#= /.failure))
                         (try.else false)))))
             ))))