Skip to content

Commit 253588b

Browse files
committed
Adapt tests to prevent removal of depots with in-use DLLs
1 parent 4390aaf commit 253588b

File tree

8 files changed

+99
-67
lines changed

8 files changed

+99
-67
lines changed

Compiler/test/special_loading.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
# Only run when testing Base compiler
44
if Base.identify_package("Compiler") === nothing
5-
mktempdir() do dir
5+
include(joinpath(Sys.BINDIR, Base.DATAROOTDIR, "julia", "test", "tempdepot.jl"))
6+
mkdepottempdir() do dir
67
withenv("JULIA_DEPOT_PATH" => dir * (Sys.iswindows() ? ";" : ":"), "JULIA_LOAD_PATH" => nothing) do
78
cd(joinpath(@__DIR__, "CompilerLoadingTest")) do
89
@test success(pipeline(`$(Base.julia_cmd()[1]) --startup-file=no --project=. compiler_loading_test.jl`; stdout, stderr))

test/compileall.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
# We make it a separate test target here, so that it can run in parallel
33
# with the rest of the tests.
44

5+
include("tempdepot.jl")
6+
57
function precompile_test_harness(@nospecialize(f))
6-
load_path = mktempdir()
8+
load_path = mkdepottempdir()
79
try
810
pushfirst!(LOAD_PATH, load_path)
911
pushfirst!(DEPOT_PATH, load_path)

test/core.jl

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ const Bottom = Union{}
99
# For curmod_*
1010
include("testenv.jl")
1111

12+
include("tempdepot.jl")
13+
1214
## tests that `const` field declarations
1315

1416
# sanity tests that our built-in types are marked correctly for const fields
@@ -8443,7 +8445,7 @@ end
84438445

84448446
# precompilation
84458447
let load_path = mktempdir()
8446-
depot_path = mktempdir()
8448+
depot_path = mkdepottempdir()
84478449
try
84488450
pushfirst!(LOAD_PATH, load_path)
84498451
pushfirst!(DEPOT_PATH, depot_path)
@@ -8485,11 +8487,6 @@ let load_path = mktempdir()
84858487
filter!(()(load_path), LOAD_PATH)
84868488
filter!(()(depot_path), DEPOT_PATH)
84878489
rm(load_path, recursive=true, force=true)
8488-
try
8489-
rm(depot_path, force=true, recursive=true)
8490-
catch err
8491-
@show err
8492-
end
84938490
end
84948491
end
84958492

test/loading.jl

Lines changed: 19 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ end
3434
@test @nested_LINE_expansion2() == ((@__LINE__() - 5, @__LINE__() - 9), @__LINE__())
3535

3636
original_depot_path = copy(Base.DEPOT_PATH)
37+
include("tempdepot.jl")
3738
include("precompile_utils.jl")
3839

3940
loaded_files = String[]
@@ -226,7 +227,6 @@ end
226227
end
227228
end
228229

229-
230230
## functional testing of package identification, location & loading ##
231231

232232
saved_load_path = copy(LOAD_PATH)
@@ -236,8 +236,9 @@ watcher_counter = Ref(0)
236236
push!(Base.active_project_callbacks, () -> watcher_counter[] += 1)
237237
push!(Base.active_project_callbacks, () -> error("broken"))
238238

239+
const testdefaultdepot = mkdepottempdir()
239240
push!(empty!(LOAD_PATH), joinpath(@__DIR__, "project"))
240-
append!(empty!(DEPOT_PATH), [mktempdir(), joinpath(@__DIR__, "depot")])
241+
append!(empty!(DEPOT_PATH), [testdefaultdepot, joinpath(@__DIR__, "depot")])
241242
@test watcher_counter[] == 0
242243
@test_logs (:error, r"active project callback .* failed") Base.set_active_project(nothing)
243244
@test watcher_counter[] == 1
@@ -461,7 +462,7 @@ function make_env(flat, root, roots, graph, paths, dummies)
461462
)
462463
end
463464

