Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
IanButterworth committed Nov 14, 2023
1 parent d09d782 commit cd34380
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 0 deletions.
42 changes: 42 additions & 0 deletions test/loading.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1331,3 +1331,45 @@ end
@test filesize(cache_path) != cache_size
end
end

@testset "code coverage disabled during precompilation" begin
cov_test_dir = joinpath(@__DIR__, "project", "deps", "CovTest.jl")
function rm_cov_files()
for cov_file in filter(endswith(".cov"), readdir(joinpath(cov_test_dir, "src"), join=true))
rm(cov_file)
end
@test !cov_exists()
end
cov_exists() = !isempty(filter(endswith(".cov"), readdir(joinpath(cov_test_dir, "src"))))

mktempdir() do depot
rm_cov_files() # clear out any coverage files first
@test !cov_exists()

cd(cov_test_dir) do
# In our depot, precompile CovTest.jl with coverage on
@test success(addenv(
`$(Base.julia_cmd()) --startup-file=no --code-coverage=@ --project -e 'using CovTest; exit(0)'`,
"JULIA_DEPOT_PATH" => depot,
))
@test !cov_exists()
rm_cov_files()

# same again but call foo(), which is in the pkgimage, and should generate coverage
@test success(addenv(
`$(Base.julia_cmd()) --startup-file=no --code-coverage=@ --project -e 'using CovTest; foo(); exit(0)'`,
"JULIA_DEPOT_PATH" => depot,
))
@test cov_exists()
rm_cov_files()

# same again but call bar(), which is NOT in the pkgimage, and should generate coverage
@test success(addenv(
`$(Base.julia_cmd()) --startup-file=no --code-coverage=@ --project -e 'using CovTest; bar(); exit(0)'`,
"JULIA_DEPOT_PATH" => depot,
))
@test cov_exists()
rm_cov_files()
end
end
end
3 changes: 3 additions & 0 deletions test/project/deps/CovTest.jl/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
name = "CovTest"
uuid = "f1f4390d-b815-473a-b5dd-5af6e1d717cb"
version = "0.1.0"
26 changes: 26 additions & 0 deletions test/project/deps/CovTest.jl/src/CovTest.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# This file is a part of Julia. License is MIT: https://julialang.org/license

module CovTest

function foo()
x = 1
y = 2
z = x * y
return z
end

function bar()
x = 1
y = 2
z = x * y
return z
end

if Base.generating_output()
# precompile foo but not bar
foo()
end

export foo, bar

end #module

0 comments on commit cd34380

Please sign in to comment.