Skip to content

Commit 818ffdd

Browse files
authored
Merge pull request #5355 from brandon-leapyear/fix-coverage
Fix building coverage report with Cabal 3
2 parents bfe72c8 + 650fbaf commit 818ffdd

File tree

7 files changed

+36
-1
lines changed

7 files changed

+36
-1
lines changed

ChangeLog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ Bug fixes:
4040
pvp-bounds. See
4141
[#5289](https://github.com/commercialhaskell/stack/issues/5289)
4242

43+
* Fix `stack test --coverage` when using Cabal 3
44+
4345
## v2.3.1
4446

4547
Release notes:

src/Stack/Coverage.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ findPackageFieldForBuiltPackage pkgDir pkgId internalLibs field = do
434434
extractField path = do
435435
contents <- readFileUtf8 (toFilePath path)
436436
case asum (map (T.stripPrefix (field <> ": ")) (T.lines contents)) of
437-
Just result -> return $ Right result
437+
Just result -> return $ Right $ T.strip result
438438
Nothing -> notFoundErr
439439
cabalVer <- view cabalVersionL
440440
if cabalVer < mkVersion [1, 24]
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import Control.Monad (unless)
2+
import Data.List (isInfixOf)
3+
import StackTest
4+
5+
main :: IO ()
6+
main = do
7+
stack ["setup"]
8+
stackCheckStderr ["test", "--coverage"] $ \out -> do
9+
unless ("The coverage report for foo's test-suite \"foo-test\" is available at" `isInfixOf` out) $
10+
fail "Coverage report didn't build"
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
name: foo
2+
3+
dependencies:
4+
- base
5+
6+
library:
7+
source-dirs: src
8+
9+
tests:
10+
foo-test:
11+
source-dirs: test
12+
main: Main.hs
13+
dependencies:
14+
- foo
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module Lib (foo) where
2+
3+
foo :: Int
4+
foo = 1
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
resolver: lts-15.0
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import Lib
2+
3+
main :: IO ()
4+
main = print foo

0 commit comments

Comments
 (0)