Skip to content

HPC: Coverage for multi-package projects #9493

@alt-romes

Description

@alt-romes

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions