Package.hs 20.6 KB
Newer Older
ijones's avatar
ijones committed
1
{-# OPTIONS -cpp -DDEBUG #-}
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
-----------------------------------------------------------------------------
-- |
-- Module      :  Distribution.Package
-- Copyright   :  Isaac Jones 2003-2004
-- 
-- Maintainer  :  Isaac Jones <ijones@syntaxpolice.org>
-- Stability   :  alpha
-- Portability :  
--
-- Explanation: <FIX>
-- WHERE DOES THIS MODULE FIT IN AT A HIGH-LEVEL <FIX>

{- Copyright (c) 2003-2004, Isaac Jones
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

    * Redistributions of source code must retain the above copyright
      notice, this list of conditions and the following disclaimer.

    * Redistributions in binary form must reproduce the above
      copyright notice, this list of conditions and the following
      disclaimer in the documentation and/or other materials provided
      with the distribution.

    * Neither the name of Isaac Jones nor the names of other
      contributors may be used to endorse or promote products derived
      from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -}

45
module Distribution.Package (
simonmar's avatar
simonmar committed
46
47
	PackageIdentifier(..), 
	showPackageId,
48
	PackageDescription(..),
md9ms's avatar
md9ms committed
49
        BuildInfo(..),
ijones's avatar
ijones committed
50
	emptyPackageDescription,
51
        parsePackageDesc,
ijones's avatar
ijones committed
52
#ifdef DEBUG        
53
        hunitTests,
ijones's avatar
ijones committed
54
        test
ijones's avatar
ijones committed
55
#endif
56
  ) where
57

md9ms's avatar
md9ms committed
58
59
60
61
import Control.Monad.State
import Control.Monad(when, foldM)
import Control.Monad.Error
import Data.Char(isSpace, toLower)
md9ms's avatar
md9ms committed
62
import Data.List(isPrefixOf)
63
import Data.Maybe(fromMaybe)
ijones's avatar
ijones committed
64

65
66
import Distribution.Version(Version(..), VersionRange(..),
                            showVersion, parseVersion, parseVersionRange)
md9ms's avatar
md9ms committed
67
import Distribution.Misc(License(..), Dependency(..), Extension(..))
md9ms's avatar
md9ms committed
68
import Distribution.Setup(CompilerFlavor(..))
69

70
71
import System.IO(openFile, IOMode(..), hGetContents)

ijones's avatar
ijones committed
72
73
import Text.ParserCombinators.Parsec

ijones's avatar
ijones committed
74
#ifdef DEBUG
ijones's avatar
ijones committed
75
import HUnit (Test(..), (~:), (~=?), assertEqual, assertBool, Assertion, runTestTT)
ijones's avatar
ijones committed
76
77
#endif

78
79
data PackageIdentifier
    = PackageIdentifier {pkgName::String, pkgVersion::Version}
simonmar's avatar
simonmar committed
80
      deriving (Read, Show, Eq)
81

simonmar's avatar
simonmar committed
82
showPackageId :: PackageIdentifier -> String
ijones's avatar
ijones committed
83
showPackageId (PackageIdentifier n (Version [] _)) = n -- if no version, don't show version.
simonmar's avatar
simonmar committed
84
85
86
showPackageId pkgid = 
  pkgName pkgid ++ '-': showVersion (pkgVersion pkgid)

87
88
89
90
91
92
93
94
95
96
-- | This data type is the internal representation of the file @pkg.descr@.
-- It contains two kinds of information about the package: information
-- which is needed for all packages, such as the package name and version, and 
-- information which is needed for the simple build system only, such as 
-- the compiler options and library name.
-- 
data PackageDescription
    =  PackageDescription {
	-- the following are required by all packages:
	package        :: PackageIdentifier,
97
        license        :: License,
98
99
100
        copyright      :: String,
        maintainer     :: String,
        stability      :: String,
101
102
        library        :: Maybe BuildInfo,
        executables    :: [(String,BuildInfo)]
103
    }
ijones's avatar
ijones committed
104
105
    deriving (Show, Read, Eq)

106
107
108
109
110
111
112
113
114
115
116
117
118
119
data BuildInfo = BuildInfo {
        buildDepends    :: [Dependency],
        modules         :: [String],
	exposedModules  :: [String],
        cSources        :: [FilePath],
        hsSourceDir     :: FilePath,
        extensions      :: [Extension],
        extraLibs       :: [String],
        includeDirs     :: [FilePath],
        includes        :: [FilePath],
        options         :: [(CompilerFlavor,[String])]
    }
    deriving (Show,Read,Eq)

ijones's avatar
ijones committed
120
121
122
123
124
125
126
127
128
-- |Set the name for this package. Convenience function.
setPkgName :: String -> PackageDescription -> PackageDescription
setPkgName n desc@PackageDescription{package=pkgIdent}
    = desc{package=pkgIdent{pkgName=n}}

-- |Set the version for this package. Convenience function.
setPkgVersion :: Version -> PackageDescription -> PackageDescription
setPkgVersion v desc@PackageDescription{package=pkgIdent}
    = desc{package=pkgIdent{pkgVersion=v}}
129
130
131

emptyPackageDescription :: PackageDescription
emptyPackageDescription
ijones's avatar
ijones committed
132
    =  PackageDescription {package      = PackageIdentifier "" (Version [] []),
133
                      license      = AllRightsReserved,
134
135
136
                      copyright    = "",
                      maintainer   = "",
                      stability    = "",
137
138
                      library      = Nothing,
                      executables  = []
139
                     }
140

141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
emptyBuildInfo :: BuildInfo
emptyBuildInfo = BuildInfo {
                      buildDepends   = [],
                      modules        = [],
		      exposedModules = [], -- Only used for libs
		      cSources       = [],
		      hsSourceDir    = ".", -- FIX: FileUtils.currentDir
                      extensions     = [],
                      extraLibs      = [],
                      includeDirs    = [],
                      includes       = [],
                      options        = []
                     }
                        
-- |Add options for a specific compiler. Convenience function.
setOptions :: CompilerFlavor -> [String] -> BuildInfo -> BuildInfo
setOptions c xs desc@BuildInfo{options=opts}
    = desc{options=(c,xs):opts}
ijones's avatar
ijones committed
159
160
161
162
163

-- ------------------------------------------------------------
-- * Parsing
-- ------------------------------------------------------------

ijones's avatar
ijones committed
164
165
166
notImp :: String -> a
notImp s = error $ s ++ " not yet implemented"

167
-- |Parse the given package file.
168
parsePackageDesc :: FilePath -> IO PackageDescription
169
170
171
parsePackageDesc p = do h <- openFile p ReadMode
                        str <- hGetContents h
                        case parseDescription str of
md9ms's avatar
md9ms committed
172
                          Left  e -> error (showError e) -- FIXME
173
                          Right x -> return x
174

md9ms's avatar
md9ms committed
175
176
177
178
179
180
data PError = Parsec ParseError | FromString String
        deriving Show

instance Error PError where
        strMsg = FromString

md9ms's avatar
md9ms committed
181
182
183
showError (Parsec pe)    = show pe
showError (FromString s) = s

md9ms's avatar
md9ms committed
184
parseDescription :: String -> Either PError PackageDescription
185
186
187
188
189
190
191
parseDescription inp = do let (st:sts) = splitStanzas inp
                          pkg <- foldM parseBasicStanza emptyPackageDescription st
                          exes <- mapM parseExecutableStanza sts
                          return pkg{executables=exes}
  where -- The basic stanza, with library building info
        parseBasicStanza pkg (f@"name",      val) = return (setPkgName val pkg)
        parseBasicStanza pkg (f@"version",   val) =
md9ms's avatar
md9ms committed
192
193
          do v <- runP f parseVersion val
             return (setPkgVersion v pkg)
194
195
        parseBasicStanza pkg (f@"copyright", val) = return pkg{copyright=val}
        parseBasicStanza pkg (f@"license",   val) =
md9ms's avatar
md9ms committed
196
197
          do l <- runP f parseLicense val
             return pkg{license=l}
198
199
200
201
202
203
204
205
206
207
208
        parseBasicStanza pkg (f@"maintainer", val) = return pkg{maintainer=val}
        parseBasicStanza pkg (f@"stability",  val) = return pkg{stability=val}
        parseBasicStanza pkg (field, val) =
          do let lib = fromMaybe emptyBuildInfo (library pkg)
             lib' <- parseExeHelp lib (field, val)
             return pkg{library=Just lib'}
        -- Stanzas for executables
        parseExecutableStanza (("executable",exeName):st) =
          do binfo <- foldM parseExeHelp emptyBuildInfo st
             return (exeName,binfo)
        parseExeHelp binfo (f@"extra-libs", val) =
md9ms's avatar
md9ms committed
209
          do xs <- runP f (parseCommaList word) val
210
211
             return binfo{extraLibs=xs}
        parseExeHelp binfo (f@"build-depends", val) =
md9ms's avatar
md9ms committed
212
          do xs <- runP f (parseCommaList parseDependency) val
213
             return binfo{buildDepends=xs}
md9ms's avatar
md9ms committed
214
        -- Paths and stuff
215
        parseExeHelp binfo (f@"c-sources", val) =
216
          do paths <- runP f (parseCommaList parseFilePath) val
217
218
             return binfo{cSources=paths}
        parseExeHelp binfo (f@"include-dirs", val) =
219
          do paths <- runP f (parseCommaList parseFilePath) val
220
221
             return binfo{includeDirs=paths}
        parseExeHelp binfo (f@"includes", val) =
222
          do paths <- runP f (parseCommaList parseFilePath) val
223
224
             return binfo{includes=paths}
        parseExeHelp binfo (f@"hs-source-dir", val) =
md9ms's avatar
md9ms committed
225
          do path <- runP f parseFilePath val
226
             return binfo{hsSourceDir=path}
md9ms's avatar
md9ms committed
227
        -- Module related
228
        parseExeHelp binfo (f@"modules", val) =
md9ms's avatar
md9ms committed
229
          do xs <- runP f (parseCommaList moduleName) val
230
231
             return binfo{modules=xs}
        parseExeHelp binfo (f@"exposed-modules", val) =
md9ms's avatar
md9ms committed
232
          do xs <- runP f (parseCommaList moduleName) val
233
234
             return binfo{exposedModules=xs}
        parseExeHelp binfo (f@"extensions", val) =
md9ms's avatar
md9ms committed
235
          do exts <- runP f (parseCommaList parseExtension) val
236
237
             return binfo{extensions=exts}
        parseExeHelp binfo (f, val) | "options-" `isPrefixOf` f =
md9ms's avatar
md9ms committed
238
239
240
          let compilers = [("ghc",GHC),("nhc",NHC),("hugs",Hugs)] -- FIXME
           in case lookup (drop 8 f) compilers of
                Just c -> do xs <- runP f (parseCommaList parseOption) val
241
                             return (setOptions c xs binfo)
md9ms's avatar
md9ms committed
242
                Nothing -> error $ "Unknown compiler (" ++ drop 8 f ++ ")"
243
        parseExeHelp binfo (field, val) = error $ "Unknown field :: " ++ field
md9ms's avatar
md9ms committed
244
245
246
247
248
        -- ...
        runP f p s = case parse p f s of
                       Left pe -> Left (Parsec pe)
                       Right a -> Right a

249
250
251
252
253
254
type Stanza = [(String,String)]

-- |Split a string into blank line-separated stanzas of
-- "Field: value" groups
splitStanzas :: String -> [Stanza]
splitStanzas = map merge . groupStanzas . filter validLine . lines
md9ms's avatar
md9ms committed
255
256
257
  where validLine s = case dropWhile isSpace s of
                        '-':'-':_ -> False      -- Comment
                        _         -> True
258
259
260
        groupStanzas [] = []
        groupStanzas xs = let (ys,zs) = break (all isSpace) xs
                           in ys : groupStanzas (dropWhile (all isSpace) zs)
md9ms's avatar
md9ms committed
261
262
263
264
265
266
267
268
        merge (x:(' ':s):ys) = case dropWhile isSpace s of
                                 "." -> merge ((x++"\n"):ys)
                                 s'  -> merge ((x++"\n"++s'):ys)
        merge (x:ys) = brk x : merge ys
        merge []     = []
        brk xs = case break (==':') xs of
                   (fld, ':':val) -> (map toLower fld, dropWhile isSpace val)
                   (fld, "")      -> error "FIXME"