464-
const depots = [mktempdir() for _ = 1:3]
465+
const depots = [mkdepottempdir() for _ = 1:3]
465466
const envs = Dict{String,Any}()
466467

467468
append!(empty!(DEPOT_PATH), depots)
@@ -755,13 +756,6 @@ end
755756
for env in keys(envs)
756757
rm(env, force=true, recursive=true)
757758
end
758-
for depot in depots
759-
try
760-
rm(depot, force=true, recursive=true)
761-
catch err
762-
@show err
763-
end
764-
end
765759

766760
append!(empty!(LOAD_PATH), saved_load_path)
767761
append!(empty!(DEPOT_PATH), saved_depot_path)
@@ -1043,9 +1037,10 @@ end
10431037
_pkgversion == pkgversion(parent) || error("unexpected extension \$ext version: \$_pkgversion")
10441038
end
10451039
"""
1046-
depot_path = mktempdir()
1047-
try
1048-
proj = joinpath(@__DIR__, "project", "Extensions", "HasDepWithExtensions.jl")
1040+
depot_path = mkdepottempdir()
1041+
proj = joinpath(@__DIR__, "project", "Extensions", "HasDepWithExtensions.jl")
1042+
1043+
begin
10491044

10501045
function gen_extension_cmd(compile, distr=false)
10511046
load_distr = distr ? "using Distributed; addprocs(1)" : ""
@@ -1155,7 +1150,7 @@ end
11551150

11561151
# Extension-to-extension dependencies
11571152

1158-
mktempdir() do depot # Parallel pre-compilation
1153+
mkdepottempdir() do depot # Parallel pre-compilation
11591154
code = """
11601155
Base.disable_parallel_precompile = false
11611156
using ExtToExtDependency
@@ -1171,7 +1166,7 @@ end
11711166
)
11721167
@test occursin("Hello ext-to-ext!", String(read(cmd)))
11731168
end
1174-
mktempdir() do depot # Serial pre-compilation
1169+
mkdepottempdir() do depot # Serial pre-compilation
11751170
code = """
11761171
Base.disable_parallel_precompile = true
11771172
using ExtToExtDependency
@@ -1188,7 +1183,7 @@ end
11881183
@test occursin("Hello ext-to-ext!", String(read(cmd)))
11891184
end
11901185

1191-
mktempdir() do depot # Parallel pre-compilation
1186+
mkdepottempdir() do depot # Parallel pre-compilation
11921187
code = """
11931188
Base.disable_parallel_precompile = false
11941189
using CrossPackageExtToExtDependency
@@ -1204,7 +1199,7 @@ end
12041199
)
12051200
@test occursin("Hello x-package ext-to-ext!", String(read(cmd)))
12061201
end
1207-
mktempdir() do depot # Serial pre-compilation
1202+
mkdepottempdir() do depot # Serial pre-compilation
12081203
code = """
12091204
Base.disable_parallel_precompile = true
12101205
using CrossPackageExtToExtDependency
@@ -1224,7 +1219,7 @@ end
12241219
# Extensions for "parent" dependencies
12251220
# (i.e. an `ExtAB` where A depends on / loads B, but B provides the extension)
12261221

1227-
mktempdir() do depot # Parallel pre-compilation
1222+
mkdepottempdir() do depot # Parallel pre-compilation
12281223
code = """
12291224
Base.disable_parallel_precompile = false
12301225
using Parent
@@ -1239,7 +1234,7 @@ end
12391234
)
12401235
@test occursin("Hello parent!", String(read(cmd)))
12411236
end
1242-
mktempdir() do depot # Serial pre-compilation
1237+
mkdepottempdir() do depot # Serial pre-compilation
12431238
code = """
12441239
Base.disable_parallel_precompile = true
12451240
using Parent
@@ -1254,13 +1249,6 @@ end
12541249
)
12551250
@test occursin("Hello parent!", String(read(cmd)))
12561251
end
1257-
1258-
finally
1259-
try
1260-
rm(depot_path, force=true, recursive=true)
1261-
catch err
1262-
@show err
1263-
end
12641252
end
12651253
end
12661254

@@ -1364,7 +1352,7 @@ end
13641352
end
13651353

13661354
@testset "relocatable upgrades #51989" begin
1367-
mktempdir() do depot
1355+
mkdepottempdir() do depot
13681356
# realpath is needed because Pkg is used for one of the precompile paths below, and Pkg calls realpath on the
13691357
# project path so the cache file slug will be different if the tempdir is given as a symlink
13701358
# (which it often is on MacOS) which would break the test.
@@ -1438,7 +1426,7 @@ end
14381426
end
14391427

14401428
@testset "code coverage disabled during precompilation" begin
1441-
mktempdir() do depot
1429+
mkdepottempdir() do depot
14421430
cov_test_dir = joinpath(@__DIR__, "project", "deps", "CovTest.jl")
14431431
cov_cache_dir = joinpath(depot, "compiled", "v$(VERSION.major).$(VERSION.minor)", "CovTest")
14441432
function rm_cov_files()
@@ -1482,7 +1470,7 @@ end
14821470
end
14831471

14841472
@testset "command-line flags" begin
1485-
mktempdir() do depot_path mktempdir() do dir
1473+
mkdepottempdir() do depot_path mktempdir() do dir
14861474
# generate a Parent.jl and Child.jl package, with Parent depending on Child
14871475
open(joinpath(dir, "Child.jl"), "w") do io
14881476
println(io, """
@@ -1565,7 +1553,7 @@ end
15651553
end
15661554

