From 9284e572eb0a9f18ec7276de2f6456dcc0b99ed4 Mon Sep 17 00:00:00 2001 From: Nicholas Bauer Date: Fri, 9 Feb 2024 22:08:04 -0500 Subject: [PATCH] Add `Vector{<:AbstractString}` method for `Cmd()` (#49531) 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. --- base/cmd.jl | 2 +- test/spawn.jl | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/base/cmd.jl b/base/cmd.jl index da29c732c7f26..0e4ec119109f1 100644 --- a/base/cmd.jl +++ b/base/cmd.jl @@ -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, diff --git a/test/spawn.jl b/test/spawn.jl index 4ae4b3368bef6..9d58b32976357 100644 --- a/test/spawn.jl +++ b/test/spawn.jl @@ -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