Skip to content

Commit

Permalink
Fix GAP.Packages.test
Browse files Browse the repository at this point in the history
  • Loading branch information
lgoettgens committed Nov 22, 2024
1 parent 5e51614 commit 0338bed
Showing 1 changed file with 27 additions and 19 deletions.
46 changes: 27 additions & 19 deletions src/packages.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0338bed

Please sign in to comment.