Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport ComposedFunction #720

Merged
merged 12 commits into from
Sep 25, 2020
Prev Previous commit
Next Next commit
Merge branch 'master' into composedfunction
  • Loading branch information
tkf committed Sep 24, 2020
commit c7a479958e1afa483aeaa2725ec94b88d028ec25
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
You are viewing a condensed version of this merge commit. You can view the full changes here.