Skip to content

Commit

Permalink
Add support for exclude markers.
Browse files Browse the repository at this point in the history
  • Loading branch information
maleadt committed Jan 21, 2020
1 parent 39b02b0 commit 135a469
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/CoverageTools.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
9 changes: 9 additions & 0 deletions test/exclusions.jl
Original file line number Diff line number Diff line change
@@ -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
13 changes: 13 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 135a469

Please sign in to comment.