15671555
@testset "including non-existent file throws proper error #52462" begin
1568-
mktempdir() do depot
1556+
mkdepottempdir() do depot
15691557
project_path = joinpath(depot, "project")
15701558
mkpath(project_path)
15711559

@@ -1707,7 +1695,7 @@ end
17071695
end
17081696

17091697
@testset "require_stdlib loading duplication" begin
1710-
depot_path = mktempdir()
1698+
depot_path = mkdepottempdir()
17111699
oldBase64 = nothing
17121700
try
17131701
push!(empty!(DEPOT_PATH), depot_path)
@@ -1731,7 +1719,6 @@ end
17311719
finally
17321720
oldBase64 === nothing || Base.register_root_module(oldBase64)
17331721
copy!(DEPOT_PATH, original_depot_path)
1734-
rm(depot_path, force=true, recursive=true)
17351722
end
17361723
end
17371724

test/precompile.jl

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ using Test, Distributed, Random, Logging, Libdl
44
using REPL # testing the doc lookup function should be outside of the scope of this file, but is currently tested here
55

66
include("precompile_utils.jl")
7+
include("tempdepot.jl")
78

89
Foo_module = :Foo4b3a94a1a081a8cb
910
foo_incl_dep = :foo4b3a94a1a081a8cb
@@ -1524,11 +1525,11 @@ end
15241525
test_workers = addprocs(1)
15251526
push!(test_workers, myid())
15261527
save_cwd = pwd()
1527-
temp_path = mktempdir()
1528+
temp_path = mkdepottempdir()
15281529
try
15291530
cd(temp_path)
15301531
load_path = mktempdir(temp_path)
1531-
load_cache_path = mktempdir(temp_path)
1532+
load_cache_path = mkdepottempdir(temp_path)
15321533

15331534
ModuleA = :Issue19960A
15341535
ModuleB = :Issue19960B
@@ -1576,11 +1577,6 @@ end
15761577
end
15771578
finally
15781579
cd(save_cwd)
1579-
try
1580-
rm(temp_path, recursive=true)
1581-
catch err
1582-
@show err
1583-
end
15841580
pop!(test_workers) # remove myid
15851581
rmprocs(test_workers)
15861582
end

test/precompile_utils.jl

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,18 @@
11
# This file is a part of Julia. License is MIT: https://julialang.org/license
22

