From 8e05fb94f09d4107e4ef6fc2704cc29d4f2d0153 Mon Sep 17 00:00:00 2001 From: Claire Foster Date: Thu, 22 Jun 2023 07:42:13 +1000 Subject: [PATCH] Accommodate JuliaSyntax in tests JuliaSyntax generates more consistent syntax trees for obscure versions of long and short form anonymous function argument lists. For the cases which are different and lead to errors, adjust the tests to use explicit `Expr`s here so that we're testing ExprTools code rather than the Julia parser itself. * `function (x)::Integer; x end` is now parsed correctly * Use an explicit Expr for the old `(;) -> nothing` syntax --- test/function.jl | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/test/function.jl b/test/function.jl index 3c59523..562dd7c 100644 --- a/test/function.jl +++ b/test/function.jl @@ -483,12 +483,16 @@ function_form(short::Bool) = string(short ? "short" : "long", "-form") @testset "block expression ($(function_form(short)) anonymous function)" for short in (true, false) @testset "(;)" begin # The `(;)` syntax was deprecated in 1.4.0-DEV.585 (ce29ec547e) but we can still - # test the behavior with `begin end`. - f, expr = if short - @audit (begin end) -> nothing + # test the behavior with an explicit Expr + expr = if short + # `(;) -> nothing` + Expr(:->, Expr(:block), Expr(:block, LineNumberNode(@__LINE__, @__FILE__), :nothing)) else - @audit function (begin end) nothing end + # `function (;) nothing end` + Expr(:function, Expr(:block), Expr(:block, LineNumberNode(@__LINE__, @__FILE__), :nothing)) end + f = eval(expr) + @test length(methods(f)) == 1 @test f() === nothing @@ -788,8 +792,12 @@ function_form(short::Bool) = string(short ? "short" : "long", "-form") @testset "return-type (long-form anonymous function)" begin @testset "(x)::Integer" begin - # Interpreted as `function (x::Integer); x end` - f, expr = @audit function (x)::Integer; x end + # Older parsers interpret + # `function (x)::Integer; x end` + # as + # `function (x::Integer); x end` + expr = Expr(:function, Expr(:tuple, Expr(:(::), :x, :Integer)), Expr(:block, LineNumberNode(@__LINE__, @__FILE__), :x)) + f = eval(expr) @test length(methods(f)) == 1 @test f(0) == 0 @test_throws MethodError f(0.0)