Skip to content

Commit ecb6dea

Browse files
committed
fix bug with Expr's containing meaningful nothing literals
1 parent ee2719e commit ecb6dea

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

src/ReTest.jl

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,18 @@ end
8888
isfor(ts::TestsetExpr) = ts.loops !== nothing
8989
isfinal(ts::TestsetExpr) = isempty(ts.children)
9090

91+
struct _Invalid
92+
global const invalid = _Invalid.instance
93+
end
94+
9195
# replace unqualified `@testset` by TestsetExpr
9296
function replace_ts(source, mod, x::Expr, parent)
9397
if x.head === :macrocall
9498
name = x.args[1]
9599
if name === Symbol("@testset")
96100
@assert x.args[2] isa LineNumberNode
97101
ts, hasbroken = parse_ts(x.args[2], mod, Tuple(x.args[3:end]), parent)
98-
ts !== nothing && parent !== nothing && push!(parent.children, ts)
102+
ts !== invalid && parent !== nothing && push!(parent.children, ts)
99103
ts, false # hasbroken counts only "proper" @test_broken, not recursive ones
100104
elseif name === Symbol("@test_broken")
101105
x, true
@@ -116,7 +120,7 @@ function replace_ts(source, mod, x::Expr, parent)
116120
x, false
117121
else @label default
118122
body_br = map(z -> replace_ts(source, mod, z, parent), x.args)
119-
filter!(x -> first(x) !== nothing, body_br)
123+
filter!(x -> first(x) !== invalid, body_br)
120124
Expr(x.head, first.(body_br)...), any(last.(body_br))
121125
end
122126
end
@@ -127,7 +131,7 @@ replace_ts(source, mod, x, _) = x, false
127131
function parse_ts(source::LineNumberNode, mod::Module, args::Tuple, parent=nothing)
128132
function tserror(msg)
129133
@error msg _file=String(source.file) _line=source.line _module=mod
130-
nothing, false
134+
invalid, false
131135
end
132136

133137
isempty(args) &&
@@ -433,7 +437,7 @@ function updatetests!(mod::Module, dup::Bool)
433437
# the last version; should we delete all of the versions in this case?
434438
for (tsargs, source) in news
435439
ts, hasbroken = parse_ts(source, mod, tsargs)
436-
ts === nothing && continue
440+
ts === invalid && continue
437441
idx = get!(map, ts.desc, length(tests) + 1)
438442
if idx == length(tests) + 1
439443
push!(tests, ts)

test/runtests.jl

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -826,6 +826,21 @@ end
826826
end
827827
end
828828

829+
module Bugs
830+
using ReTest
831+
@testset "macros with nothing" begin
832+
# in parse_ts(), we were returning `nothing` to mean invalid testset,
833+
# and then filtering out those; but some `Expr`s have meaningful
834+
# `nothing` literals which must *not* be filtered out, e.g.
835+
# the `@int128_str` macro:
836+
@test 24_061_467_864_032_622_473_692_149_727_991 isa Integer
837+
end
838+
end # Bugs
839+
840+
@chapter Bugs begin
841+
check(Bugs, [])
842+
end
843+
829844

830845
module TestsetErrors
831846
using ReTest
@@ -837,7 +852,7 @@ using ReTest
837852
@testset "d" let; end
838853
end
839854

840-
@chapter "TestsetErrors" begin
855+
@chapter TestsetErrors begin
841856
Test.@testset "TestsetErrors" begin
842857
@test_logs (
843858
:error, "expected begin/end block or for loop as argument to @testset") (

0 commit comments

Comments
 (0)