3+
include("tempdepot.jl")
4+
35
function precompile_test_harness(@nospecialize(f), testset::String)
46
@testset "$testset" precompile_test_harness(f, true)
57
end
68
function precompile_test_harness(@nospecialize(f), separate::Bool=true)
7-
load_path = mktempdir()
8-
load_cache_path = separate ? mktempdir() : load_path
9+
load_path = mkdepottempdir()
10+
load_cache_path = separate ? mkdepottempdir() : load_path
911
try
1012
pushfirst!(LOAD_PATH, load_path)
1113
pushfirst!(DEPOT_PATH, load_cache_path)
1214
f(load_path)
1315
finally
14-
try
15-
rm(load_path, force=true, recursive=true)
16-
catch err
17-
@show err
18-
end
19-
if separate
20-
try
21-
rm(load_cache_path, force=true, recursive=true)
22-
catch err
23-
@show err
24-
end
25-
end
2616
filter!(()(load_path), LOAD_PATH)
2717
separate && filter!(()(load_cache_path), DEPOT_PATH)
2818
end

test/relocatedepot.jl

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ using Test
44

55

66
include("testenv.jl")
7+
include("tempdepot.jl")
78

89

910
function test_harness(@nospecialize(fn); empty_load_path=true, empty_depot_path=true)
@@ -32,7 +33,7 @@ if !test_relocated_depot
3233

3334
# insert @depot only once for first match
3435
test_harness() do
35-
mktempdir() do dir
36+
mkdepottempdir() do dir
3637
pushfirst!(DEPOT_PATH, dir)
3738
if Sys.iswindows()
3839
# dirs start with a drive letter instead of a path separator
@@ -46,7 +47,7 @@ if !test_relocated_depot
4647

4748
# 55340
4849
empty!(DEPOT_PATH)
49-
mktempdir() do dir
50+
mkdepottempdir() do dir
5051
jlrc = joinpath(dir, "julia-rc2")
5152
jl = joinpath(dir, "julia")
5253
mkdir(jl)
@@ -61,7 +62,7 @@ if !test_relocated_depot
6162

6263
# deal with and without trailing path separators
6364
test_harness() do
64-
mktempdir() do dir
65+
mkdepottempdir() do dir
6566
pushfirst!(DEPOT_PATH, dir)
6667
path = joinpath(dir, "foo")
6768
if isdirpath(DEPOT_PATH[1])
@@ -176,7 +177,7 @@ if !test_relocated_depot
176177
# add them as include_dependency()s to a new pkg Foo, which will be precompiled into depot3.
177178
# After loading the include_dependency()s of Foo should refer to depot1 depot2 each.
178179
test_harness() do
179-
mktempdir() do depot1
180+
mkdepottempdir() do depot1
180181
# precompile Example in depot1
181182
example1_root = joinpath(depot1, "Example1")
182183
mkpath(joinpath(example1_root, "src"))
@@ -196,7 +197,7 @@ if !test_relocated_depot
196197
end
197198
pushfirst!(LOAD_PATH, depot1); pushfirst!(DEPOT_PATH, depot1)
198199
pkg = Base.identify_package("Example1"); Base.require(pkg)
199-
mktempdir() do depot2
200+
mkdepottempdir() do depot2
200201
# precompile Example in depot2
201202
example2_root = joinpath(depot2, "Example2")
202203
mkpath(joinpath(example2_root, "src"))
@@ -216,7 +217,7 @@ if !test_relocated_depot
216217
end
217218
pushfirst!(LOAD_PATH, depot2); pushfirst!(DEPOT_PATH, depot2)
218219
pkg = Base.identify_package("Example2"); Base.require(pkg)
219-
mktempdir() do depot3
220+
mkdepottempdir() do depot3
220221
# precompile Foo in depot3
221222
open(joinpath(depot3, "Module52161.jl"), write=true) do io
222223
println(io, """

0 commit comments

Comments
 (0)