Skip to content

Commit

Permalink
Merge pull request #23412 from JuliaLang/cv/env-get
Browse files Browse the repository at this point in the history
Add method for `get(f::Function, ::EnvHash, key)`
  • Loading branch information
omus authored Aug 25, 2017
2 parents 706e720 + 31ec9da commit 14d0b4a
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 0 deletions.
1 change: 1 addition & 0 deletions base/env.jl
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ similar(::EnvHash) = Dict{String,String}()

getindex(::EnvHash, k::AbstractString) = access_env(k->throw(KeyError(k)), k)
get(::EnvHash, k::AbstractString, def) = access_env(k->def, k)
get(f::Callable, ::EnvHash, k::AbstractString) = access_env(k->f(), k)
in(k::AbstractString, ::KeyIterator{EnvHash}) = _hasenv(k)
pop!(::EnvHash, k::AbstractString) = (v = ENV[k]; _unsetenv(k); v)
pop!(::EnvHash, k::AbstractString, def) = haskey(ENV,k) ? pop!(ENV,k) : def
Expand Down
1 change: 1 addition & 0 deletions test/env.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ key = randstring(25)
@test !haskey(ENV,key)
@test_throws KeyError ENV[key]
@test get(ENV,key,"default") == "default"
@test get(() -> "default", ENV, key) == "default"

# Test for #17956
@test length(ENV) > 1
Expand Down

0 comments on commit 14d0b4a

Please sign in to comment.