Skip to content

Commit

Permalink
Add integration test for #4105
Browse files Browse the repository at this point in the history
  • Loading branch information
mihaimaruseac committed Jun 22, 2018
1 parent 013d1c4 commit 0ec3063
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 0 deletions.
19 changes: 19 additions & 0 deletions test/integration/tests/4105-test-coverage-of-internal-lib/Main.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import Control.Monad (unless)
import Data.List (isInfixOf, isPrefixOf)
import StackTest

main :: IO ()
main = do
stack ["clean"]
stack ["build"]
res <- getCoverageLines . snd <$> stackStderr ["test", "--coverage"]
case res of
_:exprs:_ -> unless ("2/2" `isInfixOf` exprs) testFail
_ -> testFail
where
testFail = fail "Stack didn't generate coverage from both libraries"

getCoverageLines :: String -> [String]
getCoverageLines = dropWhile (not . isCoverageHeader) . lines
where
isCoverageHeader = isPrefixOf "Generating coverage report for "
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: files
version: 0.1.0.0
build-type: Simple
cabal-version: >= 2.0

library
exposed-modules: Src
hs-source-dirs: src
build-depends: base
default-language: Haskell2010

library sublib
exposed-modules: B
hs-source-dirs: src-sublib
build-depends: base
default-language: Haskell2010

test-suite test
type: exitcode-stdio-1.0
main-is: Main.hs
hs-source-dirs: test
build-depends: base, files, sublib
default-language: Haskell2010
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module B where

-- | A function of the internal library
funInternal :: Int -> Int
funInternal = pred
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module Src where

-- | A function of the main library
funMainLib :: Int -> Int
funMainLib = succ
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
resolver: lts-11.11
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import Control.Monad (when)

import Src
import B

main = when (funMainLib 41 /= funInternal 43) $ error "test failed"

0 comments on commit 0ec3063

Please sign in to comment.