Skip to content

Commit 31a665f

Browse files
committed
Merge pull request #9678 from JuliaLang/teh/pkg_tests
Fix and test Pkg.test(pkg, coverage=true)
2 parents 4cb149b + bda6659 commit 31a665f

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

base/pkg/entry.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,7 @@ function test!(pkg::AbstractString, errs::Vector{AbstractString}, notests::Vecto
690690
cd(dirname(test_path)) do
691691
try
692692
color = Base.have_color? "--color=yes" : "--color=no"
693-
codecov = coverage? "--code-coverage=user --inline=no" : "--code-coverage=none"
693+
codecov = coverage? ["--code-coverage=user", "--inline=no"] : ["--code-coverage=none"]
694694
run(`$JULIA_HOME/julia --check-bounds=yes $codecov $color $test_path`)
695695
info("$pkg tests passed")
696696
catch err

test/pkg.jl

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,47 @@ temp_pkg_dir() do
7676
@test err.msg == "PackageWithFailingTests had test errors"
7777
end
7878
end
79+
80+
# Testing with code-coverage
81+
@unix_only begin # TODO: delete unix_only when #8911, #9654 are fixed
82+
temp_pkg_dir() do
83+
Pkg.generate("PackageWithCodeCoverage", "MIT", config=Dict("user.name"=>"Julia Test", "user.email"=>"[email protected]"))
84+
85+
src = """
86+
module PackageWithCodeCoverage
87+
88+
export f1, f2, f3, untested
89+
90+
f1(x) = 2x
91+
f2(x) = f1(x)
92+
function f3(x)
93+
3x
94+
end
95+
untested(x) = 7
96+
97+
end"""
98+
linetested = [false, false, false, false, true, true, false, true, false, false]
99+
open(Pkg.dir("PackageWithCodeCoverage", "src", "PackageWithCodeCoverage.jl"), "w") do f
100+
println(f, src)
101+
end
102+
isdir(Pkg.dir("PackageWithCodeCoverage","test")) || mkdir(Pkg.dir("PackageWithCodeCoverage","test"))
103+
open(Pkg.dir("PackageWithCodeCoverage", "test", "runtests.jl"),"w") do f
104+
println(f,"using PackageWithCodeCoverage, Base.Test")
105+
println(f,"@test f2(2) == 4")
106+
println(f,"@test f3(5) == 15")
107+
end
108+
109+
Pkg.test("PackageWithCodeCoverage")
110+
covfile = Pkg.dir("PackageWithCodeCoverage","src","PackageWithCodeCoverage.jl.cov")
111+
@test !isfile(covfile)
112+
Pkg.test("PackageWithCodeCoverage", coverage=true)
113+
@test isfile(covfile)
114+
covstr = readall(covfile)
115+
srclines = split(src, '\n')
116+
covlines = split(covstr, '\n')
117+
for i = 1:length(linetested)
118+
covline = (linetested[i] ? " 1 " : " - ")*srclines[i]
119+
@test covlines[i] == covline
120+
end
121+
end
122+
end

0 commit comments

Comments
 (0)