|
| 1 | +# Developer Coverage Overview |
| 2 | + |
| 3 | +## Building |
| 4 | + |
| 5 | +The implementation of coverage starts with the "doCoverage" flag on |
| 6 | +the builder in `comp-builder.nix`. The doCoverage flag enables and |
| 7 | +disables the Cabal coverage flag and copies any generated coverage |
| 8 | +data to "$out/share/hpc". |
| 9 | + |
| 10 | +There also exists a `covered` attribute on each component, it takes |
| 11 | +the existing derivation for that component and modifies it to have |
| 12 | +coverage enabled. |
| 13 | + |
| 14 | +## Mix and tix files |
| 15 | + |
| 16 | +The coverage information for any derivation consists of "mix" and |
| 17 | +"tix" files. |
| 18 | + |
| 19 | +Mix files record static information about a source file and are |
| 20 | +generated at build time. They primarily contain a path to the source |
| 21 | +file and information about expressions and regions of the source file, |
| 22 | +which are later referenced by tix files. |
| 23 | + |
| 24 | +Tix files contain dynamic information about a test run, recording when |
| 25 | +a portion of a source file is touched by a test. These are generated |
| 26 | +when the test is run. |
| 27 | + |
| 28 | +## Coverage reports |
| 29 | + |
| 30 | +### Package reports |
| 31 | + |
| 32 | +The coverage information generated will look something like this: |
| 33 | + |
| 34 | +```bash |
| 35 | +/nix/store/...-my-project-0.1.0.0-coverage-report/ |
| 36 | +└── share |
| 37 | + └── hpc |
| 38 | + ├── mix |
| 39 | + │ ├── my-library-0.1.0.0 |
| 40 | + │ │ └── my-library-0.1.0.0-ERSaOroBZhe9awsoBkhmcV |
| 41 | + │ │ ├── My.Lib.Config.mix |
| 42 | + │ │ ├── My.Lib.Types.mix |
| 43 | + │ │ └── My.Lib.Util.mix |
| 44 | + │ └── my-test-1 |
| 45 | + │ ├── Spec.mix |
| 46 | + │ └── Main.mix |
| 47 | + ├── tix |
| 48 | + │ ├── my-library-0.1.0.0 |
| 49 | + │ │ └── my-library-0.1.0.0.tix |
| 50 | + │ └── my-test-1 |
| 51 | + │ └── my-test-1.tix |
| 52 | + └── html |
| 53 | + ├── my-library-0.1.0.0 |
| 54 | + │ ├── hpc_index_alt.html |
| 55 | + │ ├── hpc_index_exp.html |
| 56 | + │ ├── hpc_index_fun.html |
| 57 | + │ └── hpc_index.html |
| 58 | + └── my-test-1 |
| 59 | + ├── hpc_index_alt.html |
| 60 | + ├── hpc_index_exp.html |
| 61 | + ├── hpc_index_fun.html |
| 62 | + └── hpc_index.html |
| 63 | +``` |
| 64 | + |
| 65 | +- The mix files are copied verbatim from the builds with coverage. |
| 66 | +- The tix files for each test are copied from the check run verbatim. |
| 67 | +- The tix files for each library are generated by summing the tix |
| 68 | + files for each test, but excluding any test modules. |
| 69 | + - Test modules are determined by inspecting the plan for the project |
| 70 | + (i.e. for the project "my-project" and test-suite "my-test-1", the |
| 71 | + test modules are read from: |
| 72 | + `my-project.project.pkg-set.config.packages.my-project.components.tests.my-test-1.modules`) |
| 73 | +- The hpc reports for each component are generated from their |
| 74 | + respective tix files. |
| 75 | + - `html/my-library-0.1.0.0/hpc_index.html` contains coverage |
| 76 | + information for the library, excluding any test modules. |
| 77 | + - `html/my-test-1/hpc_index.html` contains the coverage information |
| 78 | + that the test contributes to the library, excluding any test modules. |
| 79 | + - The library might have 100% coverage, 50% generated by test-1 |
| 80 | + and 50% generated by test-2. The HTML reports for each test will |
| 81 | + only show 50% coverage, but the library will show 100% coverage. |
| 82 | + |
| 83 | +### Project-wide reports |
| 84 | + |
| 85 | +The coverage information for an entire project will look something |
| 86 | +like this: |
| 87 | + |
| 88 | +```bash |
| 89 | +/nix/store/...-coverage-report |
| 90 | +└── share |
| 91 | + └── hpc |
| 92 | + ├── mix |
| 93 | + │ ├── my-library-0.1.0.0 |
| 94 | + │ │ └── my-library-0.1.0.0-ERSaOroBZhe9awsoBkhmcV |
| 95 | + │ │ ├── My.Lib.Config.mix |
| 96 | + │ │ ├── My.Lib.Types.mix |
| 97 | + │ │ └── My.Lib.Util.mix |
| 98 | + │ ├── my-test-1 |
| 99 | + │ │ ├── Spec.mix |
| 100 | + │ │ └── Main.mix |
| 101 | + │ ├── other-library-0.1.0.0 |
| 102 | + │ │ └── other-library-0.1.0.0-48EVZBwW9Kj29VTaRMhBDf |
| 103 | + │ │ ├── Other.Lib.A.mix |
| 104 | + │ │ └── Other.Lib.B.mix |
| 105 | + │ └── other-test-1 |
| 106 | + │ ├── Spec.mix |
| 107 | + │ └── Main.mix |
| 108 | + ├── tix |
| 109 | + │ ├── all |
| 110 | + │ │ └── all.tix |
| 111 | + │ ├── my-library-0.1.0.0 |
| 112 | + │ │ └── my-library-0.1.0.0.tix |
| 113 | + │ ├── my-test-1 |
| 114 | + │ │ └── my-test-1.tix |
| 115 | + │ ├── other-library-0.1.0.0 |
| 116 | + │ │ └── other-library-0.1.0.0.tix |
| 117 | + │ └── other-test-1 |
| 118 | + │ └── other-test-1.tix |
| 119 | + └── html |
| 120 | + ├── my-library-0.1.0.0 |
| 121 | + │ ├── my-library-0.1.0.0-ERSaOroBZhe9awsoBkhmcV |
| 122 | + │ │ ├── My.Lib.Config.hs.html |
| 123 | + │ │ ├── My.Lib.Types.hs.html |
| 124 | + │ │ └── My.Lib.Util.hs.html |
| 125 | + │ ├── hpc_index_alt.html |
| 126 | + │ ├── hpc_index_exp.html |
| 127 | + │ ├── hpc_index_fun.html |
| 128 | + │ └── hpc_index.html |
| 129 | + ├── my-test-1 |
| 130 | + │ ├── my-library-0.1.0.0-ERSaOroBZhe9awsoBkhmcV |
| 131 | + │ │ ├── My.Lib.Config.hs.html |
| 132 | + │ │ ├── My.Lib.Types.hs.html |
| 133 | + │ │ └── My.Lib.Util.hs.html |
| 134 | + │ ├── hpc_index_alt.html |
| 135 | + │ ├── hpc_index_exp.html |
| 136 | + │ ├── hpc_index_fun.html |
| 137 | + │ └── hpc_index.html |
| 138 | + ├── other-libray-0.1.0.0 |
| 139 | + │ ├── other-library-0.1.0.0-48EVZBwW9Kj29VTaRMhBDf |
| 140 | + │ │ ├── Other.Lib.A.hs.html |
| 141 | + │ │ └── Other.Lib.B.hs.html |
| 142 | + │ ├── hpc_index_alt.html |
| 143 | + │ ├── hpc_index_exp.html |
| 144 | + │ ├── hpc_index_fun.html |
| 145 | + │ └── hpc_index.html |
| 146 | + ├── other-test-1 |
| 147 | + │ ├── other-library-0.1.0.0-48EVZBwW9Kj29VTaRMhBDf |
| 148 | + │ │ ├── Other.Lib.A.hs.html |
| 149 | + │ │ └── Other.Lib.B.hs.html |
| 150 | + │ ├── hpc_index_alt.html |
| 151 | + │ ├── hpc_index_exp.html |
| 152 | + │ ├── hpc_index_fun.html |
| 153 | + │ └── hpc_index.html |
| 154 | + └── index.html |
| 155 | +``` |
| 156 | + |
| 157 | +All of the coverage information is copied verbatim from the coverage |
| 158 | +reports for each of the constituent packages. A few additions are |
| 159 | +made: |
| 160 | + - `tix/all/all.tix` is generated from the union of all the library |
| 161 | + tix files. |
| 162 | + - We use this file when generating coverage reports for |
| 163 | + "coveralls.io". |
| 164 | + - An index page (`html/index.html`) is generated which links to the |
| 165 | + HTML coverage reports of the constituent packages. |
0 commit comments