From 305e2fb875a41bfff9d35031d6ffba44060932de Mon Sep 17 00:00:00 2001 From: Dilum Aluthge Date: Tue, 6 Sep 2022 12:51:35 -0400 Subject: [PATCH] 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) --- test/testdefs.jl | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/test/testdefs.jl b/test/testdefs.jl index 1d36d8893e199..0f8ef610d02c8 100644 --- a/test/testdefs.jl +++ b/test/testdefs.jl @@ -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