Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Coverage for failing tests #58

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 27 additions & 5 deletions src/LocalCoverage.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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).

"""

briederer marked this conversation as resolved.
Show resolved Hide resolved
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
Expand Down
6 changes: 6 additions & 0 deletions test/DummyPackage/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
49 changes: 31 additions & 18 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -40,14 +61,6 @@ function test_coverage(pkg;
@test startswith(doctype, "<!DOCTYPE coverage")
end

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))

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why was this removed?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was not removed. It was moved up to line 42 and beyond.
The reason is, that for the new test case of a failing test in the dummy package no coverage is returned, but instead throws an error. Therefore all the tests using cov cannot be processed, after the test has thrown.

So there is no change in the tests for the old ones, but an adaption for the test of the new feature.

if !isnothing(Sys.which("genhtml"))
mktempdir() do dir
html_coverage(pkg, dir = dir, css = css)
Expand All @@ -59,10 +72,6 @@ function test_coverage(pkg;

@test isfile(lcovtrace)
rm(covdir, recursive = true)

@info "Printing coverage information for visual debugging"
show(stdout, cov)
show(IOContext(stdout, :print_gaps => true), cov)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why was this removed?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as before.

end

@testset verbose = true "Testing coverage with" begin
Expand Down Expand Up @@ -93,6 +102,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"], should_throw = true)
end
end

@test LocalCoverage.find_gaps([nothing, 0, 0, 0, 2, 3, 0, nothing, 0, 3, 0, 6, 2]) ==
Expand Down
Loading