From 6c421908c0ea13cdc98f21aa299b03e3f0b09257 Mon Sep 17 00:00:00 2001 From: Debaditya Pal Date: Fri, 8 Jan 2021 01:57:24 +0530 Subject: [PATCH] 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 Co-authored-by: Simeon Schaub --- stdlib/Test/src/Test.jl | 4 ++++ stdlib/Test/test/runtests.jl | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/stdlib/Test/src/Test.jl b/stdlib/Test/src/Test.jl index c14678903f0aa..ceee6ae727648 100644 --- a/stdlib/Test/src/Test.jl +++ b/stdlib/Test/src/Test.jl @@ -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 diff --git a/stdlib/Test/test/runtests.jl b/stdlib/Test/test/runtests.jl index 140553f134f56..541e8dcc2bf7d 100644 --- a/stdlib/Test/test/runtests.jl +++ b/stdlib/Test/test/runtests.jl @@ -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 @@ -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[]