@@ -94,8 +94,8 @@ function replace_ts(source, mod, x::Expr, parent)
94
94
name = x. args[1 ]
95
95
if name === Symbol (" @testset" )
96
96
@assert x. args[2 ] isa LineNumberNode
97
- ts, hasbroken = parse_ts (source , mod, Tuple (x. args[3 : end ]), parent)
98
- parent != = nothing && push! (parent. children, ts)
97
+ ts, hasbroken = parse_ts (x . args[ 2 ] , mod, Tuple (x. args[3 : end ]), parent)
98
+ ts != = nothing && parent != = nothing && push! (parent. children, ts)
99
99
ts, false # hasbroken counts only "proper" @test_broken, not recursive ones
100
100
elseif name === Symbol (" @test_broken" )
101
101
x, true
@@ -116,30 +116,38 @@ function replace_ts(source, mod, x::Expr, parent)
116
116
x, false
117
117
else @label default
118
118
body_br = map (z -> replace_ts (source, mod, z, parent), x. args)
119
+ filter! (x -> first (x) != = nothing , body_br)
119
120
Expr (x. head, first .(body_br)... ), any (last .(body_br))
120
121
end
121
122
end
122
123
123
124
replace_ts (source, mod, x, _) = x, false
124
125
125
126
# create a TestsetExpr from @testset's args
126
- function parse_ts (source, mod, args:: Tuple , parent= nothing )
127
+ function parse_ts (source:: LineNumberNode , mod:: Module , args:: Tuple , parent= nothing )
128
+ function tserror (msg)
129
+ @error msg _file= String (source. file) _line= source. line _module= mod
130
+ nothing , false
131
+ end
132
+
127
133
local desc
128
134
options = Options ()
129
135
for arg in args[1 : end - 1 ]
130
136
if arg isa String || Meta. isexpr (arg, :string )
131
137
desc = arg
132
138
elseif Meta. isexpr (arg, :(= ))
133
- arg. args[1 ] in fieldnames (Options) || error (" unsupported @testset option" )
139
+ arg. args[1 ] in fieldnames (Options) ||
140
+ return tserror (" unsupported @testset option" )
134
141
# TODO : make that work with non-literals:
135
142
setfield! (options, arg. args[1 ], arg. args[2 ])
136
143
else
137
- error (" unsupported @testset" )
144
+ return tserror (" unsupported @testset" )
138
145
end
139
146
end
140
147
141
148
body = args[end ]
142
- isa (body, Expr) || error (" Expected begin/end block or for loop as argument to @testset" )
149
+ isa (body, Expr) ||
150
+ return tserror (" expected begin/end block or for loop as argument to @testset" )
143
151
if body. head === :for
144
152
tsbody = body. args[2 ]
145
153
loops = body. args[1 ]
@@ -165,7 +173,7 @@ function parse_ts(source, mod, args::Tuple, parent=nothing)
165
173
desc = " anonym $(randstring (' 0' :' 9' )) "
166
174
end
167
175
else
168
- error ( " Expected begin/end block or for loop as argument to @testset" )
176
+ return tserror ( " expected begin/end block or for loop as argument to @testset" )
169
177
end
170
178
171
179
ts = TestsetExpr (source, mod, desc, options, loops, parent)
@@ -422,6 +430,7 @@ function updatetests!(mod::Module, dup::Bool)
422
430
# the last version; should we delete all of the versions in this case?
423
431
for (tsargs, source) in news
424
432
ts, hasbroken = parse_ts (source, mod, tsargs)
433
+ ts === nothing && continue
425
434
idx = get! (map, ts. desc, length (tests) + 1 )
426
435
if idx == length (tests) + 1
427
436
push! (tests, ts)
0 commit comments