Commit e1e6e123 authored by Duncan Coutts's avatar Duncan Coutts
Browse files

Add a test of the --keep-going feature

This actually only tests the new-build side of things, but the code in
both cases is essentially identical. It also only tests the serial
JobControl not the parallel JobControl. It may be sensible to have a
specific unit test for the two JobControl implementations.
parent e2495eb6
......@@ -114,6 +114,11 @@ Extra-Source-Files:
tests/IntegrationTests/user-config/uses_CABAL_CONFIG.out
tests/IntegrationTests/user-config/uses_CABAL_CONFIG.sh
tests/IntegrationTests2.hs
tests/IntegrationTests2/build/keep-going/cabal.project
tests/IntegrationTests2/build/keep-going/p/P.hs
tests/IntegrationTests2/build/keep-going/p/p.cabal
tests/IntegrationTests2/build/keep-going/q/Q.hs
tests/IntegrationTests2/build/keep-going/q/q.cabal
tests/IntegrationTests2/build/setup-custom1/A.hs
tests/IntegrationTests2/build/setup-custom1/Setup.hs
tests/IntegrationTests2/build/setup-custom1/a.cabal
......
......@@ -18,9 +18,7 @@ import Distribution.Version
import Distribution.Verbosity
import Distribution.Text
#if !MIN_VERSION_base(4,8,0)
import Data.Monoid
#endif
import qualified Data.Map as Map
import Control.Monad
import Control.Exception
......@@ -61,6 +59,7 @@ tests config =
, testGroup "Successful builds" $
[ testCaseSteps "Setup script styles" (testSetupScriptStyles config)
, testCase "keep-going" (testBuildKeepGoing config)
]
, testGroup "Regression tests" $
......@@ -161,6 +160,34 @@ testSetupScriptStyles config reportSubCase = do
hasDefaultSetupDeps = fmap defaultSetupDepends
. setupBuildInfo . pkgDescription
-- | Test the behaviour with and without @--keep-going@
--
testBuildKeepGoing :: ProjectConfig -> Assertion
testBuildKeepGoing config = do
-- P is expected to fail, Q does not depend on P but without
-- parallel build and without keep-going then we don't build Q yet.
plan1 <- executePlan =<< planProject testdir (config <> keepGoing False)
(_, failure1) <- expectPackageFailed plan1 pkgidP
expectBuildFailed failure1
_ <- expectPackageProcessing plan1 pkgidQ
-- With keep-going then we should go on to sucessfully build Q
plan2 <- executePlan =<< planProject testdir (config <> keepGoing True)
(_, failure2) <- expectPackageFailed plan2 pkgidP
expectBuildFailed failure2
_ <- expectPackageInstalled plan2 pkgidQ
return ()
where
testdir = "build/keep-going"
pkgidP = PackageIdentifier (PackageName "p") (Version [0,1] [])
pkgidQ = PackageIdentifier (PackageName "q") (Version [0,1] [])
keepGoing kg =
mempty {
projectConfigBuildOnly = mempty {
projectConfigKeepGoing = toFlag kg
}
}
-- | See <https://github.com/haskell/cabal/issues/3324>
--
testRegressionIssue3324 :: ProjectConfig -> Assertion
......@@ -332,6 +359,15 @@ expectPackageConfigured plan pkgid = do
-> return pkg
_ -> unexpectedPackageState "Configured" planpkg
expectPackageProcessing :: ElaboratedInstallPlan -> PackageId
-> IO ElaboratedConfiguredPackage
expectPackageProcessing plan pkgid = do
planpkg <- expectPlanPackage plan pkgid
case planpkg of
InstallPlan.Processing (ReadyPackage pkg)
-> return pkg
_ -> unexpectedPackageState "Processing" planpkg
expectPackageInstalled :: ElaboratedInstallPlan -> PackageId
-> IO (ElaboratedConfiguredPackage,
Maybe InstalledPackageInfo,
......@@ -357,7 +393,7 @@ unexpectedPackageState :: String -> ElaboratedPlanPackage -> IO a
unexpectedPackageState expected planpkg =
throwIO $ HUnitFailure $
"expected to find " ++ display (packageId planpkg) ++ " in the "
++ expected ++ " state, but it is actually in the " ++ actual ++ "state."
++ expected ++ " state, but it is actually in the " ++ actual ++ " state."
where
actual = case planpkg of
InstallPlan.PreExisting{} -> "PreExisting"
......
module P where
p :: Int
p = this_is_not_expected_to_compile
name: p
version: 0.1
build-type: Simple
cabal-version: >= 1.2
library
exposed-modules: P
build-depends: base
name: q
version: 0.1
build-type: Simple
cabal-version: >= 1.2
library
exposed-modules: Q
build-depends: base
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