diff --git a/src/packages.jl b/src/packages.jl index bf39e2b4..ce17b6e0 100644 --- a/src/packages.jl +++ b/src/packages.jl @@ -423,40 +423,48 @@ to a package extension that depends on the `Test` package in the future. function test(name::String) global disable_error_handler - function with_gap_var(f, n::String, val) - name = GapObj(n) - old_value = Globals.ValueGlobal(name) - Globals.MakeReadWriteGlobal(name) - Globals.UnbindGlobal(name) - Globals.BindGlobal(name, val) + function with_gap_var(f, name::String, val) + gname = GapObj(name) + old_value = Globals.ValueGlobal(gname) + Globals.MakeReadWriteGlobal(gname) + Globals.UnbindGlobal(gname) + Globals.BindGlobal(gname, val) try f() finally - Globals.MakeReadWriteGlobal(name); - Globals.UnbindGlobal(name); - Globals.BindGlobal(name, old_value); + Globals.MakeReadWriteGlobal(gname); + Globals.UnbindGlobal(gname); + Globals.BindGlobal(gname, old_value); end end error_occurred = false + ended_using_QuitGap = false function fake_QuitGap(code) - global error_occurred - if code != 0 - error_occurred = true - end + if code != 0 + error_occurred = true + end + ended_using_QuitGap = true end disable_error_handler[] = true try - with_gap_var("ERROR_OUTPUT", Globals._JULIAINTERFACE_ORIGINAL_ERROR_OUTPUT) do - with_gap_var("QuitGap", fake_QuitGap) do - with_gap_var("FORCE_QUIT_GAP", identity) do - Globals.TestPackage(GapObj(name)) - end + with_gap_var("ERROR_OUTPUT", Globals._JULIAINTERFACE_ORIGINAL_ERROR_OUTPUT) do + with_gap_var("QuitGap", fake_QuitGap) do + with_gap_var("QUIT_GAP", fake_QuitGap) do + with_gap_var("ForceQuitGap", identity) do + with_gap_var("FORCE_QUIT_GAP", identity) do + result = Globals.TestPackage(GapObj(name)) + @test ended_using_QuitGap || result == true + # Due to the hack above, we run into an error in TestPackage that is usually unreachable. + # In the case of a `QuitGap` call, we thus don't check for `result == true`. + end end + end end + end finally - disable_error_handler[] = false + disable_error_handler[] = false end @test !error_occurred