Skip to content

Commit b54e036

Browse files
committed
Restrict HPC reports to just the library the TestSuite came from #634
1 parent 2af3d1b commit b54e036

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/Stack/Build/Execute.hs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -835,6 +835,7 @@ singleTest topts ac ee task =
835835

836836
when needHpc $ forM_ (lastMay testsToRun) $ \testName -> do
837837
let pkgName = packageNameText (packageName package)
838+
pkgId = packageIdentifierText (packageIdentifier package)
838839
when (not $ null $ tail testsToRun) $ $logWarn $ T.concat
839840
[ "Error: The --coverage flag does not yet support multiple test suites in a single cabal file. "
840841
, "All of the tests have been run, however, the HPC report will only supply coverage info for "
@@ -843,7 +844,7 @@ singleTest topts ac ee task =
843844
, testName
844845
, "."
845846
]
846-
generateHpcReport pkgDir pkgName testName
847+
generateHpcReport pkgDir pkgName pkgId testName
847848

848849
bs <- liftIO $
849850
case mlogFile of
@@ -877,15 +878,22 @@ compareTestsComponents comps tests2 =
877878
_ -> Set.empty
878879

879880
-- | Generate the HTML report and show a textual coverage summary.
880-
generateHpcReport :: M env m => Path Abs Dir -> Text -> Text -> m ()
881-
generateHpcReport pkgDir pkgName testName = do
881+
generateHpcReport :: M env m => Path Abs Dir -> Text -> Text -> Text -> m ()
882+
generateHpcReport pkgDir pkgName pkgId testName = do
882883
let whichTest = pkgName <> "'s test-suite \"" <> testName <> "\""
883884
hpcDir <- hpcDirFromDir pkgDir
884885
hpcRelDir <- (</> dotHpc) <$> hpcRelativeDir
885886
pkgDirs <- Map.keys . bcPackages <$> asks getBuildConfig
886887
let args =
888+
-- Use index files from all packages (allows cross-package
889+
-- coverage results).
887890
concatMap (\x -> ["--srcdir", toFilePath x]) pkgDirs ++
888-
["--hpcdir", toFilePath hpcRelDir, "--reset-hpcdirs"]
891+
-- Look for index files in the correct dir (relative to
892+
-- each pkgdir).
893+
["--hpcdir", toFilePath hpcRelDir, "--reset-hpcdirs"
894+
-- Restrict to just the current library code (see #634 -
895+
-- this will likely be customizable in the future)
896+
,"--include", T.unpack (pkgId <> ":")]
889897
tixFile <- parseRelFile (T.unpack testName ++ ".tix")
890898
let tixFileAbs = hpcDir </> tixFile
891899
tixFileExists <- fileExists tixFileAbs

0 commit comments

Comments
 (0)