Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
5 changes: 3 additions & 2 deletions src/ReTestItems.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/macros.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 10 additions & 0 deletions test/macros.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading