aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/test/aedifex/cli.lux
blob: d0aef0468e4d5c2856a1b34d2e1af50226bd7b69 (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
(.require
 [library
  [lux (.except)
   ["_" test (.only Test)]
   [abstract
    [monad (.only do)]
    [\\specification
     ["$[0]" equivalence]]]
   [control
    ["[0]" pipe]
    ["[0]" try]
    [parser
     ["[0]" cli]]]
   [data
    ["[0]" text]
    [collection
     ["[0]" list]]]
   [math
    ["[0]" random (.only Random) (.use "[1]#[0]" monad)]]]]
 [\\program
  ["[0]" / (.only)
   ["/[1]" //
    ["[1]" profile]]]])

(def compilation
  (Random /.Compilation)
  (random.or (random#in [])
             (random#in [])))

(def command
  (Random /.Command)
  (all random.or
       ... #Version
       (random#in [])
       ... #Clean
       (random#in [])
       ... #POM
       (random#in [])
       ... #Dependencies
       (random#in [])
       ... #Install
       (random#in [])
       ... #Deploy
       (all random.and
            (random.alphabetic 1)
            (random.alphabetic 1)
            (random.alphabetic 1))
       ... #Compilation
       ..compilation
       ... #Auto
       ..compilation))

(def (compilation_format value)
  (-> /.Compilation (List Text))
  (case value
    {/.#Build} (list "build")
    {/.#Test} (list "test")))

(def (format value)
  (-> /.Command (List Text))
  (case value
    {/.#Version} (list "version")
    {/.#Clean} (list "clean")
    {/.#POM} (list "pom")
    {/.#Dependencies} (list "deps")
    {/.#Install} (list "install")
    {/.#Deploy repository [user password]} (list "deploy" repository user password)
    {/.#Compilation compilation} (..compilation_format compilation)
    {/.#Auto compilation} (list.partial "auto" (..compilation_format compilation))))

(def without_profile
  Test
  (do random.monad
    [expected ..command]
    (_.property "Without profile."
      (|> expected
          ..format
          (cli.result /.command)
          (pipe.case
            {try.#Success [names actual]}
            (and (at (list.equivalence text.equivalence) = (list //.default) names)
                 (at /.equivalence = expected actual))
            
            {try.#Failure error}
            false)))))

(def with_profile
  Test
  (do random.monad
    [expected_profile (random.alphabetic 1)
     expected_command ..command]
    (_.property "With profile."
      (|> expected_command
          ..format
          (list.partial "with" expected_profile)
          (cli.result /.command)
          (pipe.case
            {try.#Success [actual_profile actual_command]}
            (and (at (list.equivalence text.equivalence) = (list expected_profile //.default) actual_profile)
                 (at /.equivalence = expected_command actual_command))
            
            {try.#Failure error}
            false)))))

(def .public test
  Test
  (<| (_.covering /._)
      (_.for [/.Compilation /.Command]
             (all _.and
                  (_.for [/.equivalence]
                         ($equivalence.spec /.equivalence ..command))

                  (_.for [/.command]
                         (all _.and
                              ..without_profile
                              ..with_profile
                              ))))))