3haskell.nix can generate coverage information for your package or
4project using Cabal's inbuilt hpc support.
8To get a sensible coverage report, you need to enable coverage on each
9of the packages of your project:
12pkgs.haskell-nix.project {
13 src = pkgs.haskell-nix.haskellLib.cleanGit {
14 name = "haskell-nix-project";
17 compiler-nix-name = "ghc884";
20 packages.$pkg.components.library.doCoverage = true;
25If you would like to make coverage optional, add an argument to your nix expression:
28{ withCoverage ? false }:
30pkgs.haskell-nix.project {
31 src = pkgs.haskell-nix.haskellLib.cleanGit {
32 name = "haskell-nix-project";
35 compiler-nix-name = "ghc884";
37 modules = pkgs.lib.optional withCoverage [{
38 packages.$pkg.components.library.doCoverage = true;
46nix-build default.nix -A "projectWithCoverage.$pkg.coverageReport"
49This will generate a coverage report for the package you requested.
50All tests that are enabled (configured with `doCheck == true`) are
51included in the coverage report.
53See the [developer coverage docs](../dev/coverage.md#package-reports) for more information.
58nix-build default.nix -A "projectWithCoverage.projectCoverageReport"
61This will generate a coverage report for all the local packages in
64See the [developer coverage docs](../dev/coverage.md#project-wide-reports) for more information.
68By default, the behaviour of the `coverageReport` attribute is to
69generate a coverage report that describes how that package affects the
70coverage of all local packages (including itself) in the project.
72The default behaviour of `projectCoverageReport` is to sum the
73default coverage reports (produced by the above process) of all local
74packages in the project.
76You can modify this behaviour by using the `coverageReport` and
77`projectCoverageReport` functions found in the haskell.nix library:
81 inherit (pkgs.haskell-nix) haskellLib;
83 project = haskellLib.project {
84 src = pkgs.haskell-nix.haskellLib.cleanGit {
85 name = "haskell-nix-project";
88 compiler-nix-name = "ghc884";
91 packages.$pkgA.components.library.doCoverage = true;
92 packages.$pkgB.components.library.doCoverage = true;
96 # Generate a coverage report for $pkgA that only includes the
97 # unit-test check and only shows coverage information for $pkgA, not
99 custom$pkgACoverageReport = haskellLib.coverageReport rec {
100 name = "$pkgA-unit-tests-only"
101 inherit (project.$pkgA.components) library;
102 checks = [project.$pkgA.components.checks.unit-test];
103 # Note that this is the default value of the "mixLibraries"
104 # argument and so this line isn't really necessary.
105 mixLibraries = [project.$pkgA.components.library];
108 custom$pkgBCoverageReport = haskellLib.coverageReport rec {
109 name = "$pkgB-unit-tests-only"
110 inherit (project.$pkgB.components) library;
111 checks = [project.$pkgB.components.checks.unit-test];
112 mixLibraries = [project.$pkgB.components.library];
115 # Generate a project coverage report that only includes the unit
116 # tests of the project, and only shows how each unit test effects
117 # the coverage of it's package, and not other packages in the
119 allUnitTestsProjectReport = haskellLib.projectCoverageReport [custom$pkgACoverageReport custom$pkgBCoverageReport];
121 inherit project custom$pkgACoverageReport custom$pkgBCoverageReport allUnitTestsProjectCoverageReport;
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list