Skip to content

Commit ed1183b

Browse files
authored
Merge pull request #19697 from JuliaLang/yyc/replinit
Fix replinit after jn/world
2 parents 4a140d2 + 233278a commit ed1183b

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

base/client.jl

+3-2
Original file line numberDiff line numberDiff line change
@@ -338,16 +338,17 @@ file.
338338
"""
339339
atreplinit(f::Function) = (unshift!(repl_hooks, f); nothing)
340340

341-
function _atreplinit(repl)
341+
function __atreplinit(repl)
342342
for f in repl_hooks
343343
try
344344
f(repl)
345345
catch err
346-
show(STDERR, err)
346+
showerror(STDERR, err)
347347
println(STDERR)
348348
end
349349
end
350350
end
351+
_atreplinit(repl) = eval(Main, :($__atreplinit($repl)))
351352

352353
function _start()
353354
empty!(ARGS)

test/repl.jl

+16
Original file line numberDiff line numberDiff line change
@@ -548,3 +548,19 @@ let io = IOBuffer()
548548
end, [])
549549
@test length(String(take!(io))) < 1500
550550
end
551+
552+
function test_replinit()
553+
stdin_write, stdout_read, stdout_read, repl = fake_repl()
554+
# Relies on implementation detail to make sure we only have the single
555+
# replinit callback we want to test.
556+
saved_replinit = copy(Base.repl_hooks)
557+
slot = Ref(false)
558+
# Create a closure from a newer world to check if `_atreplinit`
559+
# can run it correctly
560+
atreplinit(eval(:(repl::Base.REPL.LineEditREPL->($slot[] = true))))
561+
Base._atreplinit(repl)
562+
@test slot[]
563+
@test_throws MethodError Base.repl_hooks[1](repl)
564+
copy!(Base.repl_hooks, saved_replinit)
565+
end
566+
test_replinit()

0 commit comments

Comments
 (0)