diff --git a/Project.toml b/Project.toml index 93502e6..64e45be 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "LocalCoverage" uuid = "5f6e1e16-694c-5876-87ef-16b5274f298e" authors = ["Tamas K. Papp "] -version = "0.8.0" +version = "0.8.1" [deps] Coverage = "a2441757-f6aa-5fb2-8edb-039e3f45d037" @@ -23,6 +23,7 @@ Dates = "1.6" DefaultApplication = "1" DocStringExtensions = "0.8, 0.9" EzXML = "1" +FileCmp = "1" LibGit2 = "1.6" OrderedCollections = "1" Pkg = "1.6" @@ -32,6 +33,7 @@ julia = "1.6" [extras] Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" +FileCmp = "343a5541-a696-4ae7-8102-bc61c09e1896" [targets] -test = ["Test"] +test = ["Test","FileCmp"] diff --git a/src/LocalCoverage.jl b/src/LocalCoverage.jl index ba854bb..fcf7f1d 100644 --- a/src/LocalCoverage.jl +++ b/src/LocalCoverage.jl @@ -281,12 +281,13 @@ end """ $(SIGNATURES) -Generate, and optionally open, the HTML coverage summary in a browser for `pkg` -inside `dir`. +Generate, and optionally open, the HTML coverage summary in a browser +for `pkg` inside `dir`. The optional keyword argument `css` can be +used to set the path to a custom CSS file styling the coverage report. See [`generate_coverage`](@ref). """ -function html_coverage(coverage::PackageCoverage; gitroot = ".", open = false, dir = tempdir()) +function html_coverage(coverage::PackageCoverage; gitroot = ".", open = false, dir = tempdir(), css::Union{Nothing,AbstractString}=nothing) cd(coverage.package_dir) do branch = try LibGit2.headname(GitRepo(gitroot)) @@ -298,7 +299,13 @@ function html_coverage(coverage::PackageCoverage; gitroot = ".", open = false, d tracefile = joinpath(COVDIR, LCOVINFO) try - run(`genhtml -t $(title) -o $(dir) $(tracefile)`) + cmd = `genhtml -t $(title) -o $(dir) $(tracefile)` + if !isnothing(css) + css_file = abspath(css) + isfile(css_file) || throw(ArgumentError("Could not find CSS file at $(css_file)")) + cmd = `$(cmd) --css-file $(css_file)` + end + run(cmd) catch e error( "Failed to run genhtml. Check that lcov is installed (see the README).", @@ -318,9 +325,10 @@ function html_coverage(pkg = nothing; dir = tempdir(), test_args = [""], folder_list = ["src"], - file_list = []) + file_list = [], + css = nothing) gen_cov() = generate_coverage(pkg; test_args = test_args, folder_list = folder_list, file_list = file_list) - html_coverage(gen_cov(); gitroot = gitroot, open = open, dir = dir) + html_coverage(gen_cov(); gitroot = gitroot, open = open, dir = dir, css = css) end """ diff --git a/test/dummy.css b/test/dummy.css new file mode 100644 index 0000000..a8cb6c2 --- /dev/null +++ b/test/dummy.css @@ -0,0 +1,4 @@ +body { + color: white; + background-color: black; +} diff --git a/test/runtests.jl b/test/runtests.jl index deec42b..d75f1ae 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,4 +1,6 @@ using LocalCoverage, Test +using FileCmp + import Pkg Pkg.activate("./DummyPackage/") @@ -15,7 +17,8 @@ function test_coverage(pkg; run_test = true, test_args = [""], folder_list = ["src"], - file_list = []) + file_list = [], + css = nothing) @info "Testing coverage for $pkg" test_args folder_list file_list clean_coverage(pkg) @test isdir(LocalCoverage.pkgdir(pkg)) @@ -47,8 +50,10 @@ function test_coverage(pkg; if !isnothing(Sys.which("genhtml")) mktempdir() do dir - html_coverage(pkg, dir = dir) + html_coverage(pkg, dir = dir, css = css) @test isfile(joinpath(dir, "index.html")) + isnothing(css) || + @test filecmp(joinpath(dir, "gcov.css"), css) end end @@ -83,6 +88,11 @@ end folder_list = [joinpath(dirname(@__FILE__), "DummyPackage", "src", "corge")], file_list = [joinpath(dirname(@__FILE__), "DummyPackage", "src", "qux.jl")]) end + + @testset "custom CSS" begin + @test_throws TypeError test_coverage("DummyPackage", css=1) + test_coverage("DummyPackage", css=joinpath(dirname(@__FILE__), "dummy.css")) + end end @test LocalCoverage.find_gaps([nothing, 0, 0, 0, 2, 3, 0, nothing, 0, 3, 0, 6, 2]) ==