ijones's avatar
ijones committed
269

270
-- |parse a module name
md9ms's avatar
md9ms committed
271
moduleName = many (alphaNum <|> oneOf "_'.") <?> "moduleName"
ijones's avatar
ijones committed
272

273
274
275
276
277
278
279
mainModule = do filename <- word
                skipMany parseWhite
                char ':'
                skipMany parseWhite
                modname <- moduleName
                return (filename,modname)

280
-- |FIX: must learn to escape whitespace
281
282
283
284
285
286
parseFilePath :: GenParser Char st FilePath
parseFilePath = liftM concat (many1 (
                        do try word
                           <|> toStr digit
                           <|> toStr (oneOf "!@#$%^&*()?></\\|]}[{.")
                       ))
md9ms's avatar
md9ms committed
287
        <?> "parseFilePath"
288

289
parseDependency :: GenParser Char st Dependency
md9ms's avatar
md9ms committed
290
parseDependency = do name <- many1 (letter <|> digit <|> oneOf "-_")
291
                     skipMany parseWhite
292
                     ver <- parseVersionRange <|> return AnyVersion
293
294
                     skipMany parseWhite
                     return $ Dependency name ver
md9ms's avatar
md9ms committed
295
        <?> "parseDependency"
296

297
298
299
300
parseLicense :: GenParser Char st License
parseLicense = choice [ try (string s >> return l) | (s,l) <- licenses]
        <?> "parseLicense"

