Skip to content

Commit

Permalink
REPL: Skip comments when assessing for missing packages, fixes JuliaL…
Browse files Browse the repository at this point in the history
  • Loading branch information
IanButterworth authored and Amit Shirodkar committed Jun 9, 2021
1 parent be8fd2c commit 8334eb9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
1 change: 1 addition & 0 deletions stdlib/REPL/src/REPL.jl
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ function modules_to_be_loaded(ast, mods = Symbol[])
end
return mods
end
modules_to_be_loaded(::Nothing) = Symbol[] # comments are parsed as nothing

"""
start_repl_backend(repl_channel::Channel, response_channel::Channel)
Expand Down
27 changes: 16 additions & 11 deletions stdlib/REPL/test/repl.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1298,27 +1298,32 @@ end

@testset "Install missing packages via hooks" begin
@testset "Parse AST for packages" begin
mods = REPL.modules_to_be_loaded(Meta.parse("using Foo"))
mods = REPL.modules_to_be_loaded(Base.parse_input_line("using Foo"))
@test mods == [:Foo]
mods = REPL.modules_to_be_loaded(Meta.parse("import Foo"))
mods = REPL.modules_to_be_loaded(Base.parse_input_line("import Foo"))
@test mods == [:Foo]
mods = REPL.modules_to_be_loaded(Meta.parse("using Foo, Bar"))
mods = REPL.modules_to_be_loaded(Base.parse_input_line("using Foo, Bar"))
@test mods == [:Foo, :Bar]
mods = REPL.modules_to_be_loaded(Meta.parse("import Foo, Bar"))
mods = REPL.modules_to_be_loaded(Base.parse_input_line("import Foo, Bar"))
@test mods == [:Foo, :Bar]

mods = REPL.modules_to_be_loaded(Meta.parse("if false using Foo end"))
mods = REPL.modules_to_be_loaded(Base.parse_input_line("if false using Foo end"))
@test mods == [:Foo]
mods = REPL.modules_to_be_loaded(Meta.parse("if false if false using Foo end end"))
mods = REPL.modules_to_be_loaded(Base.parse_input_line("if false if false using Foo end end"))
@test mods == [:Foo]
mods = REPL.modules_to_be_loaded(Meta.parse("if false using Foo, Bar end"))
mods = REPL.modules_to_be_loaded(Base.parse_input_line("if false using Foo, Bar end"))
@test mods == [:Foo, :Bar]
mods = REPL.modules_to_be_loaded(Meta.parse("if false using Foo: bar end"))
mods = REPL.modules_to_be_loaded(Base.parse_input_line("if false using Foo: bar end"))
@test mods == [:Foo]

mods = REPL.modules_to_be_loaded(Meta.parse("import Foo.bar as baz"))
mods = REPL.modules_to_be_loaded(Base.parse_input_line("import Foo.bar as baz"))
@test mods == [:Foo]
mods = REPL.modules_to_be_loaded(Meta.parse("using .Foo"))
@test mods == []
mods = REPL.modules_to_be_loaded(Base.parse_input_line("using .Foo"))
@test isempty(mods)

mods = REPL.modules_to_be_loaded(Base.parse_input_line("# comment"))
@test isempty(mods)
mods = REPL.modules_to_be_loaded(Base.parse_input_line("Foo"))
@test isempty(mods)
end
end

0 comments on commit 8334eb9

Please sign in to comment.