Skip to content

Commit 3baec6d

Browse files
authored
Merge pull request #15152 from dotty-staging/coverage-docs
Remove coverage docs from usage. Describe code coverage process in internals
2 parents cb22645 + 49e8a6a commit 3baec6d

File tree

3 files changed

+38
-61
lines changed

3 files changed

+38
-61
lines changed

docs/_docs/internals/coverage.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
---
2+
layout: doc-page
3+
title: "Code Coverage for Scala 3"
4+
---
5+
6+
## Instrument code for coverage analysis
7+
8+
[PR#13880](https://github.com/lampepfl/dotty/pull/13880) has implemented code coverage support for Dotty.
9+
In general, code coverage "instruments" the program at compile time: code is inserted to record which statement are called. This does not change the behavior of the program. Also, a list of all the coverable statements is produced.
10+
11+
To use this feature, add the compile option `-coverage-out:DIR`, where `DIR` is the destination of the measurement files.
12+
13+
You can also set `-sourceroot:PATHS_ROOT` to customize how the path of your source files are resolved.
14+
Note that `-sourceroot` also sets the root path of the SemanticDB files.
15+
16+
## Details: how the code is instrumented
17+
18+
When the `-coverage-out` option is set, a new phase `instrumentCoverage` runs, just before `firstTransform`.
19+
For a carefully selected list of tree types, it adds a call to `scala.runtime.Invoker.invoked(statementId, DIR)`.
20+
21+
For instance, this code:
22+
```
23+
def method() =
24+
println(f())
25+
```
26+
27+
with `-coverage-out:target/cov` be turned to
28+
```
29+
def method() =
30+
Invoker.invoked(2, "target/cov")
31+
println({
32+
Invoker.invoked(1, "target/cov")
33+
f()
34+
})
35+
```
36+
37+
At the end of the phase, the list of all the instrumented statements is serialized to the file `DIR/scoverage.coverage`.

docs/_docs/usage/coverage.md

Lines changed: 0 additions & 61 deletions
This file was deleted.

docs/sidebar.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,5 +194,6 @@ subsection:
194194
- page: internals/dotty-internals-1-notes.md
195195
- page: internals/debug-macros.md
196196
- page: internals/gadts.md
197+
- page: internals/coverage.md
197198
- page: release-notes-0.1.2.md
198199
hidden: true

0 commit comments

Comments
 (0)