ijones's avatar
ijones committed
301
302
303
304
305
306
307
308
309
-- |Mapping between the licenses and their names
licenses :: [(String, License)]
licenses= [("GPL", GPL),
           ("LGPL", LGPL),
           ("BSD3", BSD3),
           ("BSD4", BSD4),
           ("PublicDomain", PublicDomain),
           ("AllRightsReserved", AllRightsReserved)]

md9ms's avatar
md9ms committed
310
311
312
313
314
315
316
317
318
parseExtension :: GenParser Char st Extension
parseExtension = choice [ try (string s >> return e) | (s,e) <- extensionsMap ]
        <?> "parseExtension"

-- |Mapping between extensions and their names
extensionsMap = [("OverlappingInstances", OverlappingInstances),
                 ("TypeSynonymInstances", TypeSynonymInstances),
                 ("TemplateHaskell", TemplateHaskell)]

md9ms's avatar
md9ms committed
319
320
parseOption = many1 (letter <|> digit <|> oneOf "-+/\\._") -- FIXME

321
toStr c = c >>= \x -> return [x]
ijones's avatar
ijones committed
322
323

word :: GenParser Char st String
ijones's avatar
ijones committed
324
325
326
327
328
329
330
word = many1 letter <?> "word"

parseCommaList :: GenParser Char st a -- ^The parser for the stuff between commas
               -> GenParser Char st [a]
