Skip to content

Commit b44c155

Browse files
committed
Tests for __LINE__ macro inside nested macro calls
Plus some refactoring to improve the test case naming.
1 parent cfc2dbd commit b44c155

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

test/loading.jl

+24-6
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,37 @@ using Base.Test
55
# Tests for @__LINE__ inside and outside of macros
66
@test @__LINE__() == 6
77

8-
macro macro_body_lineno()
8+
macro macro_caller_lineno()
99
line = current_location()::Int
10+
:($line)
11+
end
12+
13+
@test @macro_caller_lineno() == @__LINE__
14+
15+
# @__LINE__ in a macro expands to the location of the macro caller
16+
macro emit_LINE()
17+
quote
18+
@__LINE__
19+
end
20+
end
21+
@test @emit_LINE() == @__LINE__
22+
23+
# @__LINE__ expands to location of calling macro in a two-level macro expansion,
24+
# not the top level.
25+
macro nested_LINE_expansion()
1026
quote
11-
$line
27+
@emit_LINE()
1228
end
1329
end
30+
@test @nested_LINE_expansion() == @__LINE__()-3
1431

15-
macro macro_ast_lineno()
16-
:(@__LINE__)
32+
# @__LINE__ ignores any macro in a multi-level expansion if there's no line
33+
# nodes in the AST.
34+
macro nested_LINE_expansion2()
35+
:(@emit_LINE())
1736
end
37+
@test @nested_LINE_expansion2() == @__LINE__()
1838

19-
@test @macro_body_lineno() == @__LINE__
20-
@test @macro_ast_lineno() == @__LINE__
2139

2240

2341
include("test_sourcepath.jl")

0 commit comments

Comments
 (0)