From b44c1556ff08ce2d64c3a8fc6d28e363a81bb86a Mon Sep 17 00:00:00 2001 From: Chris Foster Date: Thu, 16 Mar 2017 23:15:05 +1000 Subject: [PATCH] Tests for __LINE__ macro inside nested macro calls Plus some refactoring to improve the test case naming. --- test/loading.jl | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/test/loading.jl b/test/loading.jl index 72910eead8690..13eeb4b4d995c 100644 --- a/test/loading.jl +++ b/test/loading.jl @@ -5,19 +5,37 @@ using Base.Test # Tests for @__LINE__ inside and outside of macros @test @__LINE__() == 6 -macro macro_body_lineno() +macro macro_caller_lineno() line = current_location()::Int + :($line) +end + +@test @macro_caller_lineno() == @__LINE__ + +# @__LINE__ in a macro expands to the location of the macro caller +macro emit_LINE() + quote + @__LINE__ + end +end +@test @emit_LINE() == @__LINE__ + +# @__LINE__ expands to location of calling macro in a two-level macro expansion, +# not the top level. +macro nested_LINE_expansion() quote - $line + @emit_LINE() end end +@test @nested_LINE_expansion() == @__LINE__()-3 -macro macro_ast_lineno() - :(@__LINE__) +# @__LINE__ ignores any macro in a multi-level expansion if there's no line +# nodes in the AST. +macro nested_LINE_expansion2() + :(@emit_LINE()) end +@test @nested_LINE_expansion2() == @__LINE__() -@test @macro_body_lineno() == @__LINE__ -@test @macro_ast_lineno() == @__LINE__ include("test_sourcepath.jl")