antoyo
antoyo

Reputation: 11923

Cabal and HPC and Errors when Running Tests with Code Coverage

I use Cabal to run my tests.

Here is how it is configured in the .cabal file:

test-suite test
    type:           exitcode-stdio-1.0
    main-is:        Test.hs
    build-depends:  base >= 4.7 && < 4.8, containers >=0.5 && <0.6, ghc, test-framework >=0.8 && <0.9, QuickCheck >=2.7 && <2.8, HUnit >=1.2 && <1.3, test-framework-hunit, test-framework-quickcheck2
    default-language:    Haskell2010
    ghc-options:    -Wall -fhpc

When I run the test the first time, everything is OK.

However, if I change the tests and run them again, I get the following error:

Hpc failure: module mismatch with .tix/.mix file hash number
(perhaps remove test.tix file?)

So, I need to manually remove the .tix file.

Is there a way to get rid of this problem?

By the way, is there a way to have this .tix file generated in the dist directory instead of at the root directory?

How can I configure my Cabal file to work nicely with HPC (i.e. having the generated HTML files in the dist directory)?

Thanks.

Upvotes: 6

Views: 812

Answers (2)

Yuras
Yuras

Reputation: 13876

To make cabal generate code coverage report, you can enable that when configuring your package:

cabal configure --enable-coverage

Then run tests as usual:

cabal test

Note that you may need --enable-library-coverage with older cabal. Also IIRC hpc integration in cabal was broken for ghc-7.6.

Upvotes: 4

danplubell
danplubell

Reputation: 131

I'm using GHC 7.8.3 and Cabal 1.22.0.0

You can set the file path of the .tix files in a couple of ways.

  1. Set the HPCTIXDIR environment variable. The tix file will be created in the provided directory. The name will be formatted as -.tix If the directory doesn't exist it will be created.

  2. Set the HPCTIXFILE environment variable. The tix file will be created with the file name you provided in the current working directory. You can specify a file path. But, the directory won't be created.

Upvotes: 1

Related Questions