Skip to content

Commit fec6bf8

Browse files
add test
1 parent 235430d commit fec6bf8

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# This file is a part of Julia. License is MIT: https://julialang.org/license
2+
3+
# Test that interactive mode starts up without error when history file is bad
4+
5+
using Test
6+
7+
const BASE_TEST_PATH = joinpath(Sys.BINDIR, "..", "share", "julia", "test")
8+
isdefined(Main, :FakePTYs) || @eval Main include(joinpath($(BASE_TEST_PATH), "testhelpers", "FakePTYs.jl"))
9+
import .Main.FakePTYs: with_fake_pty
10+
11+
@testset "Bad history file startup" begin
12+
mktempdir() do tmpdir
13+
# Create a bad history file
14+
hist_file = joinpath(tmpdir, "repl_history.jl")
15+
write(hist_file, "{ invalid json content\nmore bad content\n")
16+
17+
julia_exe = Base.julia_cmd()[1]
18+
19+
# Test interactive Julia startup with bad history file
20+
with_fake_pty() do pts, ptm
21+
# Set up environment with our bad history file
22+
nENV = copy(ENV)
23+
nENV["JULIA_HISTORY"] = hist_file
24+
25+
# Start Julia in interactive mode
26+
p = run(detach(setenv(`$julia_exe --startup-file=no --color=no -q`, nENV)), pts, pts, pts, wait=false)
27+
Base.close_stdio(pts)
28+
29+
# Read output until we get the prompt, which indicates successful startup
30+
output = readuntil(ptm, "julia> ", keep=true)
31+
32+
# Test conditions:
33+
# 1. We should see the invalid history file error
34+
has_history_error = occursin("Invalid history file", output) ||
35+
occursin("Invalid character", output)
36+
@test has_history_error
37+
38+
# 2. We should NOT see UndefRefError (the bug being fixed)
39+
has_undef_error = occursin("UndefRefError", output)
40+
@test !has_undef_error
41+
42+
# 3. We should see the "Disabling history file" message if the fix works
43+
has_disable_message = occursin("Disabling history file for this session", output)
44+
@test has_disable_message
45+
46+
# Send exit command to clean shutdown
47+
write(ptm, "exit()\n")
48+
49+
# Read any remaining output until the process exits
50+
try
51+
read(ptm, String)
52+
catch ex
53+
# Handle platform-specific EOF behavior
54+
if ex isa Base.IOError && ex.code == Base.UV_EIO
55+
# This is expected on some platforms (e.g., Linux)
56+
else
57+
rethrow()
58+
end
59+
end
60+
61+
# Wait for process to finish
62+
wait(p)
63+
64+
@test p.exitcode == 0
65+
end
66+
end
67+
end

stdlib/REPL/test/runtests.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ end
2222
module TerminalMenusTest
2323
include("TerminalMenus/runtests.jl")
2424
end
25+
module BadHistoryStartupTest
26+
include("bad_history_startup.jl")
27+
end
2528

2629
# Restore the original environment
2730
for k in keys(ENV)

0 commit comments

Comments
 (0)