Skip to content

Commit 1046736

Browse files
iblislinfredrikekre
authored andcommitted
stdlib/Test: fix display of with atol (#24926)
fix #24919
1 parent 02b4dcc commit 1046736

File tree

2 files changed

+50
-19
lines changed

2 files changed

+50
-19
lines changed

stdlib/Test/src/Test.jl

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,17 @@ function eval_test(evaluated::Expr, quoted::Expr, source::LineNumberNode)
220220
func_sym = quoted_args[1]
221221
if isempty(kwargs)
222222
quoted = Expr(:call, func_sym, args...)
223+
elseif func_sym === :
224+
# in case of `≈(x, y, atol = z)`
225+
# make the display like `Evaluated: x ≈ y (atol=z)`
226+
kws = [Symbol(Expr(:kw, k, v), ",") for (k, v) in kwargs]
227+
kws[end] = Symbol(Expr(:kw, kwargs[end]...))
228+
kws[1] = Symbol("(", kws[1])
229+
kws[end] = Symbol(kws[end], ")")
230+
quoted = Expr(:comparison, args[1], func_sym, args[2], kws...)
231+
if length(quoted.args) & 1 == 0 # hack to fit `show_unquoted`
232+
push!(quoted.args, Symbol())
233+
end
223234
else
224235
kwargs_expr = Expr(:parameters, [Expr(:kw, k, v) for (k, v) in kwargs]...)
225236
quoted = Expr(:call, func_sym, kwargs_expr, args...)
@@ -339,7 +350,7 @@ function get_test_result(ex, source)
339350
Expr(:comparison, $(quoted_terms...)),
340351
$(QuoteNode(source)),
341352
))
342-
elseif isa(ex, Expr) && ex.head == :call && ex.args[1] in (:isequal, :isapprox)
353+
elseif isa(ex, Expr) && ex.head == :call && ex.args[1] in (:isequal, :isapprox, :)
343354
escaped_func = esc(ex.args[1])
344355
quoted_func = QuoteNode(ex.args[1])
345356

stdlib/Test/test/runtests.jl

Lines changed: 38 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -633,22 +633,42 @@ end
633633
end
634634

635635
@testset "file info in test errors" begin
636-
local f = tempname()
637-
638-
write(f,
639-
"""
640-
using Test
641-
@testset begin
642-
@test 1==2
643-
@test_throws UndefVarError 1
644-
@test_broken 1 == 1
645-
end
646-
""")
647-
648-
local msg = read(pipeline(ignorestatus(`$(Base.julia_cmd()) --startup-file=no --color=no $f`), stderr=DevNull), String)
649-
@test contains(msg, "at " * f * ":" * "3")
650-
@test contains(msg, "at " * f * ":" * "4")
651-
@test contains(msg, "at " * f * ":" * "5")
652-
653-
rm(f; force=true)
636+
local f = tempname()
637+
638+
write(f,
639+
"""
640+
using Test
641+
@testset begin
642+
@test 1==2
643+
@test_throws UndefVarError 1
644+
@test_broken 1 == 1
645+
end
646+
""")
647+
648+
local msg = read(pipeline(ignorestatus(`$(Base.julia_cmd()) --startup-file=no --color=no $f`), stderr=DevNull), String)
649+
@test contains(msg, "at " * f * ":" * "3")
650+
@test contains(msg, "at " * f * ":" * "4")
651+
@test contains(msg, "at " * f * ":" * "5")
652+
653+
rm(f; force=true)
654654
end
655+
656+
# issue #24919
657+
@testset "≈ with atol" begin
658+
local cmd = `$(Base.julia_cmd()) --startup-file=no --color=no`
659+
f(src) = read(pipeline(ignorestatus(`$cmd -e $src`), stderr=DevNull), String)
660+
661+
msg = f("""
662+
using Test
663+
x, y = 0.9, 0.1
664+
@test x ≈ y atol=0.01
665+
""")
666+
@test contains(msg, "Evaluated: 0.9 ≈ 0.1 (atol=0.01)")
667+
668+
msg = f("""
669+
using Test
670+
x, y = 0.9, 0.1
671+
@test x ≈ y nans=true atol=0.01
672+
""")
673+
@test contains(msg, "Evaluated: 0.9 ≈ 0.1 (nans=true, atol=0.01)")
674+
end

0 commit comments

Comments
 (0)