Skip to content

Commit 305e2fb

Browse files
authored
Test suite: after running a test set, throw an error if Base.DEPOT_PATH, Base.LOAD_PATH, or ENV have been modified and not restored to their original values (#46602)
1 parent cfec173 commit 305e2fb

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

test/testdefs.jl

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,44 @@ function runtests(name, path, isolate=true; seed=nothing)
2121
res_and_time_data = @timed @testset "$name" begin
2222
# Random.seed!(nothing) will fail
2323
seed != nothing && Random.seed!(seed)
24+
25+
original_depot_path = copy(Base.DEPOT_PATH)
26+
original_load_path = copy(Base.LOAD_PATH)
27+
original_env = copy(ENV)
28+
2429
Base.include(m, "$path.jl")
30+
31+
if Base.DEPOT_PATH != original_depot_path
32+
msg = "The `$(name)` test set mutated Base.DEPOT_PATH and did not restore the original values"
33+
@error(
34+
msg,
35+
original_depot_path,
36+
Base.DEPOT_PATH,
37+
testset_name = name,
38+
testset_path = path,
39+
)
40+
error(msg)
41+
end
42+
if Base.LOAD_PATH != original_load_path
43+
msg = "The `$(name)` test set mutated Base.LOAD_PATH and did not restore the original values"
44+
@error(
45+
msg,
46+
original_load_path,
47+
Base.LOAD_PATH,
48+
testset_name = name,
49+
testset_path = path,
50+
)
51+
error(msg)
52+
end
53+
if copy(ENV) != original_env
54+
msg = "The `$(name)` test set mutated ENV and did not restore the original values"
55+
@error(
56+
msg,
57+
testset_name = name,
58+
testset_path = path,
59+
)
60+
error(msg)
61+
end
2562
end
2663
rss = Sys.maxrss()
2764
#res_and_time_data[1] is the testset

0 commit comments

Comments
 (0)