parseCommaList p
    = do words <- sepBy1 p separator
         return words
md9ms's avatar
md9ms committed
331
    where separator = spaces >> char ',' >> spaces
ijones's avatar
ijones committed
332
333

parseWhite = try parseSpaceNotNewline
334
            <|> (try (char '\n' >> parseWhite))
ijones's avatar
ijones committed
335
336
337
338
339
340

parseSpaceNotNewline = (satisfy isSpaceNotNewline <?> "space, not newline")
    where isSpaceNotNewline :: Char -> Bool
          isSpaceNotNewline '\n' = False
          isSpaceNotNewline n    = isSpace n

ijones's avatar
ijones committed
341
342
343
344
-- ------------------------------------------------------------
-- * Testing
-- ------------------------------------------------------------
#ifdef DEBUG
345
346
347
348
349
350
351
352
353
354
355
356
357
testPkgDesc = unlines [
        "-- Required",
        "Name: Cabal",
        "Version: 0.1.1.1.1-rain",
        "License: LGPL",
        "Copyright: Free Text String",
        "-- Optional - may be in source?",
        "Stability: Free Text String",
        "Build-Depends: haskell-src, HUnit>=1.0.0-rain",
        "Modules: Distribution.Package, Distribution.Version, Distribution.Simple.GHCPackageConfig",
        "C-Sources: not/even/rain.c, such/small/hands",
        "HS-Source-Dir: src",
        "Exposed-Modules: Distribution.Void, Foo.Bar",
md9ms's avatar
md9ms committed
358
        "Extensions: OverlappingInstances, TypeSynonymInstances",
359
360
361
        "Extra-Libs: libfoo, bar, bang",
        "Include-Dirs: your/slightest, look/will",
        "Includes: /easily/unclose, /me",
md9ms's avatar
md9ms committed
362
        "Options-ghc: -fTH",
363
364
365
366
367
368
369
        "Options-hugs: +TH",
        "",
        "-- Next is an executable",
        "Executable: somescript",
        "Modules: Foo1, Util, Main",
        "HS-Source-Dir: scripts",
        "Extensions: OverlappingInstances"
370
        ]
