Skip to content

Commit e22e4fe

Browse files
authored
Rephrase instructions for local usage (#327)
The rewords some of the instructions in the README for local coverage measurement. The major changes & their motivations are: - indicate the purpose of each step before describing the mechanics of the step. This also makes it easier to indicate that one does not necessarily need to measure summary statistics if one's only goal is to find lines lacking coverage. - prioritize `Pkg.test(; coverage=true)` above manual measurement. Most users will want the simpler option. - clarify the role of the `.info` tracefile. This allows users to determine when they need to supply the more complex set of options. By presenting it as a choice it also makes it clearer that you don't need to execute both lines. - acknowledge limitations in the accuracy of Julia's coverage analysis
1 parent c3fe9bc commit e22e4fe

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

README.md

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,25 @@ Most users will want to use [Coverage.jl](https://github.com/JuliaCI/Coverage.jl
2222

2323
### Code coverage
2424

25-
*Step 1:* Navigate to your test directory, and run julia with the `--code-coverage` option:
25+
*Step 1: collect coverage data.* If you are using your default test suite, you can collect coverage data with `Pkg.test("MyPkg"; coverage=true)`. Alternatively, you can collect coverage data manually: in the terminal, navigate to whatever directory you want to start from as the working directory, and run julia with the `--code-coverage` option:
26+
2627
```sh
2728
julia --code-coverage=user
29+
```
30+
or more comprehensively (if you're interested in getting coverage for Julia's standard libraries)
31+
```sh
2832
julia --code-coverage=tracefile-%p.info --code-coverage=user # available in Julia v1.1+
2933
```
34+
You can add other options (e.g., `--project`) as needed. After the REPL starts, execute whatever commands you wish, and then quit Julia. Coverage data are written to files when Julia exits.
3035

31-
*Step 2:* Run your tests (e.g., `include("runtests.jl")`) and quit Julia. (If you use `Pkg.test` to run your tests, set the `coverage` keyword argument to `true`, i.e. `Pkg.test("MyPkg"; coverage=true)`.)
32-
33-
*Step 3:* Navigate to the top-level directory of your package, restart Julia (with no special flags) and analyze your code coverage:
36+
*Step 2: collect summary statistics (optional).* Navigate to the top-level directory of your package, restart Julia (with no special flags) and analyze your code coverage:
3437

3538
```julia
3639
using Coverage
3740
# process '*.cov' files
3841
coverage = process_folder() # defaults to src/; alternatively, supply the folder name as argument
39-
coverage = append!(coverage, process_folder("deps"))
40-
# process '*.info' files
42+
coverage = append!(coverage, process_folder("deps")) # useful if you want to analyze more than just src/
43+
# process '*.info' files, if you collected them
4144
coverage = merge_coverage_counts(coverage, filter!(
4245
let prefixes = (joinpath(pwd(), "src", ""),
4346
joinpath(pwd(), "deps", ""))
@@ -51,10 +54,15 @@ covered_lines, total_lines = get_summary(coverage)
5154
```
5255
The fraction of total coverage is equal to `covered_lines/total_lines`.
5356

54-
To discover which functions lack testing, browse through the `*.cov` files in your `src/`
55-
directory and look for lines starting with `-` or `0` - those lines were never executed.
57+
*Step 3: identify uncovered lines (optional).* To discover which functions lack testing, browse through the `*.cov` files in your `src/`
58+
directory and look for lines starting with `-` or `0`, which mark lines that were never executed.
5659
Numbers larger than 0 are counts of the number of times the respective line was executed.
60+
Note that blank lines, comments, lines with `end` statements, etc. are marked with `-` but do not count against your coverage.
61+
62+
Be aware of a few limitations:
5763

64+
- a line that can take one of two branches gets marked as covered even if only one branch is tested
65+
- currently, code run by Julia's internal interpreter [is not marked as covered](https://github.com/JuliaLang/julia/issues/37059).
5866

5967
### Memory allocation
6068

0 commit comments

Comments
 (0)