Re: [Haskell-cafe] The State of Testing?

On Tue, Feb 7, 2012 at 3:23 PM, Austin Seipp
If you're writing a library, you need to compile the library with `-fhpc`, i.e. put it in the library stanza, not the testsuite stanza, and then you can compile the test program using your library - the resulting 'tix' file will contain the library coverage reports. You can link a HPC-built library into an executable not compiled with HPC just fine.
Normally I only compile the library under HPC mode, link it in a test, and distribute the results from that. That way your coverage reports don't include the test module (which may or may not be relevant.)
I normally add a cabal flag called 'hpc' which optionally enables coverage reports for my library, e.g.
flag hpc default: False
library ... ... if flag(hpc) ghc-options: -fhpc
Then when you want coverage reports, just say 'cabal install -fhpc --enable-tests' and the resulting properties executable will spit out the results when run.
First, as author of the test suite code, let me apologize for the terrible documentation. This is absolutely NOT how coverage reports are supposed to work. If you configure with '--enable-tests --enable-library-coverage', Cabal will take care of _everything_ else for you, including excluding the test module from the coverage report. You should not have to put any flag gymnastics in your .cabal file. If this doesn't work for you, please let me know, because it's a bug. Thanks! -- Thomas Tuegel

Thanks Thomas, that new flag is great.
Mike Craig
On Tue, Feb 7, 2012 at 10:03 PM, Thomas Tuegel
On Tue, Feb 7, 2012 at 3:23 PM, Austin Seipp
wrote: If you're writing a library, you need to compile the library with `-fhpc`, i.e. put it in the library stanza, not the testsuite stanza, and then you can compile the test program using your library - the resulting 'tix' file will contain the library coverage reports. You can link a HPC-built library into an executable not compiled with HPC just fine.
Normally I only compile the library under HPC mode, link it in a test, and distribute the results from that. That way your coverage reports don't include the test module (which may or may not be relevant.)
I normally add a cabal flag called 'hpc' which optionally enables coverage reports for my library, e.g.
flag hpc default: False
library ... ... if flag(hpc) ghc-options: -fhpc
Then when you want coverage reports, just say 'cabal install -fhpc --enable-tests' and the resulting properties executable will spit out the results when run.
First, as author of the test suite code, let me apologize for the terrible documentation.
This is absolutely NOT how coverage reports are supposed to work. If you configure with '--enable-tests --enable-library-coverage', Cabal will take care of _everything_ else for you, including excluding the test module from the coverage report. You should not have to put any flag gymnastics in your .cabal file.
If this doesn't work for you, please let me know, because it's a bug.
Thanks!
-- Thomas Tuegel
participants (2)
-
Michael Craig
-
Thomas Tuegel