Skip to content

Commit

Permalink
Merge pull request #19697 from JuliaLang/yyc/replinit
Browse files Browse the repository at this point in the history
Fix replinit after jn/world
  • Loading branch information
yuyichao authored Dec 28, 2016
2 parents 4a140d2 + 233278a commit ed1183b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
5 changes: 3 additions & 2 deletions base/client.jl
Original file line number Diff line number Diff line change
Expand Up @@ -338,16 +338,17 @@ file.
"""
atreplinit(f::Function) = (unshift!(repl_hooks, f); nothing)

function _atreplinit(repl)
function __atreplinit(repl)
for f in repl_hooks
try
f(repl)
catch err
show(STDERR, err)
showerror(STDERR, err)
println(STDERR)
end
end
end
_atreplinit(repl) = eval(Main, :($__atreplinit($repl)))

function _start()
empty!(ARGS)
Expand Down
16 changes: 16 additions & 0 deletions test/repl.jl
Original file line number Diff line number Diff line change
Expand Up @@ -548,3 +548,19 @@ let io = IOBuffer()
end, [])
@test length(String(take!(io))) < 1500
end

function test_replinit()
stdin_write, stdout_read, stdout_read, repl = fake_repl()
# Relies on implementation detail to make sure we only have the single
# replinit callback we want to test.
saved_replinit = copy(Base.repl_hooks)
slot = Ref(false)
# Create a closure from a newer world to check if `_atreplinit`
# can run it correctly
atreplinit(eval(:(repl::Base.REPL.LineEditREPL->($slot[] = true))))
Base._atreplinit(repl)
@test slot[]
@test_throws MethodError Base.repl_hooks[1](repl)
copy!(Base.repl_hooks, saved_replinit)
end
test_replinit()

0 comments on commit ed1183b

Please sign in to comment.