Skip to content

Commit

Permalink
Test suite: after running a test set, throw an error if `Base.DEPOT_P…
Browse files Browse the repository at this point in the history
…ATH`, `Base.LOAD_PATH`, or `ENV` have been modified and not restored to their original values (JuliaLang#46602)
  • Loading branch information
DilumAluthge committed Sep 6, 2022
1 parent cfec173 commit 305e2fb
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions test/testdefs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,44 @@ function runtests(name, path, isolate=true; seed=nothing)
res_and_time_data = @timed @testset "$name" begin
# Random.seed!(nothing) will fail
seed != nothing && Random.seed!(seed)

original_depot_path = copy(Base.DEPOT_PATH)
original_load_path = copy(Base.LOAD_PATH)
original_env = copy(ENV)

Base.include(m, "$path.jl")

if Base.DEPOT_PATH != original_depot_path
msg = "The `$(name)` test set mutated Base.DEPOT_PATH and did not restore the original values"
@error(
msg,
original_depot_path,
Base.DEPOT_PATH,
testset_name = name,
testset_path = path,
)
error(msg)
end
if Base.LOAD_PATH != original_load_path
msg = "The `$(name)` test set mutated Base.LOAD_PATH and did not restore the original values"
@error(
msg,
original_load_path,
Base.LOAD_PATH,
testset_name = name,
testset_path = path,
)
error(msg)
end
if copy(ENV) != original_env
msg = "The `$(name)` test set mutated ENV and did not restore the original values"
@error(
msg,
testset_name = name,
testset_path = path,
)
error(msg)
end
end
rss = Sys.maxrss()
#res_and_time_data[1] is the testset
Expand Down

0 comments on commit 305e2fb

Please sign in to comment.