From 681c5031ad6a26cc64c2a64f9f11b63d62c40f78 Mon Sep 17 00:00:00 2001 From: Michael Goerz Date: Mon, 16 Oct 2023 15:36:11 -0400 Subject: [PATCH] Use tracefiles for coverage This is to avoid `.cov` files cluttering the src directory. --- .github/workflows/ci.yml | 5 ++++- test/clean.jl | 2 +- test/init.jl | 34 ++++++++++++++++++++++++---------- 3 files changed, 29 insertions(+), 12 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0933962..c1c01c8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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()' diff --git a/test/clean.jl b/test/clean.jl index c7de885..03e7dc0 100644 --- a/test/clean.jl +++ b/test/clean.jl @@ -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")) ########################################################################### ########################################################################### diff --git a/test/init.jl b/test/init.jl index 1dc6b76..3623d6d 100644 --- a/test/init.jl +++ b/test/init.jl @@ -33,7 +33,7 @@ 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 @@ -41,16 +41,24 @@ 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...) @@ -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=, compiled_modules=, startup_file=, @@ -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"), @@ -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)