Skip to content

Fix and test Pkg.test(pkg, coverage=true) #9678

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

Merged
merged 3 commits into from
Jan 8, 2015
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
2 changes: 1 addition & 1 deletion base/pkg/entry.jl
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,7 @@ function test!(pkg::AbstractString, errs::Vector{AbstractString}, notests::Vecto
cd(dirname(test_path)) do
try
color = Base.have_color? "--color=yes" : "--color=no"
codecov = coverage? "--code-coverage=user --inline=no" : "--code-coverage=none"
codecov = coverage? ["--code-coverage=user", "--inline=no"] : ["--code-coverage=none"]
run(`$JULIA_HOME/julia --check-bounds=yes $codecov $color $test_path`)
info("$pkg tests passed")
catch err
Expand Down
44 changes: 44 additions & 0 deletions test/pkg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,47 @@ temp_pkg_dir() do
@test err.msg == "PackageWithFailingTests had test errors"
end
end

# Testing with code-coverage
@unix_only begin # TODO: delete unix_only when #8911, #9654 are fixed
temp_pkg_dir() do
Pkg.generate("PackageWithCodeCoverage", "MIT", config=Dict("user.name"=>"Julia Test", "user.email"=>"[email protected]"))

src = """
module PackageWithCodeCoverage

export f1, f2, f3, untested

f1(x) = 2x
f2(x) = f1(x)
function f3(x)
3x
end
untested(x) = 7

end"""
linetested = [false, false, false, false, true, true, false, true, false, false]
open(Pkg.dir("PackageWithCodeCoverage", "src", "PackageWithCodeCoverage.jl"), "w") do f
println(f, src)
end
isdir(Pkg.dir("PackageWithCodeCoverage","test")) || mkdir(Pkg.dir("PackageWithCodeCoverage","test"))
open(Pkg.dir("PackageWithCodeCoverage", "test", "runtests.jl"),"w") do f
println(f,"using PackageWithCodeCoverage, Base.Test")
println(f,"@test f2(2) == 4")
println(f,"@test f3(5) == 15")
end

Pkg.test("PackageWithCodeCoverage")
covfile = Pkg.dir("PackageWithCodeCoverage","src","PackageWithCodeCoverage.jl.cov")
@test !isfile(covfile)
Pkg.test("PackageWithCodeCoverage", coverage=true)
@test isfile(covfile)
covstr = readall(covfile)
srclines = split(src, '\n')
covlines = split(covstr, '\n')
for i = 1:length(linetested)
covline = (linetested[i] ? " 1 " : " - ")*srclines[i]
@test covlines[i] == covline
end
end
end