Skip to content

Commit c4effc3

Browse files
authored
Add context to errorshow except_str tests (#56199)
With this, the error message in https://buildkite.com/julialang/julia-master/builds/41054#019294ca-e2c5-41f2-a897-e2959715f154 would become ```julia Error in testset errorshow: Test Failed at /home/jishnu/juliaPR/usr/share/julia/test/errorshow.jl:226 Expression: typeof(err) === $(Expr(:escape, :MethodError)) Evaluated: StackOverflowError === MethodError Context: expr = :(+()) ``` Having the failing expression displayed makes it easier to locate the source of the error.
1 parent 727a57e commit c4effc3

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

test/errorshow.jl

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,14 +215,17 @@ Base.show_method_candidates(buf, try bad_vararg_decl("hello", 3) catch e e end)
215215
@test occursin("bad_vararg_decl(!Matched::$Int, ::Any...)", String(take!(buf)))
216216

217217
macro except_str(expr, err_type)
218+
source_info = __source__
218219
return quote
219220
let err = nothing
220221
try
221222
$(esc(expr))
222223
catch err
223224
end
224225
err === nothing && error("expected failure, but no exception thrown")
225-
@test typeof(err) === $(esc(err_type))
226+
@testset let expr=$(repr(expr))
227+
$(Expr(:macrocall, Symbol("@test"), source_info, :(typeof(err) === $(esc(err_type)))))
228+
end
226229
buf = IOBuffer()
227230
showerror(buf, err)
228231
String(take!(buf))
@@ -231,6 +234,7 @@ macro except_str(expr, err_type)
231234
end
232235

233236
macro except_strbt(expr, err_type)
237+
source_info = __source__
234238
errmsg = "expected failure, but no exception thrown for $expr"
235239
return quote
236240
let err = nothing
@@ -239,7 +243,9 @@ macro except_strbt(expr, err_type)
239243
catch err
240244
end
241245
err === nothing && error($errmsg)
242-
@test typeof(err) === $(esc(err_type))
246+
@testset let expr=$(repr(expr))
247+
$(Expr(:macrocall, Symbol("@test"), source_info, :(typeof(err) === $(esc(err_type)))))
248+
end
243249
buf = IOBuffer()
244250
showerror(buf, err, catch_backtrace())
245251
String(take!(buf))
@@ -248,6 +254,7 @@ macro except_strbt(expr, err_type)
248254
end
249255

250256
macro except_stackframe(expr, err_type)
257+
source_info = __source__
251258
return quote
252259
let err = nothing
253260
local st
@@ -257,7 +264,9 @@ macro except_stackframe(expr, err_type)
257264
st = stacktrace(catch_backtrace())
258265
end
259266
err === nothing && error("expected failure, but no exception thrown")
260-
@test typeof(err) === $(esc(err_type))
267+
@testset let expr=$(repr(expr))
268+
$(Expr(:macrocall, Symbol("@test"), source_info, :(typeof(err) === $(esc(err_type)))))
269+
end
261270
sprint(show, st[1])
262271
end
263272
end

0 commit comments

Comments
 (0)