Skip to content

Commit d1fea44

Browse files
authored
hijack: be more precise with include=:static (#33)
Instead of fetching top-level `@testset` expressions, we inspect newly added testsets in the module via `get_tests(mod).news`. This allows for example to catch testsets defined by meta-programming.
1 parent 8ae57f1 commit d1fea44

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

src/ReTest.jl

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -147,17 +147,29 @@ function replace_ts(source, mod, x::Expr, parent; static_include::Bool)
147147
joinpath(sourcepath, path) :
148148
:(joinpath($sourcepath, $path))
149149
if static_include
150-
length(x.args) == 2 || error("cannot handle include with two arguments: $x")
151-
news = Expr(:block)
152-
insert!(x.args, 2, extract_testsets(news.args))
150+
news = InlineTest.get_tests(mod).news
151+
newslen = length(news)
153152
try
154153
Core.eval(mod, x)
155154
catch
156155
@warn "could not statically include at $source"
157-
deleteat!(x.args, 2)
158156
return x, false
159157
end
160-
replace_ts(source, mod, news, parent; static_include=static_include)
158+
newstmp = news[newslen+1:end]
159+
resize!(news, newslen)
160+
if !isempty(newstmp)
161+
# we unfortunately re-wrap ts expressions in a `@testset ...` expression :(
162+
included_ts = Expr(:block,
163+
(Expr(:macrocall, Symbol("@testset"),
164+
# NOTE: tsi.source has no effect here, it will be
165+
# overwritten by source in the replace_ts call
166+
# below; it's currently not very important
167+
tsi.source, tsi.ts...)
168+
for tsi in newstmp)...)
169+
replace_ts(source, mod, included_ts, parent; static_include=static_include)
170+
else
171+
nothing, false
172+
end
161173
else
162174
x, false
163175
end

test/Hijack/test/include_static_included1.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
@testset "include_static_included1 $i" for i=1:2
1+
# with @eval, we test that include=:static works even for a non-toplevel
2+
# @testset, what matters is that a testset is defined after including the file
3+
@eval @testset "include_static_included1 $i" for i=1:2
24
@test true
35
@testset "nested include_static_included1" begin
46
@test true

0 commit comments

Comments
 (0)