Coveralls logob
Coveralls logo
  • Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

weldr / haskell-rpm / 14

1 Jun 2017 - 12:30 coverage: 76.509% (-21.3%) from 97.778%
14

Pull #9

travis-ci

9181eb84f9c35729a3bad740fb7f9d93?size=18&default=identiconweb-flow
Add several tests for Tags
Pull Request #9: Add couple of tests for Tags

697 of 911 relevant lines covered (76.51%)

1.5 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

98.47
/tests/RPM/VersionSpec.hs
1
{-# LANGUAGE OverloadedStrings #-}
2

3
module RPM.VersionSpec (spec) where
4

5
import           Test.Hspec
6
import           Data.Foldable(forM_)
7
import qualified Data.Text as T
8
import           RPM.Version(DepRequirement(..), EVR(..), parseDepRequirement, parseEVR, satisfies, vercmp)
9
import qualified RPM.Version as RPM(DepOrdering(..))
10

11
spec :: Spec
12
spec = do
2×
13
    describe "RPM.Version.vercmp" $ do
2×
14
        let vercmpCases = [
2×
15
                         ("1.0", "1.0", EQ),
2×
16
                         ("1.0", "2.0", LT),
2×
17
                         ("2.0", "1.0", GT),
2×
18

19
                         ("2.0.1", "2.0.1", EQ),
2×
20
                         ("2.0", "2.0.1", LT),
2×
21
                         ("2.0.1", "2.0", GT),
2×
22

23
                         ("2.0.1a", "2.0.1a", EQ),
2×
24
                         ("2.0.1a", "2.0.1", GT),
2×
25
                         ("2.0.1", "2.0.1a", LT),
2×
26

27
                         ("5.5p1", "5.5p1", EQ),
2×
28
                         ("5.5p1", "5.5p2", LT),
2×
29
                         ("5.5p2", "5.5p1", GT),
2×
30

31
                         ("5.5p10", "5.5p10", EQ),
2×
32
                         ("5.5p1", "5.5p10", LT),
2×
33
                         ("5.5p10", "5.5p1", GT),
2×
34

35
                         ("10xyz", "10.1xyz", LT),
2×
36
                         ("10.1xyz", "10xyz", GT),
2×
37

38
                         ("xyz10", "xyz10", EQ),
2×
39
                         ("xyz10", "xyz10.1", LT),
2×
40
                         ("xyz10.1", "xyz10", GT),
2×
41

42
                         ("xyz.4", "xyz.4", EQ),
2×
43
                         ("xyz.4", "8", LT),
2×
44
                         ("8", "xyz.4", GT),
2×
45
                         ("xyz.4", "2", LT),
2×
46
                         ("2", "xyz.4", GT),
2×
47

48
                         ("5.5p2", "5.6p1", LT),
2×
49
                         ("5.6p1", "5.5p2", GT),
2×
50

51
                         ("5.6p1", "6.5p1", LT),
2×
52
                         ("6.5p1", "5.6p1", GT),
2×
53

54
                         ("6.0.rc1", "6.0", GT),
2×
55
                         ("6.0", "6.0.rc1", LT),
2×
56

57
                         ("10b2", "10a1", GT),
2×
58
                         ("10a2", "10b2", LT),
2×
59
                         ("1.0aa", "1.0aa", EQ),
2×
60
                         ("1.0a", "1.0aa", LT),
2×
61
                         ("1.0aa", "1.0a", GT),
2×
62

63
                         ("10.0001", "10.0001", EQ),
2×
64
                         ("10.0001", "10.1", EQ),
2×
65
                         ("10.1", "10.0001", EQ),
2×
66
                         ("10.0001", "10.0039", LT),
2×
67
                         ("10.0039", "10.0001", GT),
2×
68

69
                         ("4.999.9", "5.0", LT),
2×
70
                         ("5.0", "4.999.9", GT),
2×
71

72
                         ("20101121", "20101121", EQ),
2×
73
                         ("20101121", "20101122", LT),
2×
74
                         ("20101122", "20101121", GT),
2×
75

76
                         ("2_0", "2_0", EQ),
2×
77
                         ("2.0", "2_0", EQ),
2×
78
                         ("2_0", "2.0", EQ),
2×
79

80
                         ("a", "a", EQ),
2×
81
                         ("a+", "a+", EQ),
2×
82
                         ("a+", "a_", EQ),
2×
83
                         ("a_", "a+", EQ),
2×
84
                         ("+a", "+a", EQ),
2×
85
                         ("+a", "_a", EQ),
2×
86
                         ("_a", "+a", EQ),
2×
87
                         ("+_", "+_", EQ),
2×
88
                         ("_+", "+_", EQ),
2×
89
                         ("_+", "_+", EQ),
2×
90
                         ("+", "_", EQ),
2×
91
                         ("_", "+", EQ),
2×
92

93
                         ("1.0~rc1", "1.0~rc1", EQ),
2×
94
                         ("1.0~rc1", "1.0", LT),
2×
95
                         ("1.0", "1.0~rc1", GT),
2×
96
                         ("1.0~rc1", "1.0~rc2", LT),
2×
97
                         ("1.0~rc2", "1.0~rc1", GT),
2×
98
                         ("1.0~rc1~git123", "1.0~rc1~git123", EQ),
2×
99
                         ("1.0~rc1~git123", "1.0~rc1", LT),
2×
100
                         ("1.0~rc1", "1.0~rc1~git123", GT)
2×
101
                       ]
102

103
        forM_ vercmpCases $ \(verA, verB, ord) ->
2×
104
          it (T.unpack verA ++ " " ++ show ord ++ " " ++ T.unpack verB) $
2×
105
            vercmp verA verB `shouldBe` ord
2×
106

107
    describe "RPM.Version.EVR Ord" $ do
2×
108
        let ordCases = [
2×
109
                     (EVR{epoch=Nothing, version="1.0", release="1"}, EVR{epoch=Nothing, version="1.0", release="1"}, EQ),
2×
110
                     (EVR{epoch=Just 0,  version="1.0", release="1"}, EVR{epoch=Nothing, version="1.0", release="1"}, EQ),
2×
111
                     (EVR{epoch=Just 1,  version="1.0", release="1"}, EVR{epoch=Nothing, version="1.0", release="1"}, GT),
2×
112
                     (EVR{epoch=Nothing, version="1.0", release="1"}, EVR{epoch=Nothing, version="1.1", release="1"}, LT),
2×
113
                     (EVR{epoch=Nothing, version="1.0", release="1"}, EVR{epoch=Nothing, version="1.0", release="2"}, LT),
2×
114

115
                     (EVR{epoch=Just 8,  version="3.6.9", release="11.fc100"}, EVR{epoch=Just 3,  version="3.6.9", release="11.fc100"}, GT),
2×
116
                     (EVR{epoch=Just 8,  version="3.6.9", release="11.fc100"}, EVR{epoch=Just 11, version="3.6.9", release="11.fc100"}, LT),
2×
117
                     (EVR{epoch=Just 8,  version="3.6.9", release="11.fc100"}, EVR{epoch=Just 8,  version="7.0",   release="11.fc100"}, LT),
2×
118
                     (EVR{epoch=Just 8,  version="3.6.9", release="11.fc100"}, EVR{epoch=Just 8,  version="",      release="11.fc100"}, GT),
2×
119
                     (EVR{epoch=Just 8,  version="",      release="11.fc100"}, EVR{epoch=Just 8,  version="",      release="11.fc100"}, EQ),
2×
120

121
                     (EVR{epoch=Nothing, version="1.1",  release="1"}, EVR{epoch=Nothing, version="1.01", release="1"}, EQ),
2×
122
                     (EVR{epoch=Nothing, version="1..1", release="1"}, EVR{epoch=Nothing, version="1.1",  release="1"}, EQ)
2×
123
                   ]
124

125
        forM_ ordCases $ \(verA, verB, ord) ->
2×
126
            it (show verA ++ " " ++ show ord ++ " " ++ show verB) $
2×
127
                compare verA verB `shouldBe` ord
2×
128

129
    describe "RPM.Version.satisfies" $ do
2×
130
        let satisfiesCases = [
2×
131
              ("no", "match", False),
2×
132

133
              ("thing",          "thing",          True),
2×
134
              ("thing",          "thing >= 1.0-1", True),
2×
135
              ("thing >= 1.0-1", "thing",          True),
2×
136

137
              ("thing = 1.0-1",  "thing = 1.0-1",  True),
2×
138
              ("thing = 1.0-1",  "thing >= 1.0-1", True),
2×
139
              ("thing = 1.0-1",  "thing > 1.0-1",  False),
2×
140
              ("thing = 1.0-1",  "thing < 1.0-1",  False),
2×
141
              ("thing = 1.0-1",  "thing <= 1.0-1", True),
2×
142

143
              ("thing = 1.0",    "thing = 1.0-9",   True),
2×
144
              ("thing = 1.0",    "thing < 1.0-9",   True),
2×
145
              ("thing = 1.0",    "thing <= 1.0-9",  True),
2×
146
              ("thing = 1.0",    "thing >= 1.0-9",  True),
2×
147
              ("thing = 1.0",    "thing > 1.0-9",   True),
2×
148

149
              ("thing = 1.0",    "thing = 1.0",     True),
2×
150
              ("thing = 1.0",    "thing < 1.0",     False),
2×
151
              ("thing = 1.0",    "thing > 1.0",     False),
2×
152
              ("thing = 1.0",    "thing >= 1.0",    True),
2×
153
              ("thing = 1.0",    "thing <= 1.0",    True),
2×
154

155
              ("thing < 1.0",    "thing = 1.0",     False),
2×
156
              ("thing < 1.0",    "thing < 1.0",     True),
2×
157
              ("thing < 1.0",    "thing > 1.0",     False),
2×
158
              ("thing < 1.0",    "thing >= 1.0",    False),
2×
159
              ("thing < 1.0",    "thing <= 1.0",    True),
2×
160

161
              ("thing > 1.0",    "thing = 1.0",     False),
2×
162
              ("thing > 1.0",    "thing < 1.0",     False),
2×
163
              ("thing > 1.0",    "thing > 1.0",     True),
2×
164
              ("thing > 1.0",    "thing >= 1.0",    True),
2×
165
              ("thing > 1.0",    "thing <= 1.0",    False),
2×
166

167
              ("thing >= 1.0",   "thing = 1.0",     True),
2×
168
              ("thing >= 1.0",   "thing < 1.0",     False),
2×
169
              ("thing >= 1.0",   "thing > 1.0",     True),
2×
170
              ("thing >= 1.0",   "thing >= 1.0",    True),
2×
171
              ("thing >= 1.0",   "thing <= 1.0",    True),
2×
172

173
              ("thing <= 1.0",   "thing = 1.0",     True),
2×
174
              ("thing <= 1.0",   "thing < 1.0",     True),
2×
175
              ("thing <= 1.0",   "thing > 1.0",     False),
2×
176
              ("thing <= 1.0",   "thing >= 1.0",    True),
2×
177
              ("thing <= 1.0",   "thing <= 1.0",    True),
2×
178

179
              ("thing <= 1.0",   "thing = 1.0-9",   True),
2×
180
              ("thing <= 1.0",   "thing < 1.0-9",   True),
2×
181
              ("thing <= 1.0",   "thing <= 1.0-9",  True),
2×
182
              ("thing <= 1.0",   "thing >= 1.0-9",  True),
2×
183
              ("thing <= 1.0",   "thing > 1.0-9",   True),
2×
184

185
              ("thing >= 1.0",   "thing = 1.0-9",   True),
2×
186
              ("thing >= 1.0",   "thing < 1.0-9",   True),
2×
187
              ("thing >= 1.0",   "thing <= 1.0-9",  True),
2×
188
              ("thing >= 1.0",   "thing >= 1.0-9",  True),
2×
189
              ("thing >= 1.0",   "thing > 1.0-9",   True),
2×
190

191
              ("thing = 1.0-9",  "thing = 1.0-9",   True),
2×
192
              ("thing < 1.0-9",  "thing = 1.0-9",   False),
2×
193
              ("thing <= 1.0-9", "thing = 1.0-9",   True),
2×
194
              ("thing > 1.0-9",  "thing = 1.0-9",   False),
2×
195
              ("thing >= 1.0-9", "thing = 1.0-9",   True),
2×
196

197
              ("thing >= 1.0-1", "thing = 1.0-1",  True),
2×
198
              ("thing >= 1.0-1", "thing >= 1.0-1", True),
2×
199
              ("thing >= 1.0-1", "thing > 1.0-1",  True),
2×
200
              ("thing >= 1.0-1", "thing < 1.0-1",  False),
2×
201
              ("thing >= 1.0-1", "thing <= 1.0-1", True),
2×
202

203
              ("thing > 1.0-1",  "thing = 1.0-1",  False),
2×
204
              ("thing > 1.0-1",  "thing >= 1.0-1", True),
2×
205
              ("thing > 1.0-1",  "thing > 1.0-1",  True),
2×
206
              ("thing > 1.0-1",  "thing < 1.0-1",  False),
2×
207
              ("thing > 1.0-1",  "thing <= 1.0-1", False),
2×
208

209
              ("thing < 1.0-1",  "thing = 1.0-1",  False),
2×
210
              ("thing < 1.0-1",  "thing >= 1.0-1", False),
2×
211
              ("thing < 1.0-1",  "thing > 1.0-1",  False),
2×
212
              ("thing < 1.0-1",  "thing < 1.0-1",  True),
2×
213
              ("thing < 1.0-1",  "thing <= 1.0-1", True),
2×
214

215
              ("thing <= 1.0-1", "thing = 1.0-1",  True),
2×
216
              ("thing <= 1.0-1", "thing >= 1.0-1", True),
2×
217
              ("thing <= 1.0-1", "thing > 1.0-1",  False),
2×
218
              ("thing <= 1.0-1", "thing < 1.0-1",  True),
2×
219
              ("thing <= 1.0-1", "thing <= 1.0-1", True),
2×
220

221
              ("thing = 9.0",    "thing = 1.0-1",  False),
2×
222
              ("thing = 9.0",    "thing >= 1.0-1", True),
2×
223
              ("thing = 9.0",    "thing > 1.0-1",  True),
2×
224
              ("thing = 9.0",    "thing <= 1.0-1", False),
2×
225
              ("thing = 9.0",    "thing < 1.0-1",  False),
2×
226

227
              ("thing < 9.0",    "thing = 1.0-1",  True),
2×
228
              ("thing < 9.0",    "thing >= 1.0-1", True),
2×
229
              ("thing < 9.0",    "thing > 1.0-1",  True),
2×
230
              ("thing < 9.0",    "thing <= 1.0-1", True),
2×
231
              ("thing < 9.0",    "thing < 1.0-1",  True),
2×
232

233
              ("thing <= 9.0",   "thing = 1.0-1",  True),
2×
234
              ("thing <= 9.0",   "thing >= 1.0-1", True),
2×
235
              ("thing <= 9.0",   "thing > 1.0-1",  True),
2×
236
              ("thing <= 9.0",   "thing <= 1.0-1", True),
2×
237
              ("thing <= 9.0",   "thing < 1.0-1",  True),
2×
238

239
              ("thing > 9.0",    "thing = 1.0-1",  False),
2×
240
              ("thing > 9.0",    "thing >= 1.0-1", True),
2×
241
              ("thing > 9.0",    "thing > 1.0-1",  True),
2×
242
              ("thing > 9.0",    "thing <= 1.0-1", False),
2×
243
              ("thing > 9.0",    "thing < 1.0-1",  False),
2×
244

245
              ("thing >= 9.0",   "thing = 1.0-1",  False),
2×
246
              ("thing >= 9.0",   "thing >= 1.0-1", True),
2×
247
              ("thing >= 9.0",   "thing > 1.0-1",  True),
2×
248
              ("thing >= 9.0",   "thing <= 1.0-1", False),
2×
249
              ("thing >= 9.0",   "thing < 1.0-1",  False),
2×
250

251
              ("thing = 1.0",    "thing = 9.0-1",  False),
2×
252
              ("thing = 1.0",    "thing >= 9.0-1", False),
2×
253
              ("thing = 1.0",    "thing > 9.0-1",  False),
2×
254
              ("thing = 1.0",    "thing <= 9.0-1", True),
2×
255
              ("thing = 1.0",    "thing < 9.0-1",  True),
2×
256

257
              ("thing < 1.0",    "thing = 9.0-1",  False),
2×
258
              ("thing < 1.0",    "thing >= 9.0-1", False),
2×
259
              ("thing < 1.0",    "thing > 9.0-1",  False),
2×
260
              ("thing < 1.0",    "thing <= 9.0-1", True),
2×
261
              ("thing < 1.0",    "thing < 9.0-1",  True),
2×
262

263
              ("thing <= 1.0",   "thing = 9.0-1",  False),
2×
264
              ("thing <= 1.0",   "thing >= 9.0-1", False),
2×
265
              ("thing <= 1.0",   "thing > 9.0-1",  False),
2×
266
              ("thing <= 1.0",   "thing <= 9.0-1", True),
2×
267
              ("thing <= 1.0",   "thing < 9.0-1",  True),
2×
268

269
              ("thing >= 1.0",   "thing = 9.0-1",  True),
2×
270
              ("thing >= 1.0",   "thing >= 9.0-1", True),
2×
271
              ("thing >= 1.0",   "thing > 9.0-1",  True),
2×
272
              ("thing >= 1.0",   "thing <= 9.0-1", True),
2×
273
              ("thing >= 1.0",   "thing < 9.0-1",  True),
2×
274

275
              ("thing > 1.0",    "thing = 9.0-1",  True),
2×
276
              ("thing > 1.0",    "thing >= 9.0-1", True),
2×
277
              ("thing > 1.0",    "thing > 9.0-1",  True),
2×
278
              ("thing > 1.0",    "thing <= 9.0-1", True),
2×
279
              ("thing > 1.0",    "thing < 9.0-1",  True)
2×
280
              ]
281

282
        forM_ satisfiesCases $ \(v1, v2, b) ->
2×
283
            it (T.unpack v1 ++ " " ++ T.unpack v2 ++ ": " ++ show b) $
2×
284
                case (parseDepRequirement v1, parseDepRequirement v2) of
2×
285
                    (Right verA, Right verB) -> satisfies verA verB `shouldBe` b
2×
UNCOV
286
                    _                        -> expectationFailure "Unable to parse versions"
!
287

288
    describe "RPM.Version.parseEVR" $ do
2×
289
        let parseEVRCases = [
2×
290
                ("1.0-11.fc100",    Right EVR{epoch=Nothing, version="1.0", release="11.fc100"}),
2×
291
                ("0:1.0-11.fc100",  Right EVR{epoch=Just 0,  version="1.0", release="11.fc100"}),
2×
292
                ("8:1.0-11.fc100",  Right EVR{epoch=Just 8,  version="1.0", release="11.fc100"}),
2×
293
                ("1.0",             Right EVR{epoch=Nothing, version="1.0", release=""}),
2×
294
                ("8:1.0",           Right EVR{epoch=Just 8,  version="1.0", release=""}),
2×
295

296
                -- missing epoch
297
                (":1.0-11.fc100",   Left ()),
1×
298

299
                -- missing version
300
                ("0:-11.fc100",     Left ()),
1×
301

302
                -- missing release
303
                ("0:1.0-",          Left ()),
1×
304

305
                -- invalid epochs
306
                ("-1:1.0-100.fc11", Left ()),
1×
307
                ("A:1.0-100.fc11",  Left ()),
1×
308
                ("8589934592:1.0-100.fc11", Left ()),
1×
309

310
                -- invalid versions
311
                ("0:1.0:0-100.fc11",  Left ()),
1×
312
                ("0:1.0&0-100.fc11",  Left ()),
1×
313
                ("0:1.0\x01f32e\&0-100.fc11", Left ()),
1×
314

315
                -- invalid releases
316
                ("0:1.0-100.fc:11",  Left ()),
1×
317
                ("0:1.0-100.fc&11",  Left ()),
1×
318
                ("0:1.0-100.fc\x01f32e\&11", Left ())
1×
319
                ]
320

321
        -- For the error cases, we don't actually care about the contents of the error, so just
322
        -- make sure parseEVR returns a Left. Also, the Either returned by parseEVR is not the
323
        -- same type as the ones in the test cases (ParseError vs. ()), so unwrap the Right EVR
324
        -- cases to compare.
325
        -- Making fake ParseErrors is hard, so the Either returned by parseEVR is not the same type
326
        -- as the either in the test data (ParseError vs. ()). Unwrap the Right values to compare EVRs,
327
        -- and for parse errors just check that parseEVR returns a Left.
328
        forM_ parseEVRCases $ \(str, result) ->
2×
329
            it (T.unpack str) $ case (result, parseEVR str) of
2×
330
                (Right evr1, Right evr2) -> evr1 `shouldBe` evr2
2×
UNCOV
331
                (Left _, Right evr)      -> expectationFailure $ "bad string parsed as: " ++ show evr
!
UNCOV
332
                (Right _, Left err)      -> expectationFailure $ "unable to parse valid EVR: " ++ show err
!
333
                _                        -> return ()
1×
334

335
    describe "RPM.Version.parseDepRequirement" $ do
2×
336
        let parseDepRequirementCases = [
2×
337
                ("libthing",        DepRequirement "libthing" Nothing),
2×
338
                ("libthing >= 1.0", DepRequirement "libthing" $ Just (RPM.GTE, EVR{epoch=Nothing, version="1.0", release=""})),
2×
339
                ("libthing > 1.0",  DepRequirement "libthing" $ Just (RPM.GT,  EVR{epoch=Nothing, version="1.0", release=""})),
2×
340
                ("libthing = 1.0",  DepRequirement "libthing" $ Just (RPM.EQ,  EVR{epoch=Nothing, version="1.0", release=""})),
2×
341
                ("libthing < 1.0",  DepRequirement "libthing" $ Just (RPM.LT,  EVR{epoch=Nothing, version="1.0", release=""})),
2×
342
                ("libthing <= 1.0", DepRequirement "libthing" $ Just (RPM.LTE, EVR{epoch=Nothing, version="1.0", release=""})),
2×
343

344
                -- sometimes an RPM will have an invalid version in a Requires/Provides line.
345
                -- make sure the whole thing gets parsed as a name
346
                ("httpd-mmn = 20120211-x86-64", DepRequirement "httpd-mmn = 20120211-x86-64" Nothing)
2×
347
                ]
348

349
        forM_ parseDepRequirementCases $ \(str, result) ->
2×
350
            it (T.unpack str) $ case parseDepRequirement str of
2×
351
                Right dr -> dr `shouldBe` result
2×
UNCOV
352
                Left err -> expectationFailure $ "failed to parse DepRequirement: " ++ show err
!
Troubleshooting · Open an Issue · Sales · Support · ENTERPRISE · CAREERS · STATUS
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2023 Coveralls, Inc