3

I have a program that does slightly different things on different OS/architectures. I'll use this example:

main = do
    output <- readProcess "uname" [] ""
    print $ case output of "Linux\n" -> "tux"; "Darwin\n" -> "apple"

I would like to check the total test coverage of this program on all architectures.

To check coverage on a single architecture, I can run stack test --coverage (natively on a macOS machine and on Linux via a Docker container). It gives me .tix files and HTML reports that correctly show uncovered portions:

macOS run with "tux" shown as never evaluated Linux run with "apple" shown as never evaluated

The runs produce the following files (slightly edited for readability):

$ find .stack-work/install/*/*/*/hpc -type f -not -name \*.html
.../aarch64-osx/hash1/9.10.2/hpc/merge-cover/tests/tests.tix
.../aarch64-osx/hash1/9.10.2/hpc/merge-cover/tests/tests.tix.premunging
.../aarch64-osx/hash1/9.10.2/hpc/combined/all/all.tix
.../aarch64-osx/hash1/9.10.2/hpc/combined/custom/custom.tix
.../x86_64-linux-tinfo6/hash2/9.10.2/hpc/merge-cover/tests/tests.tix
.../x86_64-linux-tinfo6/hash2/9.10.2/hpc/merge-cover/tests/tests.tix.premunging
.../x86_64-linux-tinfo6/hash2/9.10.2/hpc/combined/all/all.tix

How do I produce a report that shows me which parts are never evaluated across both runs?

  • stack hpc report .stack-work/install/*/*/*/hpc/combined/all/all.tix crashes: can not find mypackage-0.1.0.0-hash3-tests/Main (hash matches neither of the directory names above).
  • hpc combine .stack-work/install/*/*/*/hpc/combined/all/all.tix > combined.tix produces a file containing only Tix [].

I need to combine these runs to output a single report to feed into a code coverage service so that I know if a later PR misses some code. How do I do this?

  • I have the project set up with Stack. I don't mind switching to Cabal for this, though.
  • I'm not advertising a particular code coverage service (search for "code coverage service" online) but I don't mind switching to a different one either.
    • The code coverage service I currently use allows me to upload several coverage reports in its own format. However, this format is line-based and the example line above gets a coverage of "1/2" even after the merging, which is incorrect.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.