Skip to content

Commit 4f86a43

Browse files
committed
Remove coverage docs from usage. Describe code coverage process in internals
1 parent cb22645 commit 4f86a43

File tree

2 files changed

+37
-61
lines changed

2 files changed

+37
-61
lines changed

docs/_docs/internals/coverage.md

+37
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

-61
This file was deleted.

0 commit comments

Comments
 (0)