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

clean up coverage files generated by test #522

Merged
merged 2 commits into from
Mar 7, 2022
Merged
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
71 changes: 49 additions & 22 deletions test/code_coverage/code_coverage.jl
Original file line number Diff line number Diff line change
@@ -1,32 +1,59 @@
# delete any present coverage files
let
function cleanup_coverage_files(pid)
# clean up coverage files for source code
dir, _, files = first(walkdir(normpath(@__DIR__, "..", "..", "src")))
for file in files
reg = Regex(string(".+\\.jl\\.$pid\\.cov"))
if occursin(reg, file)
rm(joinpath(dir, file))
end
end

# clean up coverage files for this file
dir, _, files = first(walkdir(@__DIR__))
for file in files
if occursin(r"coverage_example\.jl\.\d+\.cov", file)
reg = Regex(string("coverage_example\\.jl\\.$pid\\.cov"))
if occursin(reg, file)
rm(joinpath(dir, file))
end
end
end

#using DiffUtils
# using DiffUtils

@testset "code coverage" begin
out = read(`$(Base.julia_cmd()) --startup=no --project=$(dirname(dirname(@__DIR__))) --code-coverage=user
$(joinpath(@__DIR__(), "coverage_example.jl"))`, String)
@test out == "1 2 fizz 4 "

dir, _, files = first(walkdir(@__DIR__))
i = findfirst(contains(r"coverage_example\.jl\.\d+\.cov"), files)
i === nothing && error("no coverage files found in $dir: $files")
cov_file = joinpath(dir, files[i])
cov_data = read(cov_file, String)
expected = read(joinpath(dir, "coverage_example.jl.cov"), String)
if Sys.iswindows()
cov_data = replace(cov_data, "\r\n" => "\n")
expected = replace(cov_data, "\r\n" => "\n")
let
local pid
try
@testset "code coverage" begin
io = IOBuffer()
filepath = normpath(@__DIR__, "coverage_example.jl")
cmd = `$(Base.julia_cmd()) --startup=no --project=$(dirname(dirname(@__DIR__)))
--code-coverage=user $filepath`
p = run(pipeline(cmd; stdout=io); wait=false)
pid = Libc.getpid(p)
wait(p)
out = String(take!(io))
@test out == "1 2 fizz 4 "

dir, _, files = first(walkdir(@__DIR__))
i = findfirst(contains(r"coverage_example\.jl\.\d+\.cov"), files)
i === nothing && error("no coverage files found in $dir: $files")
cov_file = joinpath(dir, files[i])
cov_data = read(cov_file, String)
expected = read(joinpath(dir, "coverage_example.jl.cov"), String)
if Sys.iswindows()
cov_data = replace(cov_data, "\r\n" => "\n")
expected = replace(cov_data, "\r\n" => "\n")
end

# if cov_data != expected
# DiffUtils.diff(cov_data, expected)
# end
@test cov_data == expected
end
finally
if @isdefined(pid)
# clean up generated files
cleanup_coverage_files(pid)
end
end
#if cov_data != expected
# DiffUtils.diff(cov_data, expected)
#end
@test cov_data == expected
end