Skip to content

Commit

Permalink
Fix JuliaLang#17956 and add test. The bug was introduced in 103db50
Browse files Browse the repository at this point in the history
  • Loading branch information
dhoegh committed Aug 13, 2016
1 parent 30afe08 commit d957e75
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion base/env.jl
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ end
function next(hash::EnvHash, block::Tuple{Ptr{UInt16},Ptr{UInt16}})
pos = block[1]
blk = block[2]
len = ccall(:wcslen, UInt, (Ptr{UInt16},), pos)
len = ccall(:wcslen, UInt, (Ptr{UInt16},), pos) + 1
buf = Array{UInt16}(len)
unsafe_copy!(pointer(buf), pos, len)
env = transcode(String, buf)
Expand Down
33 changes: 33 additions & 0 deletions test/env.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,36 @@ key = randstring(25)
@test !haskey(ENV,key)
@test_throws KeyError ENV[key]
@test get(ENV,key,"default") == "default"

# Test for #17956
@test length(ENV) > 1
k1, k2 = "__test__", "__test1__"
withenv(k1=>k1, k2=>k2) do
b_k1, b_k2 = false, false
for (k, v) in ENV
if k==k1
b_k1=true
elseif k==k2
b_k2=true
end
end
@test b_k1 && b_k2
io = IOBuffer()
show(io, ENV)
s = takebuf_string(io)
@test contains(s, k1)
@test contains(s, k2)

@test pop!(ENV, k1) == k1
@test !haskey(ENV, k1)
ENV[k1] = k1
@test pop!(ENV, k1) == k1
@test pop!(ENV, k1, "not_there") == "not_there"

ENV[k1] = k1
@test delete!(ENV, k1) == ENV
@test !haskey(ENV, k1)
end

# Test for #10853
@test withenv(Dict{Any,Any}()...) do; true; end

0 comments on commit d957e75

Please sign in to comment.