Commit 4f5ab192 authored by tibbe's avatar tibbe
Browse files

Add unit test for benchmark section

parent dee975fe
......@@ -147,6 +147,7 @@ test-suite unit-tests
PackageTests.TestOptions.Check,
PackageTests.TestStanza.Check,
PackageTests.TestSuiteExeV10.Check,
PackageTests.BenchmarkStanza.Check,
PackageTests.PackageTester
hs-source-dirs: tests
build-depends:
......
module PackageTests.BenchmarkStanza.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(..), Benchmark(..), Library(..)
, BenchmarkInterface(..)
, TestType(..), emptyPackageDescription, emptyBuildInfo, emptyLibrary
, emptyBenchmark, 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" </> "BenchmarkStanza"
pdFile = directory </> "my" <.> "cabal"
spec = PackageSpec directory []
result <- cabal_configure spec
let message = "cabal configure should recognize benchmark 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
anticipatedBenchmark = emptyBenchmark
{ benchmarkName = "dummy"
, benchmarkInterface = BenchmarkExeV10 (Version [1,0] []) "dummy.hs"
, benchmarkBuildInfo = emptyBuildInfo
{ targetBuildDepends =
[ Dependency (PackageName "base") anyVersion ]
, hsSourceDirs = ["."]
}
, benchmarkEnabled = False
}
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, _) -> let gotBenchmark = head $ benchmarks f
in assertEqual "parsed benchmark stanza does not match anticipated"
gotBenchmark anticipatedBenchmark
import Distribution.Simple
main = defaultMain
name: BenchmarkStanza
version: 0.1
license: BSD3
author: Johan Tibell
stability: stable
category: PackageTests
build-type: Simple
description:
Check that Cabal recognizes the benchmark stanza defined below.
Library
exposed-modules: MyLibrary
build-depends: base
benchmark dummy
main-is: dummy.hs
type: exitcode-stdio-1.0
build-depends: base
\ No newline at end of file
......@@ -10,6 +10,7 @@ import Test.Framework
import Test.Framework.Providers.HUnit
import Test.Framework.Providers.QuickCheck2
import qualified Test.HUnit as HUnit
import PackageTests.BenchmarkStanza.Check
import PackageTests.BuildDeps.SameDepsAllRound.Check
import PackageTests.BuildDeps.TargetSpecificDeps1.Check
import PackageTests.BuildDeps.TargetSpecificDeps1.Check
......@@ -46,7 +47,10 @@ tests cabalVersion = [
(PackageTests.TestSuiteExeV10.Check.checkTest cabalVersion),
hunit "PackageTests/TestSuiteExeV10/TestWithHpc"
(PackageTests.TestSuiteExeV10.Check.checkTestWithHpc cabalVersion),
hunit "PackageTests/TestOptions" PackageTests.TestOptions.Check.suite
hunit "PackageTests/TestOptions" PackageTests.TestOptions.Check.suite,
hunit "PackageTests/BenchmarkStanza/" (PackageTests.BenchmarkStanza.Check.suite cabalVersion)
-- ^ The benchmark 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] []
......
Markdown is supported
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