forked from JuliaLang/julia
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request JuliaLang#9678 from JuliaLang/teh/pkg_tests
Fix and test Pkg.test(pkg, coverage=true)
- Loading branch information
Showing
2 changed files
with
45 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 |