Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
trixi-framework
GitHub Repository: trixi-framework/Trixi.jl
Path: blob/main/test/coverage/coverage.jl
2055 views
1
# Inspired by
2
# - https://gitlab.com/tkpapp/GitlabJuliaDemo.jl by Tamas K. Papp
3
# - https://github.com/tpapp/LocalCoverage.jl by Tamas K. Papp
4
5
using Coverage
6
7
const report_dir = "coverage_report"
8
const lcov_info_file = "lcov.info"
9
10
# Change path to root directory
11
cd(joinpath(@__DIR__, "..", "..")) do
12
# Process coverage files
13
processed = process_folder("src")
14
15
# Uncomment the following line once Codecov support is enabled
16
# Codecov.submit_local(processed)
17
18
# Calculate coverage
19
covered_lines, total_lines = get_summary(processed)
20
percentage = covered_lines / total_lines * 100
21
22
# Print coverage in a format that can be easily parsed
23
println("($(percentage)%) covered")
24
25
# Try to generate a coverage report
26
isdir(report_dir) || mkdir(report_dir)
27
tracefile = joinpath(report_dir, lcov_info_file)
28
Coverage.LCOV.writefile(tracefile, processed)
29
branch = strip(read(`git rev-parse --abbrev-ref HEAD`, String))
30
commit = strip(read(`git rev-parse --short HEAD`, String))
31
title = "commit $(commit) on branch $(branch)"
32
run(`genhtml -t $(title) -o $(report_dir) $(tracefile)`)
33
34
# Clean up .cov files
35
clean_folder("src")
36
end
37
38