Skip to content

Commit

Permalink
Fix push! signature for EnvDict. (#25011)
Browse files Browse the repository at this point in the history
  • Loading branch information
andyferris authored and JeffBezanson committed Jan 16, 2018
1 parent cdef6b7 commit 19429e2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
3 changes: 3 additions & 0 deletions base/deprecated.jl
Expand Up @@ -2641,6 +2641,9 @@ end
@deprecate lpad(s, n::Integer, p) lpad(string(s), n, string(p))
@deprecate rpad(s, n::Integer, p) rpad(string(s), n, string(p))

# PR #25011
@deprecate push!(env::EnvDict, k::AbstractString, v) push!(env, k=>v)

# issue #24868
@deprecate sprint(size::Integer, f::Function, args...; env=nothing) sprint(f, args...; context=env, sizehint=size)

Expand Down
2 changes: 1 addition & 1 deletion base/env.jl
Expand Up @@ -81,7 +81,7 @@ pop!(::EnvDict, k::AbstractString) = (v = ENV[k]; _unsetenv(k); v)
pop!(::EnvDict, k::AbstractString, def) = haskey(ENV,k) ? pop!(ENV,k) : def
delete!(::EnvDict, k::AbstractString) = (_unsetenv(k); ENV)
setindex!(::EnvDict, v, k::AbstractString) = _setenv(k,string(v))
push!(::EnvDict, k::AbstractString, v) = setindex!(ENV, v, k)
push!(::EnvDict, kv::Pair{<:AbstractString}) = setindex!(ENV, kv.second, kv.first)

if Sys.iswindows()
start(hash::EnvDict) = (pos = ccall(:GetEnvironmentStringsW,stdcall,Ptr{UInt16},()); (pos,pos))
Expand Down
8 changes: 8 additions & 0 deletions test/env.jl
Expand Up @@ -73,3 +73,11 @@ for (k, v) in ENV
@test v[end] != '\0'
end
end

@testset "push" begin
@test !haskey(ENV, "testing_envdict")
push!(ENV, "testing_envdict" => "tested")
@test haskey(ENV, "testing_envdict")
@test ENV["testing_envdict"] == "tested"
delete!(ENV, "testing_envdict")
end

0 comments on commit 19429e2

Please sign in to comment.