Skip to content

Commit

Permalink
Merge pull request #35 from JuliaCI/tb/exclude_markers
Browse files Browse the repository at this point in the history
Add support for exclude markers.
  • Loading branch information
maleadt authored Jan 21, 2020
2 parents 39b02b0 + 3784ac2 commit f8ef65b
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 1 deletion.
19 changes: 19 additions & 0 deletions src/CoverageTools.jl
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,25 @@ 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)
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
30 changes: 29 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -151,6 +155,30 @@ 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
# 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

Expand Down

0 comments on commit f8ef65b

Please sign in to comment.