ijones's avatar
ijones committed
371
372
373

testPkgDescAnswer = 
 PackageDescription {package = PackageIdentifier {pkgName = "Cabal",
ijones's avatar
ijones committed
374
                                                 pkgVersion = Version {versionBranch = [0,1,1,1,1],
md9ms's avatar
md9ms committed
375
                                                 versionTags = ["rain"]}},
ijones's avatar
ijones committed
376
                    license = LGPL,
ijones's avatar
ijones committed
377
                    copyright = "Free Text String",
ijones's avatar
ijones committed
378
                    maintainer = "",
ijones's avatar
ijones committed
379
                    stability = "Free Text String",
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403

                    library = Just $ BuildInfo {
                        buildDepends = [Dependency "haskell-src" AnyVersion,
                                        Dependency "HUnit"
                                         (UnionVersionRanges (ThisVersion (Version [1,0,0] ["rain"]))
                                          (LaterVersion (Version [1,0,0] ["rain"])))],

                        modules = ["Distribution.Package","Distribution.Version",
                                      "Distribution.Simple.GHCPackageConfig"],

                        cSources = ["not/even/rain.c", "such/small/hands"],
                        hsSourceDir = "src",
                        exposedModules = ["Distribution.Void", "Foo.Bar"],
                        extensions = [OverlappingInstances, TypeSynonymInstances],
                        extraLibs = ["libfoo", "bar", "bang"],
                        includeDirs = ["your/slightest", "look/will"],
                        includes = ["/easily/unclose", "/me"],
                        options = [(Hugs,["+TH"]), (GHC,["-fTH"])] -- Note reversed order
                    },
                    executables = [("somescript", emptyBuildInfo{
                        modules = ["Foo1","Util","Main"],
                        hsSourceDir = "scripts",
                        extensions = [OverlappingInstances]
                      })]
ijones's avatar
ijones committed
404
405
}

