From 70883744473c011b252da4fb068fe76f5c574560 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20G=C3=B6ttgens?= Date: Thu, 21 Nov 2024 20:01:56 +0100 Subject: [PATCH] Add `GAP.Packages.test` Co-authored-by: Max Horn --- .github/workflows/CI-distro.yml | 2 +- Project.toml | 2 ++ src/packages.jl | 45 ++++++++++++++++++++++++++++++++- 3 files changed, 47 insertions(+), 2 deletions(-) diff --git a/.github/workflows/CI-distro.yml b/.github/workflows/CI-distro.yml index 7428ae75..589f12ad 100644 --- a/.github/workflows/CI-distro.yml +++ b/.github/workflows/CI-distro.yml @@ -75,4 +75,4 @@ jobs: - name: "Build GAP package" run: julia --color=yes --project=. -e 'using GAP; GAP.Packages.build("${{ matrix.gap-package }}")' - name: "Run GAP package tests" - run: julia --color=yes --project=. -e 'using GAP; GAP.Globals.TestPackage(GAP.Obj("${{ matrix.gap-package }}"))' + run: julia --color=yes --project=. -e 'using GAP; GAP.Packages.test("${{ matrix.gap-package }}")' diff --git a/Project.toml b/Project.toml index 90c330de..c91bdbd6 100644 --- a/Project.toml +++ b/Project.toml @@ -21,6 +21,7 @@ Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" REPL = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb" Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" Scratch = "6c6a2e73-6563-6170-7368-637461726353" +Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [compat] AbstractAlgebra = "0.41.11, 0.42.1, 0.43" @@ -40,4 +41,5 @@ Pkg = "1.6" REPL = "1.6" Random = "1.6" Scratch = "1.1" +Test = "1.6" julia = "1.6" diff --git a/src/packages.jl b/src/packages.jl index 7eaf126e..c08b7bc7 100644 --- a/src/packages.jl +++ b/src/packages.jl @@ -3,7 +3,8 @@ module Packages import Downloads import Pidfile -import ...GAP: Globals, GapObj, replace_global!, RNamObj, sysinfo, Wrappers +import Test: @test +import ...GAP: disable_error_handler, Globals, GapObj, replace_global!, RNamObj, sysinfo, Wrappers const DEFAULT_PKGDIR = Ref{String}() const DOWNLOAD_HELPER = Ref{Downloads.Downloader}() @@ -408,6 +409,48 @@ function build(name::String; quiet::Bool = false, return res end +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) + try + f() + finally + Globals.MakeReadWriteGlobal(name); + Globals.UnbindGlobal(name); + Globals.BindGlobal(name, old_value); + end + end + + error_occurred = false + function fake_QuitGap(code) + global error_occurred + if code != 0 + error_occurred = true + end + 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 + end + end + finally + disable_error_handler[] = false + end + + @test !error_occurred +end + """ locate_package(name::String)