aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/test/aedifex/package.lux
blob: 55bca8ce369ae3c92ce9507c361455db423965e6 (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
(.module:
  [library
   [lux #*
    ["_" test (#+ Test)]
    [abstract
     [monad (#+ do)]
     [\\specification
      ["$." equivalence]]]
    [control
     ["." try]
     [concurrency
      [promise (#+ Promise)]]]
    [data
     ["." product]
     ["." text
      [encoding
       ["." utf8]]]
     [format
      ["." xml (#+ XML)]]
     [collection
      ["." set (#+ Set)]]]
    [math
     ["." random (#+ Random)]
     [number
      ["n" nat]]]
    [world
     ["." file]]]]
  [//
   ["$." profile]
   [//
    [lux
     [data
      ["$." binary]]]]]
  [\\program
   ["." /
    ["/#" // #_
     ["#" profile]
     ["#." hash ("#\." equivalence)]
     ["#." pom]
     [dependency
      ["#." status]]
     [repository
      ["#." origin]]]]])

(def: #export random
  (Random [//.Profile /.Package])
  (do {! random.monad}
    [content_size (\ ! map (n.% 100) random.nat)
     content ($binary.random content_size)
     [profile pom] (random.one (function (_ profile)
                                 (try.to_maybe
                                  (do try.monad
                                    [pom (//pom.write profile)]
                                    (wrap [profile pom]))))
                               $profile.random)]
    (wrap [profile (/.local pom content)])))

(def: #export test
  Test
  (<| (_.covering /._)
      (_.for [/.Package])
      (do {! random.monad}
        [[profile package] ..random]
        ($_ _.and
            (_.for [/.equivalence]
                   ($equivalence.spec /.equivalence (\ ! map product.right ..random)))
            
            (_.cover [/.local?]
                     (/.local? (set@ #/.origin (#//origin.Local "~/yolo") package)))
            (_.cover [/.remote?]
                     (/.remote? (set@ #/.origin (#//origin.Remote "https://example.com") package)))
            (_.cover [/.local]
                     (let [expected_pom (|> package (get@ #/.pom) product.left)
                           expected_library (|> package (get@ #/.library) product.left)

                           local (/.local expected_pom expected_library)

                           [actual_pom binary_pom pom_status] (get@ #/.pom local)
                           [actual_library library_status] (get@ #/.library local)]
                       (and (case (get@ #/.origin local)
                              (#//origin.Local "") true
                              _ false)
                            (let [expected_sha1 (//hash.sha-1 expected_library)
                                  expected_md5 (//hash.md5 expected_library)]
                              (and (is? expected_library actual_library)
                                   (case library_status
                                     (#//status.Verified actual_sha1 expected_md5)
                                     (and (//hash\= expected_sha1 actual_sha1)
                                          (//hash\= expected_md5 expected_md5))
                                     
                                     _
                                     false)))
                            (let [expected_sha1 (//hash.sha-1 binary_pom)
                                  expected_md5 (//hash.md5 binary_pom)]
                              (and (is? expected_pom actual_pom)
                                   (|> (do try.monad
                                         [xml_pom (\ utf8.codec decode binary_pom)
                                          decoded_pom (\ xml.codec decode xml_pom)]
                                         (wrap (\ xml.equivalence = actual_pom decoded_pom)))
                                       (try.default false))
                                   (case pom_status
                                     (#//status.Verified actual_sha1 expected_md5)
                                     (and (//hash\= expected_sha1 actual_sha1)
                                          (//hash\= expected_md5 expected_md5))
                                     
                                     _
                                     false))))))
            (_.cover [/.dependencies]
                     (let [expected (get@ #//.dependencies profile)]
                       (case (/.dependencies package)
                         (#try.Success actual)
                         (\ set.equivalence = expected actual)
                         
                         (#try.Failure error)
                         false)))
            (_.cover [/.repositories]
                     (let [expected (get@ #//.repositories profile)]
                       (case (/.repositories package)
                         (#try.Success actual)
                         (\ set.equivalence = expected actual)
                         
                         (#try.Failure error)
                         false)))
            ))))