Skip to content

Commit f14911c

Browse files
committed
Workaround for hot-loading handlers
1 parent fb40301 commit f14911c

File tree

3 files changed

+47
-25
lines changed

3 files changed

+47
-25
lines changed

src/loadsave.jl

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,32 @@ const sym2saver = Dict{Symbol,Vector{Symbol}}()
33

44
is_installed(pkg::Symbol) = get(Pkg.installed(), string(pkg), nothing) != nothing
55

6+
function _findmod(f::Symbol)
7+
for (u,v) in Base.loaded_modules
8+
(Symbol(v) == f) && return u
9+
end
10+
nothing
11+
end
12+
function topimport(modname)
13+
@eval Base.__toplevel__ import $modname
14+
u = _findmod(modname)
15+
@eval $modname = Base.loaded_modules[$u]
16+
end
17+
618
function checked_import(pkg::Symbol)
7-
isdefined(Main, pkg) && return getfield(Main, pkg)
8-
isdefined(FileIO, pkg) && return getfield(FileIO, pkg)
9-
!is_installed(pkg) && throw(NotInstalledError(pkg, ""))
10-
!isdefined(Main, pkg) && Core.eval(Main, Expr(:import, pkg))
11-
return getfield(Main, pkg)
19+
# kludge for test suite
20+
if isdefined(Main, pkg)
21+
m1 = getfield(Main, pkg)
22+
isa(m1, Module) && return m1
23+
end
24+
if isdefined(FileIO, pkg)
25+
m1 = getfield(FileIO, pkg)
26+
isa(m1, Module) && return m1
27+
end
28+
m = _findmod(pkg)
29+
m == nothing || return Base.loaded_modules[m]
30+
topimport(pkg)
31+
return Base.loaded_modules[_findmod(pkg)]
1232
end
1333

1434

test/error_handling.jl

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,29 @@
11
println("these tests will print warnings: ")
22

33
@testset "Not installed" begin
4-
Core.eval(Base, :(is_interactive = true)) # for interactive error handling
5-
64
add_format(format"NotInstalled", (), ".not_installed", [:NotInstalled])
7-
stdin_copy = stdin
8-
stderr_copy = stderr
9-
rs, wr = redirect_stdin()
10-
rserr, wrerr = redirect_stderr()
11-
ref = @async save("test.not_installed", nothing)
12-
println(wr, "y")
13-
@test_throws Pkg.Types.CommandError fetch(ref) #("unknown package NotInstalled")
14-
ref = @async save("test.not_installed", nothing)
15-
println(wr, "invalid") #test invalid input
16-
println(wr, "n") # don't install
17-
fetch(ref)
18-
@test istaskdone(ref)
19-
20-
close(rs);close(wr);close(rserr);close(wrerr)
21-
redirect_stdin(stdin_copy)
22-
redirect_stderr(stderr_copy)
5+
@test_throws ArgumentError save("test.not_installed", nothing)
6+
7+
# Core.eval(Base, :(is_interactive = true)) # for interactive error handling
8+
# add_format(format"NotInstalled", (), ".not_installed", [:NotInstalled])
9+
# stdin_copy = stdin
10+
# stderr_copy = stderr
11+
# rs, wr = redirect_stdin()
12+
# rserr, wrerr = redirect_stderr()
13+
# ref = @async save("test.not_installed", nothing)
14+
# println(wr, "y")
15+
# @test_throws ArgumentError fetch(ref) #("unknown package NotInstalled")
16+
# ref = @async save("test.not_installed", nothing)
17+
# println(wr, "invalid") #test invalid input
18+
# println(wr, "n") # don't install
19+
# fetch(ref)
20+
# @test istaskdone(ref)
21+
22+
# close(rs);close(wr);close(rserr);close(wrerr)
23+
# redirect_stdin(stdin_copy)
24+
# redirect_stderr(stderr_copy)
2325

24-
Core.eval(Base, :(is_interactive = false)) # for interactive error handling
26+
# Core.eval(Base, :(is_interactive = false)) # for interactive error handling
2527

2628
end
2729

test/test_mimesave.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ for filetype in [".svg", ".pdf", ".eps", ".png"]
3737

3838
@test content_new == content_original
3939
finally
40-
rm(output_filename * filetype)
40+
isfile(output_filename * filetype) && rm(output_filename * filetype)
4141
end
4242

4343
end

0 commit comments

Comments
 (0)