Skip to content

Commit

Permalink
Filter out components that don't match the package, which is still no…
Browse files Browse the repository at this point in the history
…t quite good.

It really feels like the best thing to do is figure out a way to fix
hpc relative mix paths, instead of not allowing multiple packages and
filtering libraries out..
  • Loading branch information
alt-romes committed Dec 5, 2023
1 parent becbb39 commit de274f2
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 23 deletions.
4 changes: 2 additions & 2 deletions Cabal/src/Distribution/Simple/Errors.hs
Original file line number Diff line number Diff line change
Expand Up @@ -715,12 +715,12 @@ exceptionMessage e = case e of
"Could not find test program \""
++ cmd
++ "\". Did you build the package first?"
TestCoverageSupport -> "Test coverage is only supported for projects with at least one (non-backpack) library component."
TestCoverageSupport -> "Test coverage is only supported for packages with a library component."
Couldn'tFindTestProgLibV09 cmd ->
"Could not find test program \""
++ cmd
++ "\". Did you build the package first?"
TestCoverageSupportLibV09 -> "Test coverage is only supported for projects with at least one (non-backpack) library component."
TestCoverageSupportLibV09 -> "Test coverage is only supported for packages with a library component."
RawSystemStdout errors -> errors
FindFileCwd fileName -> fileName ++ " doesn't exist"
FindFileEx fileName -> fileName ++ " doesn't exist"
Expand Down
17 changes: 12 additions & 5 deletions Cabal/src/Distribution/Simple/Test/ExeV10.hs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ runTest pkg_descr lbi clbi flags suite = do
dataDirPath = pwd </> PD.dataDir pkg_descr
tixFile = pwd </> tixFilePath distPref way (testName')
pkgPathEnv =
(pkgPathEnvVar pkg_descr "datadir", dataDirPath)
(pkgPathEnvVar pkg_descr "datadir", dataDirPath)
: existingEnv
shellEnv = [("HPCTIXFILE", tixFile) | isCoverageEnabled] ++ pkgPathEnv

Expand Down Expand Up @@ -169,10 +169,17 @@ runTest pkg_descr lbi clbi flags suite = do
-- Write summary notice to terminal indicating end of test suite
notice verbosity $ summarizeSuiteFinish suiteLog

when isCoverageEnabled $
if null $ testCoverageDistPrefs flags
then dieWithException verbosity TestCoverageSupport
else markupPackage verbosity flags lbi distPref pkg_descr [suite]
when isCoverageEnabled $ do

-- Until #9493 is fixed, we expect cabal-install to pass one dist dir per
-- library and there being at least one library in the package with the
-- testsuite. When it is fixed, we can remove this predicate and allow a
-- testsuite without a library to cover libraries in other packages of the
-- same project
when (null $ PD.allLibraries pkg_descr) $
dieWithException verbosity TestCoverageSupport

markupPackage verbosity flags lbi distPref pkg_descr [suite]

return suiteLog
where
Expand Down
15 changes: 11 additions & 4 deletions Cabal/src/Distribution/Simple/Test/LibV09.hs
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,17 @@ runTest pkg_descr lbi clbi flags suite = do
-- Write summary notice to terminal indicating end of test suite
notice verbosity $ summarizeSuiteFinish suiteLog

when isCoverageEnabled $
if null $ testCoverageDistPrefs flags
then dieWithException verbosity TestCoverageSupportLibV09
else markupPackage verbosity flags lbi distPref pkg_descr [suite]
when isCoverageEnabled $ do

-- Until #9493 is fixed, we expect cabal-install to pass one dist dir per
-- library and there being at least one library in the package with the
-- testsuite. When it is fixed, we can remove this predicate and allow a
-- testsuite without a library to cover libraries in other packages of the
-- same project
when (null $ PD.allLibraries pkg_descr) $
dieWithException verbosity TestCoverageSupport

markupPackage verbosity flags lbi distPref pkg_descr [suite]

return suiteLog
where
Expand Down
24 changes: 14 additions & 10 deletions cabal-install/src/Distribution/Client/ProjectPlanning.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4312,28 +4312,32 @@ setupHsTestFlags plan (ElaboratedConfiguredPackage{..}) sharedConfig verbosity d

-- The list of non-pre-existing libraries without module holes, i.e. the
-- main library and sub-libraries components of all the local packages in
-- the project that do not require instantiations or are instantiations
-- TODO: This currently also includes the testsuite's prefix
-- the project that do not require instantiations or are instantiations,
-- and the testsuite component.
--
-- TODO: I think that if the packages it depends on are still uninstalled,
-- this seemingly includes the packages that are not local to the project?!
-- Weird, because we filter on localToProject!
-- Try it on cabal-install: cabal test --enable-coverage cabal-install
librariesToCover =
mapMaybe
( \case
InstallPlan.Installed elab@ElaboratedConfiguredPackage{elabModuleShape = modShape}
| elabLocalToProject
, not (isIndefiniteOrInstantiation modShape) ->
Just elab
InstallPlan.Configured elab@ElaboratedConfiguredPackage{elabModuleShape = modShape}
| elabLocalToProject
, not (isIndefiniteOrInstantiation modShape) ->
Just elab
InstallPlan.Installed elab
| shouldCoverPkg elab -> Just elab
InstallPlan.Configured elab
| shouldCoverPkg elab -> Just elab
_ -> Nothing
)
$ Graph.toList
$ InstallPlan.toGraph plan

shouldCoverPkg ElaboratedConfiguredPackage{elabModuleShape = modShape, elabPkgSourceId = pkgId}
= elabLocalToProject
&& not (isIndefiniteOrInstantiation modShape)
-- TODO(#9493): We can only cover libraries in the same package
-- as the testsuite
&& pkgId == elabPkgSourceId

isIndefiniteOrInstantiation :: ModuleShape -> Bool
isIndefiniteOrInstantiation = not . Set.null . modShapeRequires

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import Test.Cabal.Prelude
main = cabalTest $ do
cabal' "v2-run" ["pkg-abc:program"] >>= assertOutputContains "pkg-def:publib"

-- # #8609
cabal' "v2-test" ["--enable-coverage", "all"]
-- #8609
expectBroken 8609 $
cabal' "v2-test" ["--enable-coverage", "all"]

return ()
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ import Test.Cabal.Prelude

main = cabalTest $ do
cabal "v2-test" []
cabal "v2-test" ["--enable-coverage"]

0 comments on commit de274f2

Please sign in to comment.