diff --git a/Project.toml b/Project.toml index 8f41086..8caac56 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "ReTestItems" uuid = "817f1d60-ba6b-4fd5-9520-3cf149f6a823" -version = "1.35.3" +version = "1.35.4" [deps] Dates = "ade2ca70-3891-5945-98fb-dc099432e06a" diff --git a/src/ReTestItems.jl b/src/ReTestItems.jl index 637a6bc..1622305 100644 --- a/src/ReTestItems.jl +++ b/src/ReTestItems.jl @@ -1055,8 +1055,9 @@ function ensure_setup!(ctx::TestContext, setup::Symbol, setups::Vector{TestSetup isassigned(ts.logstore) && close(ts.logstore[]) ts.logstore[] = open(logpath(ts), "w") mod_expr = :(module $(gensym(ts.name)) end) - # replace the module expr body with our @testsetup code - mod_expr.args[3] = ts.code + # replace the module expr body with our @testsetup code; the body is always the last + # argument, whether or not the parser prepended a syntax version (Julia 1.14+) + mod_expr.args[end] = ts.code newmod = _redirect_logs(logs == :eager ? DEFAULT_STDOUT[] : ts.logstore[]) do with_source_path(() -> Core.eval(Main, mod_expr), ts.file) end diff --git a/src/macros.jl b/src/macros.jl index 3b81924..17817ce 100644 --- a/src/macros.jl +++ b/src/macros.jl @@ -49,7 +49,8 @@ A `@testitem` depends on a `@testsetup` via the `setup` keyword e.g """ macro testsetup(mod) (mod isa Expr && mod.head == :module) || error("`@testsetup` expects a `module ... end` argument") - _, name, code = mod.args + # Julia 1.14 may prepend a syntax version: `Expr(:module, [version,] std_imports, name, body)` + name, code = mod.args[end-1], mod.args[end] name isa Symbol || error("`@testsetup module` expects a valid module name") nm = QuoteNode(name) q = QuoteNode(code) diff --git a/test/macros.jl b/test/macros.jl index fe863a4..ae9ab24 100644 --- a/test/macros.jl +++ b/test/macros.jl @@ -27,6 +27,16 @@ end @test ts.name == :TS1 end +@testset "testsetup macro with syntax-versioned module" begin + # Under a 1.14 syntax version the parser prepends that version to the `module` expression + # a macro receives: `Expr(:module, v"1.14.0", true, :Name, body)` (JuliaLang/julia#60018). + # Build that form directly so it is covered on every Julia version, not only on 1.14+. + mod = Expr(:module, v"1.14.0", true, :TSVersioned, Expr(:block, :(x = 1))) + ts = @eval @testsetup $mod + @test ts.name == :TSVersioned + @test ts.code == Expr(:block, :(x = 1)) +end + @testset "testitem macro basic" begin ti = no_run() do @testitem "TI1" begin