Codebase list distro-info / f0f3f81
Add Haskell test suite. Benjamin Drung 12 years ago
6 changed file(s) with 174 addition(s) and 12 deletion(s). Raw diff Collapse all Expand all
112112 Nothing -> onlyOneFilter
113113 Just debianFilter ->
114114 case maybeCsv of
115 Left errorMsg -> print errorMsg
115 Left errorMsg -> error $ show errorMsg
116116 Right csvData ->
117117 let
118118 result = map format $ debianFilter date $ debianEntry csvData
121121 -- Debian Filter --
122122 -------------------
123123
124 -- | Return the lastest entry of a given list.
124 -- | Return the latest entry of a given list.
125125 latest :: Int -> [a] -> [a]
126126 latest i m =
127127 if length m < i
128128 then error "Distribution data outdated."
129129 else [m !! (length m - i)]
130130
131 -- | Evaluates if a given Debian release is already release and still supported.
132 debianIsReleased :: Day -> DebianEntry -> Bool
133 debianIsReleased date DebianEntry { debRelease = release, debEol = eol } =
134 maybe False (date >=) release && maybe True (date <=) eol
135
136131 -- | List all known Debian distributions.
137132 debianAll :: Day -> [DebianEntry] -> [DebianEntry]
138133 debianAll _ = id
146141
147142 -- | Get oldstable Debian distribution based on the given date.
148143 debianOldstable :: Day -> [DebianEntry] -> [DebianEntry]
149 debianOldstable date = latest 2 . filter (debianIsReleased date)
144 debianOldstable date = latest 2 . filter isReleased
145 where
146 isReleased DebianEntry { debRelease = release } =
147 maybe False (date >=) release
150148
151149 -- | Get latest stable distribution based on the given date.
152150 debianStable :: Day -> [DebianEntry] -> [DebianEntry]
153 debianStable date = latest 1 . filter (debianIsReleased date)
151 debianStable date = latest 1 . filter isReleased
152 where
153 isReleased DebianEntry { debRelease = release, debEol = eol } =
154 maybe False (date >=) release && maybe True (date <=) eol
154155
155156 -- | Get list of all supported distributions based on the given date.
156157 debianSupported :: Day -> [DebianEntry] -> [DebianEntry]
99
1010 debian-distro-info: DebianDistroInfo.hs DistroInfo.hs
1111 ghc -Wall -o $@ --make -main-is DebianDistroInfo $<
12
13 test-distro-info: TestDistroInfo.hs DistroInfo.hs
14 ghc -Wall -o $@ --make -main-is TestDistroInfo $<
1215
1316 ubuntu-distro-info: UbuntuDistroInfo.hs DistroInfo.hs
1417 ghc -Wall -o $@ --make -main-is UbuntuDistroInfo $<
2528 install -m 644 $(wildcard perl/Debian/*.pm) $(DESTDIR)$(PREFIX)/share/perl5/Debian
2629 cd python && python setup.py install --root="$(DESTDIR)" --no-compile --install-layout=deb
2730
28 test:
31 test: test-distro-info
32 ./test-distro-info
33 cd perl && ./test.pl
2934 $(foreach python,$(shell pyversions -r),cd python && $(python) setup.py test$(\n))
30 cd perl && ./test.pl
3135
3236 clean:
3337 rm -rf *-distro-info *.hi *.o python/build python/*.egg-info
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
102102 Nothing -> onlyOneFilter
103103 Just ubuntuFilter ->
104104 case maybeCsv of
105 Left errorMsg -> print errorMsg
105 Left errorMsg -> error $ show errorMsg
106106 Right csvData ->
107107 let
108108 result = map format $ ubuntuFilter date $ ubuntuEntry csvData
55 Build-Depends: debhelper (>= 8),
66 ghc,
77 libghc-csv-dev,
8 libghc-hunit-dev,
89 liblist-compare-perl,
910 pylint,
1011 python-all (>= 2.6.3-3~),