haskell / haskell/cabal

HPC: Coverage for multi-package projects

Open
#9,493 2 comments 1 reaction 0 assignees View on GitHub
type: enhancement
Dominant language
Haskell
Stars
1.7k
Forks
750
Avg merge
4d 3h
Merged PRs (30d)
28

Description

**Describe the bug**

In #9464, we lifted the restrictions that made cabal unable to support enable multi-component coverage and further unblocked support for coverage of multi-package projects. However, due to a limitation of HPC, we introduced a deliberate exception which aborts `cabal test --enable-coverage` for multi package projects.

Currently, HPC records in `.mix` files the relative path to the source file containing the module corresponding to the .mix file.
However, this path being relative makes the `hpc markup` command invoked from the root of the project (rather than the package) after running the testsuite fail because the source of the module cannot be found using the relative path.

An undesireable "fix" would be to add `--srcdir` for each package in the project to the `markup` invocation, however, that is not a great idea because:
1. `markup` is invoked by Cabal the library, which should not know about the multiple packages in a project
2. if two packages export the same module, there will be conflicts in the HPC invocation

Ideally, HPC would record the full path to a module's source or the source of the module could be recorded in the .mix file.

To fix this ticket, HPC must better handle paths to source directories and then it should suffice to delete the check for multi-packages when --enable-coverage is on (the error thrown is named `MultiPackageCoverageUnsupported`). It may also be useful to grep for this ticket number in the source.

**To Reproduce**

There is a test which is expected to fail in a `.test.hs` file `PackageTests/MultipleLibraries/Successful` which enables coverage for the project.

If this is fixed, the coverage report for that test should be successfully generated.

As an additional real-world example you may also try to run in the root of the cabal project run
```
cabal test --enable-coverage cabal-install
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.