Check.hs 3.58 KB
Newer Older
ttuegel's avatar
ttuegel committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
module PackageTests.TestStanza.Check where

import Test.HUnit
import System.FilePath
import PackageTests.PackageTester
import Data.List (isInfixOf, intercalate)
import Distribution.Version
import Distribution.PackageDescription.Parse
        ( readPackageDescription )
import Distribution.PackageDescription.Configuration
        ( finalizePackageDescription )
import Distribution.Package
        ( PackageIdentifier(..), PackageName(..), Dependency(..) )
import Distribution.PackageDescription
15
        ( PackageDescription(..), BuildInfo(..), TestSuite(..), Library(..)
ttuegel's avatar
ttuegel committed
16
        , TestType(..), emptyPackageDescription, emptyBuildInfo, emptyLibrary
17
        , emptyTestSuite, BuildType(..) )
ttuegel's avatar
ttuegel committed
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
import Distribution.Verbosity (silent)
import Distribution.License (License(..))
import Distribution.ModuleName (fromString)
import Distribution.System (buildPlatform)
import Distribution.Compiler
        ( CompilerId(..), CompilerFlavor(..) )
import Distribution.Text

suite :: Version -> Test
suite cabalVersion = TestCase $ do
    let directory = "PackageTests" </> "TestStanza"
        pdFile = directory </> "my" <.> "cabal"
        spec = PackageSpec directory []
    result <- cabal_configure spec
    let message = "cabal configure should recognize test section"
        test = "unknown section type"
               `isInfixOf`
               (intercalate " " $ lines $ outputText result)
    assertEqual message False test
    genPD <- readPackageDescription silent pdFile
    let compiler = CompilerId GHC $ Version [6, 12, 2] []
        anyV = intersectVersionRanges anyVersion anyVersion
        anticipatedFinalPD = emptyPackageDescription
                { package = PackageIdentifier
                        { pkgName = PackageName "TestStanza"
                        , pkgVersion = Version [0, 1] []
                        }
                , license = BSD3
                , author = "Thomas Tuegel"
                , stability = "stable"
                , description = "Check that Cabal recognizes the Test stanza defined below."
                , category = "PackageTests"
                , descCabalVersion = anyVersion
                , buildType = Just Simple
                , buildDepends =
                    [ Dependency (PackageName "base") anyV ]
                , library = Just emptyLibrary
                        { exposedModules = [fromString "MyLibrary"]
                        , libBuildInfo = emptyBuildInfo
                                { targetBuildDepends =
                                        [ Dependency (PackageName "base") anyVersion ]
                                , hsSourceDirs = ["."]
                                }
                        }
62
                , testSuites = [ emptyTestSuite
ttuegel's avatar
ttuegel committed
63
                        { testName = "dummy"
64
                        , testType = ExeTest (Version [1,0] []) "dummy.hs"
ttuegel's avatar
ttuegel committed
65
66
67
68
69
70
71
72
73
74
75
76
77
78
                        , testBuildInfo = emptyBuildInfo
                                { targetBuildDepends =
                                        [ Dependency (PackageName "base") anyVersion ]
                                , hsSourceDirs = ["."]
                                }
                        }
                                ]
                }
    case finalizePackageDescription [] (const True) buildPlatform compiler [] genPD of
        Left xs -> let depMessage = "should not have missing dependencies:\n" ++
                                    (unlines $ map (show . disp) xs)
                   in assertEqual depMessage True False
        Right (f, _) -> assertEqual "parsed package description does not match anticipated"
                                f anticipatedFinalPD