From ec24d5deea106f059f9dc8d714734d0de9973277 Mon Sep 17 00:00:00 2001 From: Dilum Aluthge Date: Sun, 17 Sep 2023 22:15:27 -0400 Subject: [PATCH] testdefs: make sure that if a test set changes the active project, they change it back when they're done (#51029) We already check the following for mutation by a test set: 1. DEPOT_PATH 2. LOAD_PATH 3. ENV So this PR just adds the active project to the list of things we check. Changing the active project during a test set can definitely have negative effects on subsequent test sets that are run on the same worker, so we want to make sure if a test set changes the active project, that they change it back when they're done. --- test/testdefs.jl | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/testdefs.jl b/test/testdefs.jl index b6f49396c1a09..a1d4107a502bd 100644 --- a/test/testdefs.jl +++ b/test/testdefs.jl @@ -25,6 +25,7 @@ function runtests(name, path, isolate=true; seed=nothing) original_depot_path = copy(Base.DEPOT_PATH) original_load_path = copy(Base.LOAD_PATH) original_env = copy(ENV) + original_project = Base.active_project() Base.include(m, "$path.jl") @@ -63,6 +64,17 @@ function runtests(name, path, isolate=true; seed=nothing) error(msg) end end + if Base.active_project() != original_project + msg = "The `$(name)` test set changed the active project and did not restore the original value" + @error( + msg, + original_project, + Base.active_project(), + testset_name = name, + testset_path = path, + ) + error(msg) + end end rss = Sys.maxrss() #res_and_time_data[1] is the testset