Skip to content

Commit

Permalink
added automatic keyword assignment support to test macro (#38270)
Browse files Browse the repository at this point in the history
* 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 <simeondavidschaub99@gmail.com>

Co-authored-by: Simeon Schaub <simeondavidschaub99@gmail.com>
  • Loading branch information
DebadityaPal and simeonschaub authored Jan 7, 2021
1 parent 34ab0a9 commit 6c42190
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions stdlib/Test/src/Test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,10 @@ function get_test_result(ex, source)
push!(escaped_kwargs, Expr(:call, :(=>), QuoteNode(a.args[1]), esc(a.args[2])))
elseif isa(a, Expr) && a.head === :...
push!(escaped_kwargs, Expr(:..., esc(a.args[1])))
elseif isa(a, Expr) && a.head === :.
push!(escaped_kwargs, Expr(:call, :(=>), QuoteNode(a.args[2].value), esc(Expr(:., a.args[1], QuoteNode(a.args[2].value)))))
elseif isa(a, Symbol)
push!(escaped_kwargs, Expr(:call, :(=>), QuoteNode(a), esc(a)))
end
end
end
Expand Down
7 changes: 7 additions & 0 deletions stdlib/Test/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ using Distributed: RemoteException
import Logging: Debug, Info, Warn

@testset "@test" begin
atol = 1
a = (; atol=2)
@test true
@test 1 == 1
@test 1 != 2
Expand All @@ -20,11 +22,16 @@ import Logging: Debug, Info, Warn
@test isapprox(1, 1, atol=0.1)
@test isapprox(1, 1; atol=0.1)
@test isapprox(1, 1; [(:atol, 0)]...)
@test isapprox(1, 2; atol)
@test isapprox(1, 3; a.atol)
end
@testset "@test keyword precedence" begin
atol = 2
# post-semicolon keyword, suffix keyword, pre-semicolon keyword
@test isapprox(1, 2, atol=0) atol=1
@test isapprox(1, 3, atol=0; atol=2) atol=1
@test isapprox(1, 2, atol=0; atol)
@test isapprox(1, 3, atol=0; atol) atol=1
end
@testset "@test should only evaluate the arguments once" begin
g = Int[]
Expand Down

0 comments on commit 6c42190

Please sign in to comment.