Skip to content

Commit

Permalink
prevent versioninfo(verbose=true) init Pkg accidentally (#23075)
Browse files Browse the repository at this point in the history
* prevent versioninfo(verbose=true) init Pkg accidentally.

* Update interactiveutil.jl

remove blank line

* test/pkg: add test cases for versioninfo(verbose=true)

Make sure that it do not raise error if JULIA_PKGDIR is set.

* test/version: move versioninfo tests from test/pkg
  • Loading branch information
iblislin authored and fredrikekre committed Aug 24, 2017
1 parent b64e005 commit 3b767aa
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
9 changes: 7 additions & 2 deletions base/interactiveutil.jl
Original file line number Diff line number Diff line change
Expand Up @@ -330,8 +330,13 @@ function versioninfo(io::IO=STDOUT; verbose::Bool=false, packages::Bool=false)
if packages || verbose
println(io, "Packages:")
println(io, " Package Directory: ", Pkg.dir())
println(io, " Package Status:")
Pkg.status(io)
print(io, " Package Status:")
if isdir(Pkg.dir())
println(io, "")
Pkg.status(io)
else
println(io, " no packages installed")
end
end
end

Expand Down
8 changes: 0 additions & 8 deletions test/pkg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,6 @@ temp_pkg_dir() do
@test_throws PkgError Pkg.installed("MyFakePackage")
@test Pkg.installed("Example") === nothing

# check that versioninfo(io; verbose=true) doesn't error and produces some output
# (done here since it calls Pkg.status which might error or clone metadata)
buf = PipeBuffer()
versioninfo(buf, verbose=true)
ver = read(buf, String)
@test startswith(ver, "Julia Version $VERSION")
@test contains(ver, "Environment:")

# Check that setprotocol! works.
begin
try
Expand Down
18 changes: 18 additions & 0 deletions test/version.jl
Original file line number Diff line number Diff line change
Expand Up @@ -279,3 +279,21 @@ for t = 1:1_000
@test (v a && v b) ? (v i) : (v i)
end
end

# PR #23075
@testset "versioninfo" begin
# check that versioninfo(io; verbose=true) doesn't error, produces some output
# and doesn't invoke Pkg.status which will error if JULIA_PKGDIR is set
mktempdir() do dir
withenv("JULIA_PKGDIR" => dir) do
buf = PipeBuffer()
versioninfo(buf, verbose=true)
ver = read(buf, String)
@test startswith(ver, "Julia Version $VERSION")
@test contains(ver, "Environment:")
@test contains(ver, "Package Status:")
@test contains(ver, "no packages installed")
@test isempty(readdir(dir))
end
end
end

0 comments on commit 3b767aa

Please sign in to comment.