From 74a626a37be1162a919d54678bff884eb3efb049 Mon Sep 17 00:00:00 2001 From: Bernd Riederer Date: Mon, 16 Sep 2024 13:00:41 +0200 Subject: [PATCH 1/4] add functionality to process failing tests --- src/LocalCoverage.jl | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/src/LocalCoverage.jl b/src/LocalCoverage.jl index f41f5d2..dbb1c51 100644 --- a/src/LocalCoverage.jl +++ b/src/LocalCoverage.jl @@ -233,13 +233,35 @@ function generate_coverage(pkg = nothing; test_args = [""], folder_list = ["src"], file_list = [])::PackageCoverage - if run_test - if isnothing(pkg) - Pkg.test(; coverage = true, test_args = test_args) - else - Pkg.test(pkg; coverage = true, test_args = test_args) + + try + if run_test + if isnothing(pkg) + Pkg.test(; coverage = true, test_args = test_args) + else + Pkg.test(pkg; coverage = true, test_args = test_args) + end end + catch e + coverage = process_coverage(pkg; folder_list, file_list) + println(stdout, coverage) + rethrow(e) end + return process_coverage(pkg; folder_list, file_list) +end + +""" +$(SIGNATURES) + +Process coverage files for a package within folder. + +Called by [`generate_coverage`](@ref). + +""" + +function process_coverage(pkg=nothing; + folder_list=["src"], + file_list=[])::PackageCoverage package_dir = pkgdir(pkg) cd(package_dir) do # initialize empty vector of coverage data From 900202c6f334dd3ba81fd57421fbef66530e561d Mon Sep 17 00:00:00 2001 From: Bernd Riederer Date: Mon, 16 Sep 2024 13:00:53 +0200 Subject: [PATCH 2/4] Add tests for this case --- test/DummyPackage/test/runtests.jl | 6 ++++++ test/runtests.jl | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/test/DummyPackage/test/runtests.jl b/test/DummyPackage/test/runtests.jl index da33367..c45a711 100644 --- a/test/DummyPackage/test/runtests.jl +++ b/test/DummyPackage/test/runtests.jl @@ -9,4 +9,10 @@ end @testset "testset 2" begin @test corge() == "corge" +end + +if "testset 3" ∈ ARGS + @testset "testset 3" begin + @test 1 == 2 + end end \ No newline at end of file diff --git a/test/runtests.jl b/test/runtests.jl index d75f1ae..845bc55 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -93,6 +93,10 @@ end @test_throws TypeError test_coverage("DummyPackage", css=1) test_coverage("DummyPackage", css=joinpath(dirname(@__FILE__), "dummy.css")) end + + @testset "failing tests" begin + test_coverage("DummyPackage"; test_args = ["testset 3"]) + end end @test LocalCoverage.find_gaps([nothing, 0, 0, 0, 2, 3, 0, nothing, 0, 3, 0, 6, 2]) == From f834d0fc9437f2693a2188430f732a0122fd4717 Mon Sep 17 00:00:00 2001 From: Bernd Riederer Date: Mon, 16 Sep 2024 13:22:39 +0200 Subject: [PATCH 3/4] Adapt tests --- test/runtests.jl | 47 ++++++++++++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 19 deletions(-) diff --git a/test/runtests.jl b/test/runtests.jl index 845bc55..f702d79 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -18,18 +18,39 @@ function test_coverage(pkg; test_args = [""], folder_list = ["src"], file_list = [], - css = nothing) + css = nothing, + should_throw = false) @info "Testing coverage for $pkg" test_args folder_list file_list clean_coverage(pkg) @test isdir(LocalCoverage.pkgdir(pkg)) lcovtrace = joinpath(covdir, "lcov.info") @test !isfile(lcovtrace) - cov = generate_coverage(pkg; - run_test = run_test, - test_args = test_args, - folder_list = folder_list, - file_list = file_list) + if should_throw + @test_throws Pkg.Types.PkgError generate_coverage(pkg; + run_test=run_test, + test_args=test_args, + folder_list=folder_list, + file_list=file_list) + else + cov = generate_coverage(pkg; + run_test = run_test, + test_args = test_args, + folder_list = folder_list, + file_list = file_list) + + buffer = IOBuffer() + show(buffer, cov) + table = String(take!(buffer)) + println(table) + @test !isnothing(match(table_header, table)) + @test !isnothing(match(table_line, table)) + @test !isnothing(match(table_footer, table)) + + @info "Printing coverage information for visual debugging" + show(stdout, cov) + show(IOContext(stdout, :print_gaps => true), cov) + end xmltrace = joinpath(covdir,"lcov.xml") write_lcov_to_xml(xmltrace, lcovtrace) @@ -40,14 +61,6 @@ function test_coverage(pkg; @test startswith(doctype, " true), cov) end @testset verbose = true "Testing coverage with" begin @@ -95,7 +104,7 @@ end end @testset "failing tests" begin - test_coverage("DummyPackage"; test_args = ["testset 3"]) + test_coverage("DummyPackage"; test_args = ["testset 3"], should_throw = true) end end From 5c84768ee7b03490b563d87aa2de8a15ab0653ca Mon Sep 17 00:00:00 2001 From: Bernd Riederer <20151553+briederer@users.noreply.github.com> Date: Thu, 19 Sep 2024 15:46:06 +0200 Subject: [PATCH 4/4] Remove empty line Co-authored-by: Tamas K. Papp --- src/LocalCoverage.jl | 1 - 1 file changed, 1 deletion(-) diff --git a/src/LocalCoverage.jl b/src/LocalCoverage.jl index dbb1c51..a9db431 100644 --- a/src/LocalCoverage.jl +++ b/src/LocalCoverage.jl @@ -258,7 +258,6 @@ Process coverage files for a package within folder. Called by [`generate_coverage`](@ref). """ - function process_coverage(pkg=nothing; folder_list=["src"], file_list=[])::PackageCoverage