From c71cf93c57d20452a205bc55b7865b946b902cd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefanos=20Carlstr=C3=B6m?= Date: Fri, 26 Jul 2024 09:53:27 +0200 Subject: [PATCH 1/5] Support passing custom CSS file to HTML coverage report --- src/LocalCoverage.jl | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/LocalCoverage.jl b/src/LocalCoverage.jl index ba854bb..d980aab 100644 --- a/src/LocalCoverage.jl +++ b/src/LocalCoverage.jl @@ -286,7 +286,7 @@ inside `dir`. 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,String}=nothing) cd(coverage.package_dir) do branch = try LibGit2.headname(GitRepo(gitroot)) @@ -298,7 +298,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).", From 57e98eb67998c99258a2e131e670146c988388dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefanos=20Carlstr=C3=B6m?= Date: Fri, 26 Jul 2024 09:53:50 +0200 Subject: [PATCH 2/5] Bump version --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 93502e6..0a58776 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" From 7c28f2db318c09c98339a6af5e2be0196a5cae69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefanos=20Carlstr=C3=B6m?= Date: Fri, 26 Jul 2024 10:27:32 +0200 Subject: [PATCH 3/5] Added `css` to docstring and the variant method --- src/LocalCoverage.jl | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/LocalCoverage.jl b/src/LocalCoverage.jl index d980aab..8b38022 100644 --- a/src/LocalCoverage.jl +++ b/src/LocalCoverage.jl @@ -281,8 +281,9 @@ 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). """ @@ -324,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 """ From 44eb65d6110185656c7fc0926781f337c778ccd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefanos=20Carlstr=C3=B6m?= Date: Fri, 26 Jul 2024 12:35:03 +0200 Subject: [PATCH 4/5] Suggested edit --- src/LocalCoverage.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/LocalCoverage.jl b/src/LocalCoverage.jl index 8b38022..fcf7f1d 100644 --- a/src/LocalCoverage.jl +++ b/src/LocalCoverage.jl @@ -287,7 +287,7 @@ 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(), css::Union{Nothing,String}=nothing) +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)) From 0f57ce87428879989588ead8106efad6f0f154e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefanos=20Carlstr=C3=B6m?= Date: Fri, 26 Jul 2024 12:35:53 +0200 Subject: [PATCH 5/5] Test custom CSS --- Project.toml | 4 +++- test/dummy.css | 4 ++++ test/runtests.jl | 14 ++++++++++++-- 3 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 test/dummy.css diff --git a/Project.toml b/Project.toml index 0a58776..64e45be 100644 --- a/Project.toml +++ b/Project.toml @@ -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/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]) ==