diff --git a/stdlib/InteractiveUtils/src/InteractiveUtils.jl b/stdlib/InteractiveUtils/src/InteractiveUtils.jl index 0c82391ead01e..6cb34d906bf8a 100644 --- a/stdlib/InteractiveUtils/src/InteractiveUtils.jl +++ b/stdlib/InteractiveUtils/src/InteractiveUtils.jl @@ -104,17 +104,14 @@ function versioninfo(io::IO=stdout; verbose::Bool=false, packages::Bool=false) println(io, " LIBM: ",Base.libm_name) println(io, " LLVM: libLLVM-",Base.libllvm_version," (", Sys.JIT, ", ", Sys.CPU_NAME, ")") - println(io, "Environment:") - for (k,v) in ENV - if occursin(r"JULIA", String(k)) - println(io, " $(k) = $(v)") - end - end - if verbose - for (k,v) in ENV - if occursin(r"PATH|FLAG|^TERM$|HOME", String(k)) - println(io, " $(k) = $(v)") - end + env_strs = [String[ " $(k) = $(v)" for (k,v) in ENV if occursin(r"JULIA", k)]; + (verbose ? + String[ " $(k) = $(v)" for (k,v) in ENV if occursin(r"PATH|FLAG|^TERM$|HOME", k)] : + [])] + if !isempty(env_strs) + println(io, "Environment:") + for str in env_strs + println(io, str) end end if packages || verbose diff --git a/stdlib/InteractiveUtils/test/runtests.jl b/stdlib/InteractiveUtils/test/runtests.jl index d5f4f139435e4..73bcc603de1c0 100644 --- a/stdlib/InteractiveUtils/test/runtests.jl +++ b/stdlib/InteractiveUtils/test/runtests.jl @@ -188,6 +188,12 @@ end @test isempty(readdir(dir)) end end + let exename = `$(Base.julia_cmd()) --startup-file=no` + @test !occursin("Environment:", read(setenv(`$exename -e 'using InteractiveUtils; versioninfo()'`, + String[]), String)) + @test occursin("Environment:", read(setenv(`$exename -e 'using InteractiveUtils; versioninfo()'`, + String["JULIA_CPU_CORES=1"]), String)) + end end const curmod = @__MODULE__