Skip to content

Commit e5582be

Browse files
authored
Use relative import paths in tests (JuliaLang/JuliaLowering.jl#110)
For vendoring into Base we need to avoid absolute import paths as in `using JuliaLowering` and `using JuliaSyntax` in the test files as neither of these packages will be top level modules. Thus, replace all occurrences of these with relative import paths except for one central location (currently in util.jl) which can be easily adjusted.
1 parent 315d125 commit e5582be

File tree

8 files changed

+36
-29
lines changed

8 files changed

+36
-29
lines changed

JuliaLowering/test/branching.jl

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,6 @@
44

55
test_mod = Module()
66

7-
Base.eval(test_mod, quote
8-
using JuliaLowering: JuliaLowering, @ast, @chk
9-
using JuliaSyntax
10-
end)
11-
127
#-------------------------------------------------------------------------------
138
@testset "Tail position" begin
149

JuliaLowering/test/compat.jl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
using Test
2-
using JuliaSyntax
3-
using JuliaLowering
42
const JS = JuliaSyntax
53
const JL = JuliaLowering
64

JuliaLowering/test/import.jl

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,7 @@
22

33
test_mod = Module()
44

5-
JuliaLowering.include_string(test_mod, """
6-
using JuliaSyntax
7-
using JuliaLowering: SyntaxTree
8-
using JuliaLowering: SyntaxTree as st
9-
import JuliaLowering: SyntaxTree as st1, SyntaxTree as st2
10-
""")
11-
@test test_mod.SyntaxTree === JuliaLowering.SyntaxTree
12-
@test test_mod.st === JuliaLowering.SyntaxTree
13-
@test test_mod.st1 === JuliaLowering.SyntaxTree
14-
@test test_mod.st2 === JuliaLowering.SyntaxTree
15-
@test test_mod.parsestmt === JuliaSyntax.parsestmt
16-
5+
# Test attributes are correctly set for export/public
176
JuliaLowering.include_string(test_mod, """
187
x = 1
198
y = 2
@@ -25,21 +14,37 @@ public y
2514
@test Base.ispublic(test_mod, :y)
2615
@test !Base.isexported(test_mod, :y)
2716

17+
# Test various forms of `using`
2818
C = JuliaLowering.include_string(test_mod, """
2919
module C
3020
module D
21+
export x
22+
public y, f
23+
x = [101]
24+
y = [202]
25+
3126
function f()
3227
"hi"
3328
end
3429
end
3530
module E
36-
using ...C.D: f
31+
using ..D: f
32+
using ..D
33+
using .D: y as D_y
34+
using .D: x as D_x_2, y as D_y_2
35+
import .D.y as D_y_3
3736
end
3837
end
3938
""")
4039
@test C.D.f === C.E.f
40+
@test C.D.x === C.E.x
41+
@test C.D.y === C.E.D_y
42+
@test C.D.x === C.E.D_x_2
43+
@test C.D.y === C.E.D_y_2
44+
@test C.D.y === C.E.D_y_3
4145

42-
# Test that `using` F brings in the symbol G immediately
46+
# Test that using F brings in the exported symbol G immediately and that it can
47+
# be used next in the import list.
4348
F = JuliaLowering.include_string(test_mod, """
4449
module F
4550
export G

JuliaLowering/test/macros.jl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,15 @@ test_mod = Module(:macro_test)
44
Base.eval(test_mod, :(const var"@ast" = $(JuliaLowering.var"@ast")))
55
Base.eval(test_mod, :(const var"@K_str" = $(JuliaLowering.var"@K_str")))
66

7+
# These libraries may either be packages or vendored into Base - need to pull
8+
# them in via relative paths in the `using` statements below.
9+
Base.eval(test_mod, :(const JuliaLowering = $(JuliaLowering)))
10+
Base.eval(test_mod, :(const JuliaSyntax = $(JuliaSyntax)))
11+
712
JuliaLowering.include_string(test_mod, raw"""
813
module M
9-
using JuliaLowering: JuliaLowering, @ast, @chk, adopt_scope
10-
using JuliaSyntax
14+
using ..JuliaLowering: JuliaLowering, adopt_scope
15+
using ..JuliaSyntax
1116
1217
# Introspection
1318
macro __MODULE__()

JuliaLowering/test/repl_mode.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# JuliaLowering REPL mode: an interactive test utility for lowering code (not
2+
# part of the unit tests)
3+
14
module JuliaLoweringREPL
25

36
import ReplMaker

JuliaLowering/test/runtests.jl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
using Test
2-
31
include("utils.jl")
42

53
@testset "JuliaLowering.jl" begin

JuliaLowering/test/scopes_ir.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using JuliaLowering: @islocal
1+
using .JuliaLowering: @islocal
22
using Base: @locals
33

44
#*******************************************************************************

JuliaLowering/test/utils.jl

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
# Shared testing code which should be included before running individual test files.
12
using Test
23

34
using JuliaLowering
45
using JuliaSyntax
6+
57
import FileWatching
68

79
# The following are for docstrings testing. We need to load the REPL module
@@ -10,9 +12,9 @@ import FileWatching
1012
using Markdown
1113
import REPL
1214

13-
using JuliaSyntax: sourcetext, set_numeric_flags
15+
using .JuliaSyntax: sourcetext, set_numeric_flags
1416

15-
using JuliaLowering:
17+
using .JuliaLowering:
1618
SyntaxGraph, newnode!, ensure_attributes!,
1719
Kind, SourceRef, SyntaxTree, NodeId,
1820
makenode, makeleaf, setattr!, sethead!,
@@ -153,8 +155,9 @@ end
153155

154156
function setup_ir_test_module(preamble)
155157
test_mod = Module(:TestMod)
156-
JuliaLowering.include_string(test_mod, preamble)
158+
Base.eval(test_mod, :(const JuliaLowering = $JuliaLowering))
157159
Base.eval(test_mod, :(const var"@ast_" = $(var"@ast_")))
160+
JuliaLowering.include_string(test_mod, preamble)
158161
test_mod
159162
end
160163

0 commit comments

Comments
 (0)