Commit 35c5c46b authored by ttuegel's avatar ttuegel
Browse files

Testsuite for Test stanza parsing

Ticket #215 (Overhaul support for packages' tests). Parse and
finalize a simple, dummy .cabal file containing a Test stanza.
Compare with the PackageDescription it which should result
from parsing.
parent d16062cc
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
( PackageDescription(..), BuildInfo(..), Testsuite(..), Library(..)
, TestType(..), emptyPackageDescription, emptyBuildInfo, emptyLibrary
, emptyTestsuite, BuildType(..) )
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 = ["."]
}
}
, testsuites = [ emptyTestsuite
{ testName = "dummy"
, testIs = "dummy.hs"
, testType = ExeTest (thisVersion $ Version [1] [])
, 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
\ No newline at end of file
import Distribution.Simple
main = defaultMain
name: TestStanza
version: 0.1
license: BSD3
author: Thomas Tuegel
stability: stable
category: PackageTests
build-type: Simple
description:
Check that Cabal recognizes the Test stanza defined below.
Library
exposed-modules: MyLibrary
build-depends: base
Test dummy
test-is: dummy.hs
type: executable == 1
build-depends: base
\ No newline at end of file
......@@ -22,6 +22,7 @@ import PackageTests.BuildDeps.InternalLibrary1.Check
import PackageTests.BuildDeps.InternalLibrary2.Check
import PackageTests.BuildDeps.InternalLibrary3.Check
import PackageTests.BuildDeps.InternalLibrary4.Check
import PackageTests.TestStanza.Check
import Distribution.Text (display)
import Distribution.Simple.Utils (cabalVersion)
import Data.Version
......@@ -34,7 +35,11 @@ tests cabalVersion = [
hunit "PackageTests/BuildDeps/SameDepsAllRound/" PackageTests.BuildDeps.SameDepsAllRound.Check.suite,
hunit "PackageTests/BuildDeps/GlobalBuildDepsNotAdditive1/" PackageTests.BuildDeps.GlobalBuildDepsNotAdditive1.Check.suite,
hunit "PackageTests/BuildDeps/GlobalBuildDepsNotAdditive2/" PackageTests.BuildDeps.GlobalBuildDepsNotAdditive2.Check.suite,
hunit "PackageTests/BuildDeps/InternalLibrary0/" (PackageTests.BuildDeps.InternalLibrary0.Check.suite cabalVersion)
hunit "PackageTests/BuildDeps/InternalLibrary0/" (PackageTests.BuildDeps.InternalLibrary0.Check.suite cabalVersion),
hunit "PackageTests/TestStanza/"
(PackageTests.TestStanza.Check.suite cabalVersion)
-- ^ The Test stanza test will eventually be required
-- only for higher versions.
] ++
-- These tests are only required to pass on cabal version >= 1.7
(if cabalVersion >= Version [1, 7] []
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment