Skip to content

Commit 4f14797

Browse files
committed
Fix some tests when run in base
Part of JuliaLang/julia#60058. When we don't have a log file setup, the default IO is set to devnull. However, this causes `Pkg.status` to early out and skip some validity checks that we are testing for. Fix this by passing an appropriate io directly to the API. For the REPL test, which don't have an IO argument, override the global default IO, but to make that more robust also switch it to a ScopedValue (which Pkg is already using elsewhere).
1 parent 88a46e6 commit 4f14797

File tree

7 files changed

+203
-192
lines changed

7 files changed

+203
-192
lines changed

ext/REPLExt/precompile.jl

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,26 @@ let
1414
original_load_path = copy(LOAD_PATH)
1515
__init__()
1616
Pkg.UPDATED_REGISTRY_THIS_SESSION[] = true
17-
Pkg.DEFAULT_IO[] = Pkg.unstableio(devnull)
18-
withenv("JULIA_PKG_SERVER" => nothing, "JULIA_PKG_UNPACK_REGISTRY" => nothing) do
19-
tmp = Pkg._run_precompilation_script_setup()
20-
cd(tmp) do
21-
try_prompt_pkg_add(Symbol[:notapackage])
22-
promptf()
23-
term = FakeTerminal()
24-
repl = REPL.LineEditREPL(term, true)
25-
REPL.run_repl(repl)
26-
repl_init(repl)
17+
@Base.ScopedValues.with Pkg.DEFAULT_IO => Pkg.unstableio(devnull) begin
18+
withenv("JULIA_PKG_SERVER" => nothing, "JULIA_PKG_UNPACK_REGISTRY" => nothing) do
19+
tmp = Pkg._run_precompilation_script_setup()
20+
cd(tmp) do
21+
try_prompt_pkg_add(Symbol[:notapackage])
22+
promptf()
23+
term = FakeTerminal()
24+
repl = REPL.LineEditREPL(term, true)
25+
REPL.run_repl(repl)
26+
repl_init(repl)
27+
end
2728
end
28-
end
29-
copy!(DEPOT_PATH, original_depot_path)
30-
copy!(LOAD_PATH, original_load_path)
29+
copy!(DEPOT_PATH, original_depot_path)
30+
copy!(LOAD_PATH, original_load_path)
3131

32-
Base.precompile(Tuple{typeof(REPL.LineEdit.complete_line), REPLExt.PkgCompletionProvider, REPL.LineEdit.PromptState})
33-
Base.precompile(Tuple{typeof(REPL.REPLCompletions.completion_text), REPL.REPLCompletions.PackageCompletion})
34-
Base.precompile(Tuple{typeof(REPLExt.on_done), REPL.LineEdit.MIState, Base.GenericIOBuffer{Memory{UInt8}}, Bool, REPL.LineEditREPL})
35-
return Base.precompile(Tuple{typeof(Core.kwcall), NamedTuple{(:hint,), Tuple{Bool}}, typeof(REPL.LineEdit.complete_line), REPLExt.PkgCompletionProvider, REPL.LineEdit.PromptState})
32+
Base.precompile(Tuple{typeof(REPL.LineEdit.complete_line), REPLExt.PkgCompletionProvider, REPL.LineEdit.PromptState})
33+
Base.precompile(Tuple{typeof(REPL.REPLCompletions.completion_text), REPL.REPLCompletions.PackageCompletion})
34+
Base.precompile(Tuple{typeof(REPLExt.on_done), REPL.LineEdit.MIState, Base.GenericIOBuffer{Memory{UInt8}}, Bool, REPL.LineEditREPL})
35+
return Base.precompile(Tuple{typeof(Core.kwcall), NamedTuple{(:hint,), Tuple{Bool}}, typeof(REPL.LineEdit.complete_line), REPLExt.PkgCompletionProvider, REPL.LineEdit.PromptState})
36+
end
3637
end
3738

3839
if Base.generating_output()

src/Pkg.jl

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ const UPDATED_REGISTRY_THIS_SESSION = Ref(false)
6161
const OFFLINE_MODE = Ref(false)
6262
const RESPECT_SYSIMAGE_VERSIONS = Ref(true)
6363
# For globally overriding in e.g. tests
64-
const DEFAULT_IO = Ref{Union{IO, Nothing}}(nothing)
64+
const DEFAULT_IO = Base.ScopedValues.ScopedValue{IO}()
6565

6666
# ScopedValue to track whether we're currently in REPL mode
6767
const IN_REPL_MODE = Base.ScopedValues.ScopedValue{Bool}()
@@ -75,8 +75,8 @@ function unstableio(@nospecialize(io::IO))
7575
get(_io, :color, false) ? Base.ImmutableDict{Symbol, Any}(:color, true) : Base.ImmutableDict{Symbol, Any}()
7676
)
7777
end
78-
stderr_f() = something(DEFAULT_IO[], unstableio(stderr))
79-
stdout_f() = something(DEFAULT_IO[], unstableio(stdout))
78+
stderr_f() = something(Base.ScopedValues.get(DEFAULT_IO), unstableio(stderr))
79+
stdout_f() = something(Base.ScopedValues.get(DEFAULT_IO), unstableio(stdout))
8080
const PREV_ENV_PATH = Ref{String}("")
8181

8282
usable_io(io) = (io isa Base.TTY) || (io isa IOContext{IO} && io.io isa Base.TTY)
@@ -1015,7 +1015,6 @@ end
10151015
include("precompile.jl")
10161016

10171017
# Reset globals that might have been mutated during precompilation.
1018-
DEFAULT_IO[] = nothing
10191018
Pkg.UPDATED_REGISTRY_THIS_SESSION[] = false
10201019
PREV_ENV_PATH[] = ""
10211020
Types.STDLIB[] = nothing

0 commit comments

Comments
 (0)