From 135a469e9a5545bf2afd89dc05a63eec219b344b Mon Sep 17 00:00:00 2001 From: Tim Besard Date: Tue, 21 Jan 2020 13:27:50 +0100 Subject: [PATCH 1/2] Add support for exclude markers. --- src/CoverageTools.jl | 20 ++++++++++++++++++++ test/exclusions.jl | 9 +++++++++ test/runtests.jl | 13 +++++++++++++ 3 files changed, 42 insertions(+) create mode 100644 test/exclusions.jl diff --git a/src/CoverageTools.jl b/src/CoverageTools.jl index 35ea28d..e085345 100644 --- a/src/CoverageTools.jl +++ b/src/CoverageTools.jl @@ -201,6 +201,26 @@ module CoverageTools end end end + + # check for excluded lines + let io = IOBuffer(content) + excluded = false + for (l, line) in enumerate(eachline(io)) + # check for start/stop markers + if occursin("COV_EXCL_START", line) + excluded = true + elseif occursin("COV_EXCL_STOP", line) + excluded = false + end + + # also check for line markers + if excluded || occursin("COV_EXCL_LINE", line) + @debug "removing line $l: $line" + coverage[l] = nothing + end + end + end + nothing end diff --git a/test/exclusions.jl b/test/exclusions.jl new file mode 100644 index 0000000..c067b6d --- /dev/null +++ b/test/exclusions.jl @@ -0,0 +1,9 @@ +function main() + println(devnull, 1) + println(devnull, 2) # COV_EXCL_LINE + println(devnull, 3) + # COV_EXCL_START + println(devnull, 4) + # COV_EXCL_STOP + println(devnull, 5) +end diff --git a/test/runtests.jl b/test/runtests.jl index febb75e..9a64cf4 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -151,6 +151,19 @@ end @test isfile(joinpath(datadir_temp, "CoverageTools.jl")) # tear down test data rm(datadir_temp; recursive=true) + + # test exclusion markers + srcname = joinpath("test", "exclusions.jl") + covname = srcname*".cov" + clean_file(srcname) + cmdstr = "include($(repr(srcname))); main()" + run(`$(Base.julia_cmd()) --startup-file=no --code-coverage=user -e $cmdstr`) + r = withenv("DISABLE_AMEND_COVERAGE_FROM_SRC" => "yes") do + process_file(srcname, "test") + end + @test r.coverage == [nothing, 2, 1, 1, nothing, 1, nothing, 1, nothing, nothing] + amend_coverage_from_src!(r.coverage, r.filename) + @test r.coverage == [nothing, 2, nothing, 1, nothing, nothing, nothing, 1, nothing, nothing] end end From 3784ac2c930dca6ad27739e50e99abc77e8bed77 Mon Sep 17 00:00:00 2001 From: Tim Besard Date: Tue, 21 Jan 2020 14:30:40 +0100 Subject: [PATCH 2/2] Fix tests on 1.0 and 1.5. Fixes #34. --- src/CoverageTools.jl | 1 - test/runtests.jl | 23 +++++++++++++++++++---- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/CoverageTools.jl b/src/CoverageTools.jl index e085345..5172bde 100644 --- a/src/CoverageTools.jl +++ b/src/CoverageTools.jl @@ -215,7 +215,6 @@ module CoverageTools # also check for line markers if excluded || occursin("COV_EXCL_LINE", line) - @debug "removing line $l: $line" coverage[l] = nothing end end diff --git a/test/runtests.jl b/test/runtests.jl index 9a64cf4..c7e5e8f 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -117,7 +117,11 @@ end run(`$(Base.julia_cmd()) --startup-file=no --code-coverage=user -e $cmdstr`) r = process_file(srcname, datadir) - target = CoverageTools.CovCount[nothing, 2, nothing, 0, nothing, 0, nothing, nothing, nothing, nothing, 0, nothing, nothing, nothing, nothing, nothing, 0, nothing, nothing, 0, nothing, nothing, nothing, nothing, nothing, nothing, nothing, nothing, nothing] + target = if VERSION >= v"1.5.0-DEV.42" + CoverageTools.CovCount[nothing, 1, nothing, 0, nothing, 0, nothing, nothing, nothing, nothing, 0, nothing, nothing, nothing, nothing, nothing, 0, nothing, nothing, 0, nothing, nothing, nothing, nothing, nothing, nothing, nothing, nothing] + else + CoverageTools.CovCount[nothing, 2, nothing, 0, nothing, 0, nothing, nothing, nothing, nothing, 0, nothing, nothing, nothing, nothing, nothing, 0, nothing, nothing, 0, nothing, nothing, nothing, nothing, nothing, nothing, nothing, nothing, nothing] + end target_disabled = map(x -> (x !== nothing && x > 0) ? x : nothing, target) @test r.coverage == target @@ -161,9 +165,20 @@ end r = withenv("DISABLE_AMEND_COVERAGE_FROM_SRC" => "yes") do process_file(srcname, "test") end - @test r.coverage == [nothing, 2, 1, 1, nothing, 1, nothing, 1, nothing, nothing] - amend_coverage_from_src!(r.coverage, r.filename) - @test r.coverage == [nothing, 2, nothing, 1, nothing, nothing, nothing, 1, nothing, nothing] + # FIXME: coverage information for this function is useless with Julia 1.0 + if VERSION >= v"1.1" + @test r.coverage == if VERSION >= v"1.5.0-DEV.42" + [nothing, 1, 1, 1, nothing, 1, nothing, 1, nothing] + else + [nothing, 2, 1, 1, nothing, 1, nothing, 1, nothing, nothing] + end + amend_coverage_from_src!(r.coverage, r.filename) + @test r.coverage == if VERSION >= v"1.5.0-DEV.42" + [nothing, 1, nothing, 1, nothing, nothing, nothing, 1, nothing] + else + [nothing, 2, nothing, 1, nothing, nothing, nothing, 1, nothing, nothing] + end + end end end