From d910ee78284953c8f08a3cc0e94d23d94a2ee682 Mon Sep 17 00:00:00 2001 From: DebadityaPal Date: Mon, 2 Nov 2020 16:11:01 +0530 Subject: [PATCH 1/4] added automatic keyword assignment support to @test macro --- stdlib/Test/src/Test.jl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/stdlib/Test/src/Test.jl b/stdlib/Test/src/Test.jl index 1bee17d6e9891..91f7094938bce 100644 --- a/stdlib/Test/src/Test.jl +++ b/stdlib/Test/src/Test.jl @@ -486,6 +486,8 @@ 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, Symbol) + push!(escaped_kwargs, Expr(:call, :(=>), QuoteNode(a), esc(a))) end end end From 84f1dfea41e0b739cc4a5b50c22030288fc2b1e8 Mon Sep 17 00:00:00 2001 From: DebadityaPal Date: Mon, 2 Nov 2020 21:30:20 +0530 Subject: [PATCH 2/4] added some tests for test macro using atol keyword --- stdlib/Test/test/runtests.jl | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/stdlib/Test/test/runtests.jl b/stdlib/Test/test/runtests.jl index 3857efe7d0477..26d8b75c98e5a 100644 --- a/stdlib/Test/test/runtests.jl +++ b/stdlib/Test/test/runtests.jl @@ -8,6 +8,7 @@ using Distributed: RemoteException import Logging: Debug, Info, Warn @testset "@test" begin + atol = 1 @test true @test 1 == 1 @test 1 != 2 @@ -20,11 +21,15 @@ 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) 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[] From c4a64f920bbd172726510dfbb180b00bfc7655fd Mon Sep 17 00:00:00 2001 From: DebadityaPal Date: Thu, 7 Jan 2021 21:50:18 +0530 Subject: [PATCH 3/4] x = a.x syntax support added --- stdlib/Test/src/Test.jl | 3 ++- stdlib/Test/test/runtests.jl | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/stdlib/Test/src/Test.jl b/stdlib/Test/src/Test.jl index 3040c5b2ce96d..07ae0ed891716 100644 --- a/stdlib/Test/src/Test.jl +++ b/stdlib/Test/src/Test.jl @@ -487,12 +487,13 @@ 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 - # Positional arguments for a in ex.args[2:end] isa(a, Expr) && a.head in (:kw, :parameters) && continue diff --git a/stdlib/Test/test/runtests.jl b/stdlib/Test/test/runtests.jl index 8ade81802792e..541e8dcc2bf7d 100644 --- a/stdlib/Test/test/runtests.jl +++ b/stdlib/Test/test/runtests.jl @@ -9,6 +9,7 @@ import Logging: Debug, Info, Warn @testset "@test" begin atol = 1 + a = (; atol=2) @test true @test 1 == 1 @test 1 != 2 @@ -22,6 +23,7 @@ import Logging: Debug, Info, Warn @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 From 648e4638ef034fcc2770a82a7aef8a0966a9c581 Mon Sep 17 00:00:00 2001 From: Debaditya Pal Date: Thu, 7 Jan 2021 22:21:29 +0530 Subject: [PATCH 4/4] Update stdlib/Test/src/Test.jl Co-authored-by: Simeon Schaub --- stdlib/Test/src/Test.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/stdlib/Test/src/Test.jl b/stdlib/Test/src/Test.jl index 07ae0ed891716..ceee6ae727648 100644 --- a/stdlib/Test/src/Test.jl +++ b/stdlib/Test/src/Test.jl @@ -494,6 +494,7 @@ function get_test_result(ex, source) end end end + # Positional arguments for a in ex.args[2:end] isa(a, Expr) && a.head in (:kw, :parameters) && continue