|
0 |
{- Copyright (C) 2011, Benjamin Drung <bdrung@debian.org>
|
|
1 |
|
|
2 |
Permission to use, copy, modify, and/or distribute this software for any
|
|
3 |
purpose with or without fee is hereby granted, provided that the above
|
|
4 |
copyright notice and this permission notice appear in all copies.
|
|
5 |
|
|
6 |
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
7 |
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
8 |
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
9 |
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
10 |
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
11 |
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
12 |
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
13 |
-}
|
|
14 |
|
|
15 |
module TestDistroInfo (main) where
|
|
16 |
|
|
17 |
import Data.List
|
|
18 |
import Data.Time
|
|
19 |
import System.Exit
|
|
20 |
|
|
21 |
import Test.HUnit
|
|
22 |
import Text.CSV
|
|
23 |
|
|
24 |
import DistroInfo
|
|
25 |
|
|
26 |
date1 :: Day
|
|
27 |
date1 = fromGregorian 2011 01 10
|
|
28 |
|
|
29 |
------------------
|
|
30 |
-- Debian tests --
|
|
31 |
------------------
|
|
32 |
|
|
33 |
testDebianAll :: [DebianEntry] -> Test
|
|
34 |
testDebianAll d = TestCase (assertEqual "Debian all" [] (expected \\ result))
|
|
35 |
where
|
|
36 |
expected = ["buzz", "rex", "bo", "hamm", "slink", "potato", "woody",
|
|
37 |
"sarge", "etch", "lenny", "squeeze", "sid", "experimental"]
|
|
38 |
result = map debSeries $ debianAll date1 d
|
|
39 |
|
|
40 |
testDebianDevel :: [DebianEntry] -> Test
|
|
41 |
testDebianDevel d = TestCase (assertEqual "Debian devel" expected result)
|
|
42 |
where
|
|
43 |
expected = ["sid"]
|
|
44 |
result = map debSeries $ debianDevel date1 d
|
|
45 |
|
|
46 |
testDebianOldstable :: [DebianEntry] -> Test
|
|
47 |
testDebianOldstable d = TestCase (assertEqual "Debian oldstable" expected result)
|
|
48 |
where
|
|
49 |
expected = ["etch"]
|
|
50 |
result = map debSeries $ debianOldstable date1 d
|
|
51 |
|
|
52 |
testDebianStable :: [DebianEntry] -> Test
|
|
53 |
testDebianStable d = TestCase (assertEqual "Debian stable" expected result)
|
|
54 |
where
|
|
55 |
expected = ["lenny"]
|
|
56 |
result = map debSeries $ debianStable date1 d
|
|
57 |
|
|
58 |
testDebianSupported :: [DebianEntry] -> Test
|
|
59 |
testDebianSupported d = TestCase (assertEqual "Debian supported" expected result)
|
|
60 |
where
|
|
61 |
expected = ["lenny", "squeeze", "sid", "experimental"]
|
|
62 |
result = map debSeries $ debianSupported date1 d
|
|
63 |
|
|
64 |
testDebianTesting :: [DebianEntry] -> Test
|
|
65 |
testDebianTesting d = TestCase (assertEqual "Debian testing" expected result)
|
|
66 |
where
|
|
67 |
expected = ["squeeze"]
|
|
68 |
result = map debSeries $ debianTesting date1 d
|
|
69 |
|
|
70 |
testDebianUnsupported :: [DebianEntry] -> Test
|
|
71 |
testDebianUnsupported d = TestCase (assertEqual "Debian unsupported" expected result)
|
|
72 |
where
|
|
73 |
expected = ["buzz", "rex", "bo", "hamm", "slink", "potato", "woody",
|
|
74 |
"sarge", "etch"]
|
|
75 |
result = map debSeries $ debianUnsupported date1 d
|
|
76 |
|
|
77 |
------------------
|
|
78 |
-- Ubuntu tests --
|
|
79 |
------------------
|
|
80 |
|
|
81 |
testUbuntuAll :: [UbuntuEntry] -> Test
|
|
82 |
testUbuntuAll u = TestCase (assertEqual "Ubuntu all" [] (expected \\ result))
|
|
83 |
where
|
|
84 |
expected = ["warty", "hoary", "breezy", "dapper", "edgy", "feisty",
|
|
85 |
"gutsy", "hardy", "intrepid", "jaunty", "karmic", "lucid",
|
|
86 |
"maverick", "natty"]
|
|
87 |
result = map ubuSeries $ ubuntuAll date1 u
|
|
88 |
|
|
89 |
testUbuntuDevel :: [UbuntuEntry] -> Test
|
|
90 |
testUbuntuDevel u = TestCase (assertEqual "Ubuntu devel" expected result)
|
|
91 |
where
|
|
92 |
expected = ["natty"]
|
|
93 |
result = map ubuSeries $ ubuntuDevel date1 u
|
|
94 |
|
|
95 |
testUbuntuLTS :: [UbuntuEntry] -> Test
|
|
96 |
testUbuntuLTS u = TestCase (assertEqual "Ubuntu LTS" expected result)
|
|
97 |
where
|
|
98 |
expected = ["lucid"]
|
|
99 |
result = map ubuSeries $ ubuntuLTS date1 u
|
|
100 |
|
|
101 |
testUbuntuStable :: [UbuntuEntry] -> Test
|
|
102 |
testUbuntuStable u = TestCase (assertEqual "Ubuntu stable" expected result)
|
|
103 |
where
|
|
104 |
expected = ["maverick"]
|
|
105 |
result = map ubuSeries $ ubuntuStable date1 u
|
|
106 |
|
|
107 |
testUbuntuSupported :: [UbuntuEntry] -> Test
|
|
108 |
testUbuntuSupported u = TestCase (assertEqual "Ubuntu supported" expected result)
|
|
109 |
where
|
|
110 |
expected = ["dapper", "hardy", "karmic", "lucid", "maverick", "natty"]
|
|
111 |
result = map ubuSeries $ ubuntuSupported date1 u
|
|
112 |
|
|
113 |
testUbuntuUnsupported :: [UbuntuEntry] -> Test
|
|
114 |
testUbuntuUnsupported u = TestCase (assertEqual "Ubuntu unsupported" expected result)
|
|
115 |
where
|
|
116 |
expected = ["warty", "hoary", "breezy", "edgy", "feisty", "gutsy",
|
|
117 |
"intrepid", "jaunty"]
|
|
118 |
result = map ubuSeries $ ubuntuUnsupported date1 u
|
|
119 |
|
|
120 |
-----------
|
|
121 |
-- Tests --
|
|
122 |
-----------
|
|
123 |
|
|
124 |
tests :: [DebianEntry] -> [UbuntuEntry] -> Test
|
|
125 |
tests d u = TestList [
|
|
126 |
testDebianAll d,
|
|
127 |
testDebianDevel d,
|
|
128 |
testDebianOldstable d,
|
|
129 |
testDebianStable d,
|
|
130 |
testDebianSupported d,
|
|
131 |
testDebianTesting d,
|
|
132 |
testDebianUnsupported d,
|
|
133 |
testUbuntuAll u,
|
|
134 |
testUbuntuDevel u,
|
|
135 |
testUbuntuLTS u,
|
|
136 |
testUbuntuStable u,
|
|
137 |
testUbuntuSupported u,
|
|
138 |
testUbuntuUnsupported u
|
|
139 |
]
|
|
140 |
|
|
141 |
main :: IO ()
|
|
142 |
main = do
|
|
143 |
maybeDebianCsv <- parseCSVFromFile "data/debian.csv"
|
|
144 |
maybeUbuntuCsv <- parseCSVFromFile "data/ubuntu.csv"
|
|
145 |
case maybeDebianCsv of
|
|
146 |
Left errorMsg -> error $ show errorMsg
|
|
147 |
Right csvDebianData ->
|
|
148 |
case maybeUbuntuCsv of
|
|
149 |
Left errorMsg -> error $ show errorMsg
|
|
150 |
Right csvUbuntuData -> do
|
|
151 |
count <- runTestTT $ tests (debianEntry csvDebianData)
|
|
152 |
(ubuntuEntry csvUbuntuData)
|
|
153 |
case count of
|
|
154 |
Counts _ _ 0 0 -> exitWith ExitSuccess
|
|
155 |
_ -> exitWith $ ExitFailure 1
|