Skip to content

Commit

Permalink
Merge branch 'master' into composedfunction
Browse files Browse the repository at this point in the history
  • Loading branch information
tkf committed Sep 24, 2020
2 parents 48d4f22 + a135ef3 commit c7a4799
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "Compat"
uuid = "34da2185-b29b-5c13-b0c7-acf172513d20"
version = "3.15.0"
version = "3.16.0"

[deps]
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ changes in `julia`.

## Supported features

* New function `addenv` for adding environment mappings into a `Cmd` object, returning the new `Cmd` object ([#37244]). (since Compat 3.16)

* `contains(haystack, needle)` and its one argument partially applied form `contains(haystack)` have been added, it acts like `occursin(needle, haystack)` ([#35132]). (since Compat 3.15)

* `startswith(x)` and `endswith(x)`, returning partially-applied versions of the functions, similar to existing methods like `isequal(x)` ([#35052]). (since Compat 3.15)
Expand Down Expand Up @@ -197,3 +199,4 @@ Note that you should specify the correct minimum version for `Compat` in the
[#34352]: https://github.com/JuliaLang/julia/pull/34352
[#35132]: https://github.com/JuliaLang/julia/pull/35132
[#35052]: https://github.com/JuliaLang/julia/pull/35052
[#37244]: https://github.com/JuliaLang/julia/pull/37244
25 changes: 25 additions & 0 deletions src/Compat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,31 @@ else
using Base: ComposedFunction
end

# https://github.com/JuliaLang/julia/pull/37244
if VERSION < v"1.6.0-DEV.873" # 18198b1bf85125de6cec266eac404d31ccc2e65c
export addenv
function addenv(cmd::Cmd, env::Dict)
new_env = Dict{String,String}()
if cmd.env !== nothing
for (k, v) in split.(cmd.env, "=")
new_env[string(k)::String] = string(v)::String
end
end
for (k, v) in env
new_env[string(k)::String] = string(v)::String
end
return setenv(cmd, new_env)
end

function addenv(cmd::Cmd, pairs::Pair{<:AbstractString}...)
return addenv(cmd, Dict(k => v for (k, v) in pairs))
end

function addenv(cmd::Cmd, env::Vector{<:AbstractString})
return addenv(cmd, Dict(k => v for (k, v) in split.(env, "=")))
end
end

include("iterators.jl")
include("deprecated.jl")

Expand Down
28 changes: 28 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,34 @@ end
end
end

# From spawn.jl
shcmd = `sh`
havebb = false
if Sys.iswindows()
busybox = download("https://cache.julialang.org/https://frippery.org/files/busybox/busybox.exe", joinpath(tempdir(), "busybox.exe"))
havebb = try # use busybox-w32 on windows, if available
success(`$busybox`)
true
catch
false
end
if havebb
shcmd = `$busybox sh`
end
end

# https://github.com/JuliaLang/julia/pull/37244
@testset "addenv()" begin
cmd = Cmd(`$shcmd -c "echo \$FOO \$BAR"`, env=Dict("FOO" => "foo"))
@test strip(String(read(cmd))) == "foo"
cmd = addenv(cmd, "BAR" => "bar")
@test strip(String(read(cmd))) == "foo bar"
cmd = addenv(cmd, Dict("FOO" => "bar"))
@test strip(String(read(cmd))) == "bar bar"
cmd = addenv(cmd, ["FOO=baz"])
@test strip(String(read(cmd))) == "baz bar"
end

include("iterators.jl")

nothing

0 comments on commit c7a4799

Please sign in to comment.