Skip to content

Commit

Permalink
Tests for __LINE__ macro inside nested macro calls
Browse files Browse the repository at this point in the history
Plus some refactoring to improve the test case naming.
  • Loading branch information
c42f committed Apr 15, 2017
1 parent cfc2dbd commit b44c155
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions test/loading.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit b44c155

Please sign in to comment.