Commit 0f816ccb authored by refold's avatar refold
Browse files

Make TestSuiteExeV10/TestWithHpc check hpc version.

Fixes #1206.
parent 8b4a6cd5
......@@ -3,13 +3,21 @@ module PackageTests.TestSuiteExeV10.Check
, checkTestWithHpc
) where
import Distribution.PackageDescription ( TestSuite(..), emptyTestSuite )
import Distribution.PackageDescription ( TestSuite(..), emptyTestSuite )
import Distribution.Version ( Version(..), orLaterVersion )
import Distribution.Simple.Hpc
import Distribution.Simple.Program.Builtin ( hpcProgram )
import Distribution.Simple.Program.Db ( emptyProgramDb, configureProgram,
requireProgramVersion )
import PackageTests.PackageTester
import qualified Control.Exception as E ( IOException, catch )
import Control.Monad ( when )
import System.Directory
import System.FilePath
import Test.HUnit
import qualified Distribution.Verbosity as Verbosity
dir :: FilePath
dir = "PackageTests" </> "TestSuiteExeV10"
......@@ -23,20 +31,35 @@ checkTest = TestCase $ do
checkTestWithHpc :: Test
checkTestWithHpc = TestCase $ do
let spec = PackageSpec dir [ "--enable-tests"
, "--enable-library-coverage"
]
buildResult <- cabal_build spec
assertBuildSucceeded buildResult
testResult <- cabal_test spec []
assertTestSucceeded testResult
let dummy = emptyTestSuite { testName = "test-Foo" }
tixFile = tixFilePath (dir </> "dist") $ testName dummy
tixFileMessage = ".tix file should exist"
markupDir = htmlDir (dir </> "dist") $ testName dummy
markupFile = markupDir </> "hpc_index" <.> "html"
markupFileMessage = "HPC markup file should exist"
tixFileExists <- doesFileExist tixFile
assertEqual tixFileMessage True tixFileExists
markupFileExists <- doesFileExist markupFile
assertEqual markupFileMessage True markupFileExists
isCorrectVersion <- checkHpcVersion
when isCorrectVersion $ do
let spec = PackageSpec dir [ "--enable-tests"
, "--enable-library-coverage"
]
buildResult <- cabal_build spec
assertBuildSucceeded buildResult
testResult <- cabal_test spec []
assertTestSucceeded testResult
let dummy = emptyTestSuite { testName = "test-Foo" }
tixFile = tixFilePath (dir </> "dist") $ testName dummy
tixFileMessage = ".tix file should exist"
markupDir = htmlDir (dir </> "dist") $ testName dummy
markupFile = markupDir </> "hpc_index" <.> "html"
markupFileMessage = "HPC markup file should exist"
tixFileExists <- doesFileExist tixFile
assertEqual tixFileMessage True tixFileExists
markupFileExists <- doesFileExist markupFile
assertEqual markupFileMessage True markupFileExists
where
checkHpcVersion :: IO Bool
checkHpcVersion = do
let programDb' = emptyProgramDb
let verbosity = Verbosity.normal
let verRange = orLaterVersion (Version [0,7] [])
programDb <- configureProgram verbosity hpcProgram programDb'
(requireProgramVersion verbosity hpcProgram verRange programDb
>> return True) `catchIO` (\_ -> return False)
-- Distirubution.Compat.Exception is hidden.
catchIO :: IO a -> (E.IOException -> IO a) -> IO a
catchIO = E.catch
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