From de274f28fca74dd39575f51105389f984aadb489 Mon Sep 17 00:00:00 2001 From: Rodrigo Mesquita Date: Mon, 4 Dec 2023 19:58:58 +0000 Subject: [PATCH] Filter out components that don't match the package, which is still not 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.. --- Cabal/src/Distribution/Simple/Errors.hs | 4 ++-- Cabal/src/Distribution/Simple/Test/ExeV10.hs | 17 +++++++++---- Cabal/src/Distribution/Simple/Test/LibV09.hs | 15 ++++++++---- .../Distribution/Client/ProjectPlanning.hs | 24 +++++++++++-------- .../Successful/cabal.test.hs | 5 ++-- .../TestSuiteTests/ExeV10/cabal.test.hs | 1 + 6 files changed, 43 insertions(+), 23 deletions(-) diff --git a/Cabal/src/Distribution/Simple/Errors.hs b/Cabal/src/Distribution/Simple/Errors.hs index c7a4d7765dd..dc3e30ab9b6 100644 --- a/Cabal/src/Distribution/Simple/Errors.hs +++ b/Cabal/src/Distribution/Simple/Errors.hs @@ -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" diff --git a/Cabal/src/Distribution/Simple/Test/ExeV10.hs b/Cabal/src/Distribution/Simple/Test/ExeV10.hs index 9e439ae5b6a..22e5b04ee09 100644 --- a/Cabal/src/Distribution/Simple/Test/ExeV10.hs +++ b/Cabal/src/Distribution/Simple/Test/ExeV10.hs @@ -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 @@ -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 diff --git a/Cabal/src/Distribution/Simple/Test/LibV09.hs b/Cabal/src/Distribution/Simple/Test/LibV09.hs index b20a1458eec..043e1aa418f 100644 --- a/Cabal/src/Distribution/Simple/Test/LibV09.hs +++ b/Cabal/src/Distribution/Simple/Test/LibV09.hs @@ -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 diff --git a/cabal-install/src/Distribution/Client/ProjectPlanning.hs b/cabal-install/src/Distribution/Client/ProjectPlanning.hs index cf72a2b3691..ccb1e8f6340 100644 --- a/cabal-install/src/Distribution/Client/ProjectPlanning.hs +++ b/cabal-install/src/Distribution/Client/ProjectPlanning.hs @@ -4312,8 +4312,9 @@ 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! @@ -4321,19 +4322,22 @@ setupHsTestFlags plan (ElaboratedConfiguredPackage{..}) sharedConfig verbosity d 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 diff --git a/cabal-testsuite/PackageTests/MultipleLibraries/Successful/cabal.test.hs b/cabal-testsuite/PackageTests/MultipleLibraries/Successful/cabal.test.hs index a398d140339..9d5fa5cb958 100644 --- a/cabal-testsuite/PackageTests/MultipleLibraries/Successful/cabal.test.hs +++ b/cabal-testsuite/PackageTests/MultipleLibraries/Successful/cabal.test.hs @@ -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 () diff --git a/cabal-testsuite/PackageTests/TestSuiteTests/ExeV10/cabal.test.hs b/cabal-testsuite/PackageTests/TestSuiteTests/ExeV10/cabal.test.hs index 94d4db92de8..065cba9c691 100644 --- a/cabal-testsuite/PackageTests/TestSuiteTests/ExeV10/cabal.test.hs +++ b/cabal-testsuite/PackageTests/TestSuiteTests/ExeV10/cabal.test.hs @@ -2,3 +2,4 @@ import Test.Cabal.Prelude main = cabalTest $ do cabal "v2-test" [] + cabal "v2-test" ["--enable-coverage"]