Skip to content

Commit

Permalink
Merge pull request #64 from JuliaDebug/teh/modules
Browse files Browse the repository at this point in the history
Find modules in loaded packages
  • Loading branch information
timholy authored Feb 24, 2019
2 parents ca07ee9 + 2b7c63b commit a4ae7bf
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/JuliaInterpreter.jl
Original file line number Diff line number Diff line change
Expand Up @@ -474,8 +474,16 @@ function split_expressions!(modexs, docexprs, lex::Expr, mod::Module, ex::Expr;
if ex.head == :toplevel || ex.head == :block
split_expressions!(modexs, docexprs, lex, mod, ex.args; extract_docexprs=extract_docexprs, filename=filename)
elseif ex.head == :module
modname = ex.args[2]::Symbol
newmod = isdefined(mod, modname) ? getfield(mod, modname) : Core.eval(mod, :(module $modname end))
newname = ex.args[2]::Symbol
if isdefined(mod, newname)
newmod = getfield(mod, newname)
else
if (id = Base.identify_package(mod, String(newname))) !== nothing
newmod = Base.root_module(id)
else
newmod = Core.eval(mod, :(module $newname end))
end
end
split_expressions!(modexs, docexprs, lex, newmod, ex.args[3]; extract_docexprs=extract_docexprs, filename=filename)
elseif extract_docexprs && isdocexpr(ex)
docexs = get(docexprs, mod, nothing)
Expand Down
37 changes: 37 additions & 0 deletions test/toplevel.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
using JuliaInterpreter, Test

module JIVisible
module JIInvisible
end
end

@testset "Basics" begin
@test JuliaInterpreter.isdocexpr(:(@doc "string" sum))
@test JuliaInterpreter.isdocexpr(:(Core.@doc "string" sum))
Expand All @@ -11,6 +16,38 @@ using JuliaInterpreter, Test
end
@test JuliaInterpreter.isdocexpr(ex.args[2])
@test !JuliaInterpreter.isdocexpr(:(1+1))

@test !isdefined(Main, :JIInvisible)
JuliaInterpreter.split_expressions(JIVisible, :(module JIInvisible f() = 1 end))
@test !isdefined(Main, :JIInvisible)
mktempdir() do path
push!(LOAD_PATH, path)
open(joinpath(path, "TmpPkg1.jl"), "w") do io
println(io, """
module TmpPkg1
using TmpPkg2
end
""")
end
open(joinpath(path, "TmpPkg2.jl"), "w") do io
println(io, """
module TmpPkg2
f() = 1
end
""")
end
@eval using TmpPkg1
# Every package is technically parented in Main but the name may not be visible in Main
@test isdefined(@__MODULE__, :TmpPkg1)
@test !isdefined(@__MODULE__, :TmpPkg2)
JuliaInterpreter.split_expressions(Main, quote
module TmpPkg2
f() = 2
end
end)
@test isdefined(@__MODULE__, :TmpPkg1)
@test !isdefined(@__MODULE__, :TmpPkg2)
end
end

module Toplevel end
Expand Down

0 comments on commit a4ae7bf

Please sign in to comment.