Skip to content

Commit

Permalink
tidy tests avoiding duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
IanButterworth committed Sep 9, 2024
1 parent 56b2f70 commit 1ffad13
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions test/loading.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1034,6 +1034,16 @@ end
end

@testset "Extensions" begin
test_ext = """
function test_ext(parent::Module, ext::Symbol)
_ext = Base.get_extension(parent, ext)
_ext isa Module || error("expected extension \$ext to be loaded")
_pkgdir = pkgdir(_ext)
_pkgdir == pkgdir(parent) != nothing || error("unexpected extension \$ext pkgdir path: \$_pkgdir")
_pkgversion = pkgversion(_ext)
_pkgversion == pkgversion(parent) || error("unexpected extension \$ext version: \$_pkgversion")
end
"""
depot_path = mktempdir()
try
proj = joinpath(@__DIR__, "project", "Extensions", "HasDepWithExtensions.jl")
Expand All @@ -1044,16 +1054,15 @@ end
cmd = """
$load_distr
begin
$ew $test_ext
$ew push!(empty!(DEPOT_PATH), $(repr(depot_path)))
using HasExtensions
$ew using HasExtensions
$ew Base.get_extension(HasExtensions, :Extension) === nothing || error("unexpectedly got an extension")
$ew HasExtensions.ext_loaded && error("ext_loaded set")
using HasDepWithExtensions
$ew using HasDepWithExtensions
$ew Base.get_extension(HasExtensions, :Extension) isa Module || error("expected extension to load")
$ew _pkgdir = pkgdir(Base.get_extension(HasExtensions, :Extension))
$ew _pkgdir == pkgdir(HasExtensions) != nothing || error("unexpected extension pkgdir path")
$ew test_ext(HasExtensions, :Extension)
$ew Base.get_extension(HasExtensions, :Extension).extvar == 1 || error("extvar in Extension not set")
$ew HasExtensions.ext_loaded || error("ext_loaded not set")
$ew HasExtensions.ext_folder_loaded && error("ext_folder_loaded set")
Expand Down Expand Up @@ -1105,19 +1114,14 @@ end

test_ext_proj = """
begin
$test_ext
using HasExtensions
using ExtDep
Base.get_extension(HasExtensions, :Extension) isa Module || error("expected extension to load")
_pkgdir = pkgdir(Base.get_extension(HasExtensions, :Extension))
_pkgdir == pkgdir(HasExtensions) != nothing || error("unexpected extension pkgdir path: $_pkgdir")
test_ext(HasExtensions, :Extension)
using ExtDep2
Base.get_extension(HasExtensions, :ExtensionFolder) isa Module || error("expected extension to load")
_pkgdir = pkgdir(Base.get_extension(HasExtensions, :ExtensionFolder))
_pkgdir == pkgdir(HasExtensions) != nothing || error("unexpected extension pkgdir path: $_pkgdir")
test_ext(HasExtensions, :ExtensionFolder)
using ExtDep3
Base.get_extension(HasExtensions, :ExtensionDep) isa Module || error("expected extension to load")
_pkgdir = pkgdir(Base.get_extension(HasExtensions, :ExtensionDep))
_pkgdir == pkgdir(HasExtensions) != nothing || error("unexpected extension pkgdir path: $_pkgdir")
test_ext(HasExtensions, :ExtensionDep)
end
"""
for compile in (`--compiled-modules=no`, ``)
Expand Down

0 comments on commit 1ffad13

Please sign in to comment.