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

Add support for exclude markers. #35

Merged
merged 2 commits into from
Jan 21, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
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