-
Notifications
You must be signed in to change notification settings - Fork 843
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Test coverage for package whose test suite is in another package. #5713
Comments
Workaround: make a dummy test suite |
@qrilka Any opinions? |
@mpilgrem any opinions? |
I don't have much experience at all with automated testing, so I suspect I cannot help. My starting point is https://docs.haskellstack.org/en/stable/build_command/#target-syntax for targets and https://docs.haskellstack.org/en/stable/coverage/#code-coverage for the The targets documentation explains that The coverage documentation explains that it is 'quite streamlined', and its scope (only the libraries that the test executables link against). So, I wonder if
and that might explain what you experience? |
Yes that explains, but it's no less |
I've added an 'enhancement' label, then. Coming to this cold, it seems to me that |
I just realised it's not as simple as your comment above suggests. |
My little knowledge may be a dangerous thing. I've started again, from the beginning. As you will see below, I don't seem to be experiencing the problem you are experiencing. SetupI am testing this problem with a simple 3-package project named
The resolver: lts-19.5
packages:
- packageA
- packageB
- packageC The source code for the individual packages is based on the simple example template created by module LibA
( someFunc1A
, someFunc2A
) where
someFunc1A :: IO ()
someFunc1A = putStrLn "someFunc1A"
someFunc2A :: IO ()
someFunc2A = putStrLn "someFunc2A" I've changed the code for the tests for package A to (that is, no actions): main :: IO ()
main = pure () I've changed the code for the tests for package B to have two test executables, each of which tests one of import LibB
main :: IO ()
main = do
putStrLn "Testing package B library - someFunc1B"
someFunc1B and the tests:
packageB-test1:
main: Spec1.hs
source-dirs: test
when:
- condition: false
other-modules: Spec2
ghc-options:
- -threaded
- -rtsopts
- -with-rtsopts=-N
dependencies:
- packageB
packageB-test2:
main: Spec2.hs
source-dirs: test
when:
- condition: false
other-modules: Spec1
ghc-options:
- -threaded
- -rtsopts
- -with-rtsopts=-N
dependencies:
- packageB I've changed the code for the tests for package C to test parts of C and A: import LibA
import LibC
main :: IO ()
main = do
putStrLn "Testing package C library - someFunc1C"
someFunc1C
putStrLn "Testing package A library - someFunc2A"
someFunc2A The tests:
packageC-test:
main: Spec.hs
source-dirs: test
ghc-options:
- -threaded
- -rtsopts
- -with-rtsopts=-N
dependencies:
- packageC
- packageA ResultsI think that setup is equivalent to your workaround. I I then comment out the
In the folders of If I change the code for the tests for package C to test all of A, to: import LibA
import LibC
main :: IO ()
main = do
putStrLn "Testing package C library - someFunc1C"
someFunc1C
putStrLn "Testing package A library - someFunc1A"
someFunc1A
putStrLn "Testing package A library - someFunc2A"
someFunc2A again, with no testing in package A, the unified coverage report picks up that C has tested all of A. Perhaps this is explained by different
|
To investigate commercialhaskell/stack#5713
I've dug into this example of yours, great job by the way! |
I think you likely meant
It seems that with only one |
Jup! Looks like that's it :D |
OK. Some relevant code is in if length tixFiles < 2
then logInfo $
(if null tixFiles then "No tix files" else "Only one tix file") <>
" found in " <>
fromString (toFilePath outputDir) <>
", so not generating a unified coverage report."
else do
let report = "unified report"
mreportPath <- generateUnionReport report reportDir tixFiles
forM_ mreportPath (displayReportPath report . pretty) If (for the moment) I disable that by replacing the test with
I will propose a pull request for the simple solution, as an interim solution. |
…nly one *.tix file Currently, `Stack.Coverage.generateHpcUnifiedReport` assumes that a unified coverage report will be redundant if there is only one `*.tix` file. However, that is not necessarily the case. For example, one package may test the library of another package that does not test its own library. As an interim solution, this proposed pull request suggests that a unified report should always be produced if there is one or more `*.tix` files, even if it may be redundant in some circumstances. A more complex solution would be to have a more complex test that determines whether a unified report would be truely redundant if there is only one `*.tix` file.
Fix #5713 Don't assume unified coverage report redundant if only one *.tix file
General summary/comments (optional)
Coverage reports are broken when you use a test suite in one package to test another that doesn't have a test suite.
Steps to reproduce
foobar
with code in a libraryfoobar:lib:foobar
.foobar-gen
with generators and testutils in a libraryfoobar-gen:lib:foobar-gen
foobar-gen:test:foobar-test
to testfoobar
using the generators infoobar-gen
.Run
stack test foobar foobar-gen --coverage
. Find that there is no coverage report for any code infoobar
.Expected
Coverage report for both
foobar
andfoobar-gen
Actual
No coverage report for
foobar
.Stack version
Method of installation
The text was updated successfully, but these errors were encountered: