Skip to content

Commit

Permalink
Use tracefiles for coverage
Browse files Browse the repository at this point in the history
This is to avoid `.cov` files cluttering the src directory.
  • Loading branch information
goerz committed Oct 16, 2023
1 parent 756db7b commit 681c503
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 12 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ jobs:
- name: "Instantiate test environment"
run: julia --project=test devrepl.jl
- name: "Run tests"
run: julia --project=test -L devrepl.jl -e 'test()'
shell: julia --color=yes --project=test --code-coverage="user" --depwarn="yes" --check-bounds="yes" {0}
run: |
@show pwd()
include(joinpath(pwd(), "test", "runtests.jl")
- uses: julia-actions/julia-processcoverage@v1
- name: "Summarize coverage"
run: julia --project=test -L devrepl.jl -e 'show_coverage()'
Expand Down
2 changes: 1 addition & 1 deletion test/clean.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function clean(; distclean=false, _exit=true)
end
_push!(CLEAN, joinpath(ROOT, "coverage"))
_push!(CLEAN, joinpath(ROOT, "docs", "build"))
_push!(CLEAN, joinpath(ROOT, "lcov.info"))
append!(CLEAN, _glob(ROOT, ".info"))
###########################################################################

###########################################################################
Expand Down
34 changes: 24 additions & 10 deletions test/init.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,32 @@ end
"""Print out a coverage summary from existing coverage data.
```julia
show_coverage(path="./src"; sort_by=nothing)
show_coverage(path="./src"; root=pwd(), sort_by=nothing)
```
prints a a table showing the tracked files in `path`, the total number of
tracked lines in that file ("Total"), the number of lines with coverage
("Hit"), the number of lines without coverage ("Missed") and the "Coverage" as
a percentage.
The coverage data is collected from `.cov` files in `path`.
The coverage data is collected from `.cov` files in `path` as well as
`tracefile-*.info` files in `root`.
Optionally, the table can be sorted by passing the name of a column to
`sort_by`, e..g. `sort_py=:Missed`.
"""
function show_coverage(path::String=joinpath(pwd(), "src"); kwargs...)
function show_coverage(path::String=joinpath(pwd(), "src"); root=pwd(), kwargs...)
path = abspath(path)
local coverage
logger = Logging.SimpleLogger(stderr, Logging.Error)
Logging.with_logger(logger) do
coverage = Coverage.process_folder(path)
coverage = merge_coverage_counts(
Coverage.process_folder(path), # .cov files in path
Coverage.LCOV.readfolder(root), # tracefile.info
)
end
coverage = filter(coverage) do covitem
startswith(abspath(covitem.filename), path)
end
metrics = eval_coverage_metrics(coverage, path)
show_coverage(metrics; kwargs...)
Expand Down Expand Up @@ -111,8 +119,8 @@ test(
file="test/runtests.jl";
root=pwd(),
project="test",
code_coverage="user",
show_coverage=(code_coverage == "user"),
code_coverage="tracefile-%p.info",
show_coverage=(code_coverage != "none"),
color=<inherit>,
compiled_modules=<inherit>,
startup_file=<inherit>,
Expand Down Expand Up @@ -155,8 +163,8 @@ function test(
file="test/runtests.jl";
root=pwd(),
project="test",
code_coverage="user",
show_coverage=(code_coverage == "user"),
code_coverage="tracefile-%p.info", # or "user", for ".cov" files
show_coverage=(code_coverage != "none"),
color=(Base.have_color === nothing ? "auto" : Base.have_color ? "yes" : "no"),
compiled_modules=(Bool(Base.JLOptions().use_compiled_modules) ? "yes" : "no"),
startup_file=(Base.JLOptions().startupfile == 1 ? "yes" : "no"),
Expand Down Expand Up @@ -189,9 +197,15 @@ function test(
if show_coverage || genhtml
logger = Logging.SimpleLogger(stderr, Logging.Error)
local coverage
package_dir = joinpath(root, "src")
package_dir = abspath(joinpath(root, "src"))
Logging.with_logger(logger) do
coverage = Coverage.process_folder(package_dir)
coverage = merge_coverage_counts(
Coverage.process_folder(package_dir), # .cov files in path
Coverage.LCOV.readfolder(root), # tracefile.info
)
end
coverage = filter(coverage) do covitem
startswith(abspath(covitem.filename), package_dir)
end
if show_coverage
metrics = eval_coverage_metrics(coverage, package_dir)
Expand Down

0 comments on commit 681c503

Please sign in to comment.