Skip to content

Commit 6c42190

Browse files
added automatic keyword assignment support to test macro (#38270)
* added automatic keyword assignment support to @test macro * added some tests for test macro using atol keyword * x = a.x syntax support added * Update stdlib/Test/src/Test.jl Co-authored-by: Simeon Schaub <[email protected]> Co-authored-by: Simeon Schaub <[email protected]>
1 parent 34ab0a9 commit 6c42190

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

stdlib/Test/src/Test.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,10 @@ function get_test_result(ex, source)
487487
push!(escaped_kwargs, Expr(:call, :(=>), QuoteNode(a.args[1]), esc(a.args[2])))
488488
elseif isa(a, Expr) && a.head === :...
489489
push!(escaped_kwargs, Expr(:..., esc(a.args[1])))
490+
elseif isa(a, Expr) && a.head === :.
491+
push!(escaped_kwargs, Expr(:call, :(=>), QuoteNode(a.args[2].value), esc(Expr(:., a.args[1], QuoteNode(a.args[2].value)))))
492+
elseif isa(a, Symbol)
493+
push!(escaped_kwargs, Expr(:call, :(=>), QuoteNode(a), esc(a)))
490494
end
491495
end
492496
end

stdlib/Test/test/runtests.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ using Distributed: RemoteException
88
import Logging: Debug, Info, Warn
99

1010
@testset "@test" begin
11+
atol = 1
12+
a = (; atol=2)
1113
@test true
1214
@test 1 == 1
1315
@test 1 != 2
@@ -20,11 +22,16 @@ import Logging: Debug, Info, Warn
2022
@test isapprox(1, 1, atol=0.1)
2123
@test isapprox(1, 1; atol=0.1)
2224
@test isapprox(1, 1; [(:atol, 0)]...)
25+
@test isapprox(1, 2; atol)
26+
@test isapprox(1, 3; a.atol)
2327
end
2428
@testset "@test keyword precedence" begin
29+
atol = 2
2530
# post-semicolon keyword, suffix keyword, pre-semicolon keyword
2631
@test isapprox(1, 2, atol=0) atol=1
2732
@test isapprox(1, 3, atol=0; atol=2) atol=1
33+
@test isapprox(1, 2, atol=0; atol)
34+
@test isapprox(1, 3, atol=0; atol) atol=1
2835
end
2936
@testset "@test should only evaluate the arguments once" begin
3037
g = Int[]

0 commit comments

Comments
 (0)