Skip to content

Commit

Permalink
Add Vector{<:AbstractString} method for Cmd() (#49531)
Browse files Browse the repository at this point in the history
Was annoyed that `Cmd` wouldn't take a vector containing SubStrings. So
I here add a constructor that converts an `AbstractString` vector to
`String`s.
  • Loading branch information
BioTurboNick authored Feb 10, 2024
1 parent 5547305 commit 9284e57
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion base/cmd.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ struct Cmd <: AbstractCmd
env::Union{Vector{String},Nothing}
dir::String
cpus::Union{Nothing,Vector{UInt16}}
Cmd(exec::Vector{String}) =
Cmd(exec::Vector{<:AbstractString}) =
new(exec, false, 0x00, nothing, "", nothing)
Cmd(cmd::Cmd, ignorestatus, flags, env, dir, cpus = nothing) =
new(cmd.exec, ignorestatus, flags, env,
Expand Down
7 changes: 7 additions & 0 deletions test/spawn.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1032,3 +1032,10 @@ let effects = Base.infer_effects(x -> `a $x`, (Any,))
@test !Core.Compiler.is_noub(effects)
@test !Core.Compiler.is_consistent(effects)
end

# Test that Cmd accepts various AbstractStrings
@testset "AbstractStrings" begin
args = split("-l /tmp")
@assert eltype(args) != String
@test Cmd(["ls", args...]) == `ls -l /tmp`
end

0 comments on commit 9284e57

Please sign in to comment.