ijones's avatar
ijones committed
406
hunitTests :: [Test]
407
408
409
410
411
hunitTests = [TestLabel "newline before word (parsewhite)" $ TestCase $
              do assertRight "newline before word 1"
                  "foo" (parse (skipMany parseWhite>>char '\n'>>word) "" "   \n  \nfoo")
                 assertRight "newline before word 2"
                  "foo" (parse (skipMany parseWhite>>char '\n'>>word) "" "   \n \t    \n  \nfoo"),
ijones's avatar
ijones committed
412
413

              TestLabel "skip spaces not newlines" $ TestCase $
414
415
416
417
418
419
420
421
              do assertRight "spaces with newlines"
                  "foo" (parse (skipMany parseWhite>>word) "" "   \n  foo")
                 assertRight "spaces with newlines"
                  "foo" (parse (skipMany parseWhite>>word) "" "   \n \t\n   foo")
                 assertRight "no preceding spaces"
                  "foo" (parse (skipMany parseWhite>>word) "" "foo")
                 assertBool "newline before data without in-between spaces"
                  (isError (parse (skipMany parseWhite>>word) "" "   \n  \nfoo")),
ijones's avatar
ijones committed
422

md9ms's avatar
md9ms committed
423
424
425
426
427
428
--              TestLabel "basic fields" $ TestCase $
--              do let p1 = parse (do w1 <- parseField "Foo" False parseVersion
--                                    skipMany parseWhite
--                                    w2 <- parseField "Bar" True word
--                                    return (w1, w2)
--                                ) ""
md9ms's avatar
md9ms committed
429
--                     knownVal1 = (Version {versionBranch = [3,2], versionTags = ["one"]},"boo")
md9ms's avatar
md9ms committed
430
431
432
433
434
435
436
437
438
439
440
441
--                 assertRight "basic spaces 1"
--                   knownVal1 (p1 "Foo: 3.2-one\nBar: boo")
--                 assertRight "basic spaces 2"
--                   knownVal1 (p1 "Foo: 3.2-one \t   \nBar: boo")
--                 assertRight "basic spaces 3"
--                   knownVal1 (p1 "Foo : 3.2-one \t   \nBar:    boo  ")
--                 assertRight "basic spaces 3"
--                   knownVal1 (p1 "Foo:3.2-one \t   \nBar:    boo  ")
--                 assertRight "basic spaces with newline"
--                   knownVal1 (p1 "Foo:\n 3.2-one \t   \nBar:    boo  ")
--                 assertRight "basic spaces with newline"
--                   knownVal1 (p1 "Foo:\n 3.2-one \t \n  \nBar:    boo  "),
ijones's avatar
ijones committed
442

ijones's avatar
ijones committed
443
444
445
446
447
              TestCase (assertRight "BSD4" BSD4 (parse parseLicense "" "BSD4")),

              TestLabel "license parsers" $ 
                        TestCase (sequence_ [assertRight ("license " ++ lName) lVal
                                                    (parse parseLicense "" lName)
ijones's avatar
ijones committed
448
449
450
451
452
                                             | (lName, lVal) <- licenses]),

              TestLabel "Required fields" $ TestCase $
                 do assertRight "some fields"
                       emptyPackageDescription{package=(PackageIdentifier "foo"
md9ms's avatar
md9ms committed
453
                                                        (Version [0,0] ["asdf"]))}
ijones's avatar
ijones committed
454
455
456
457
                       (parseDescription "Name: foo\nVersion: 0.0-asdf")

                    assertRight "more fields foo"
                       emptyPackageDescription{package=(PackageIdentifier "foo"
md9ms's avatar
md9ms committed
458
                                                        (Version [0,0]["asdf"])),
ijones's avatar
ijones committed
459
460
461
462
463
                                               license=GPL}
                       (parseDescription "Name: foo\nVersion:0.0-asdf\nLicense: GPL")

                    assertRight "required fields for foo"
                       emptyPackageDescription{package=(PackageIdentifier "foo"
md9ms's avatar
md9ms committed
464
                                                        (Version [0,0]["asdf"])),
ijones's avatar
ijones committed
465
466
467
                                        license=GPL, copyright="2004 isaac jones"}
                       (parseDescription "Name: foo\nVersion:0.0-asdf\nCopyright: 2004 isaac jones\nLicense: GPL"),
                                          
468
469
             TestCase $ assertRight "no library" Nothing
                        (library `liftM` parseDescription "Name: foo\nVersion: 1\nLicense: GPL\nMaintainer: someone\n\nExecutable: script\n"),
ijones's avatar
ijones committed
470
471
472
473

             TestLabel "Package description" $ TestCase $ 
                assertRight "entire package description" testPkgDescAnswer
                                                         (parseDescription testPkgDesc)
md9ms's avatar
md9ms committed
474

ijones's avatar
ijones committed
475
476
             ]

ijones's avatar
ijones committed
477

ijones's avatar
ijones committed
478
479
480
481
482
483
484
485
486
487
assertRight :: (Eq val) => String -> val -> (Either a val) -> Assertion
assertRight mes expected actual
    =  assertBool mes
           (case actual of
             (Right v) -> v == expected
             _         -> False)

isError (Left _) = True
isError _        = False

ijones's avatar
ijones committed
488
test = runTestTT (TestList hunitTests)
ijones's avatar
ijones committed
489
#endif