Commit 92b1392a authored by ttuegel's avatar ttuegel
Browse files

Added unit test for exitcode-stdio-1.0 test suite with and without HPC.

parent 4b50b01e
......@@ -143,6 +143,7 @@ test-suite unit-tests
PackageTests.BuildDeps.TargetSpecificDeps3.Check,
PackageTests.BuildDeps.SameDepsAllRound.Check,
PackageTests.TestStanza.Check,
PackageTests.TestSuiteExeV10.Check,
PackageTests.PackageTester
hs-source-dirs: tests
build-depends:
......
......@@ -4,6 +4,7 @@ module PackageTests.PackageTester (
Result(..),
cabal_configure,
cabal_build,
cabal_test,
cabal_install,
unregister,
run
......@@ -31,7 +32,7 @@ data PackageSpec =
configOpts :: [String]
}
data Success = Failure | ConfigureSuccess | BuildSuccess | InstallSuccess deriving (Eq, Show)
data Success = Failure | ConfigureSuccess | BuildSuccess | InstallSuccess | TestSuccess deriving (Eq, Show)
data Result = Result {
successful :: Bool,
......@@ -103,6 +104,13 @@ cabal_install spec = do
record spec res
return res
cabal_test :: PackageSpec -> IO Result
cabal_test spec = do
res <- cabal spec ["test"]
let r = recordRun res TestSuccess nullResult
record spec r
return r
-- | Returns the command that was issued, the return code, and hte output text
cabal :: PackageSpec -> [String] -> IO (String, ExitCode, String)
cabal spec cabalArgs = do
......
module PackageTests.TestSuiteExeV10.Check
( checkTest
, checkTestWithHpc
) where
import Distribution.PackageDescription ( TestSuite(..), emptyTestSuite )
import Distribution.Simple.Hpc
import Distribution.Version
import Test.HUnit
import System.Directory
import System.FilePath
import PackageTests.PackageTester
dir :: FilePath
dir = "PackageTests" </> "TestSuiteExeV10"
checkTest :: Version -> Test
checkTest cabalVersion = TestCase $ do
let spec = PackageSpec dir ["--enable-tests"]
buildResult <- cabal_build spec
let buildMessage = "\'setup build\' should succeed"
assertEqual buildMessage True $ successful buildResult
testResult <- cabal_test spec
let testMessage = "\'setup test\' should succeed"
assertEqual testMessage True $ successful testResult
checkTestWithHpc :: Version -> Test
checkTestWithHpc cabalVersion = TestCase $ do
let spec = PackageSpec dir [ "--enable-tests"
, "--enable-library-coverage"
]
buildResult <- cabal_build spec
let buildMessage = "\'setup build\' should succeed"
assertEqual buildMessage True $ successful buildResult
testResult <- cabal_test spec
let testMessage = "\'setup test\' should succeed"
assertEqual testMessage True $ successful testResult
let dummy = emptyTestSuite { testName = "test-Foo" }
tixFile = tixFilePath (dir </> "dist") dummy
tixFileMessage = ".tix file should exist"
markupDir = tixDir (dir </> "dist") 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
module Foo where
fooTest :: [String] -> Bool
fooTest _ = True
import Distribution.Simple
main = defaultMain
name: my
version: 0.1
license: BSD3
cabal-version: >= 1.9.2
build-type: Simple
library
exposed-modules: Foo
build-depends: base
test-suite test-Foo
type: exitcode-stdio-1.0
hs-source-dirs: tests
main-is: test-Foo.hs
build-depends: base, my
module Main where
import Foo
import System.Exit
main :: IO ()
main | fooTest [] = exitSuccess
| otherwise = exitFailure
......@@ -23,6 +23,7 @@ import PackageTests.BuildDeps.InternalLibrary2.Check
import PackageTests.BuildDeps.InternalLibrary3.Check
import PackageTests.BuildDeps.InternalLibrary4.Check
import PackageTests.TestStanza.Check
import PackageTests.TestSuiteExeV10.Check
import Distribution.Text (display)
import Distribution.Simple.Utils (cabalVersion)
import Data.Version
......@@ -38,9 +39,13 @@ tests cabalVersion = [
hunit "PackageTests/BuildDeps/GlobalBuildDepsNotAdditive2/" PackageTests.BuildDeps.GlobalBuildDepsNotAdditive2.Check.suite,
hunit "PackageTests/BuildDeps/InternalLibrary0/" (PackageTests.BuildDeps.InternalLibrary0.Check.suite cabalVersion),
hunit "PackageTests/TestStanza/"
(PackageTests.TestStanza.Check.suite cabalVersion)
(PackageTests.TestStanza.Check.suite cabalVersion),
-- ^ The Test stanza test will eventually be required
-- only for higher versions.
hunit "PackageTests/TestSuiteExeV10/Test"
(PackageTests.TestSuiteExeV10.Check.checkTest cabalVersion),
hunit "PackageTests/TestSuiteExeV10/TestWithHpc"
(PackageTests.TestSuiteExeV10.Check.checkTestWithHpc cabalVersion)
] ++
-- 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