Skip to content

Commit

Permalink
JuliaLang/julia#21197: accessing Cmd as an array of strings (#379)
Browse files Browse the repository at this point in the history
  • Loading branch information
stevengj authored and tkelman committed Jul 20, 2017
1 parent 56d1578 commit c8df172
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ Currently, the `@compat` macro supports the following syntaxes:

* `@__MODULE__` is aliased to `current_module()` for Julia versions 0.6 and below. Versions of `Base.binding_module`, `expand`, `macroexpand`, and `include_string` were added that accept a module as the first argument. ([#22064])

* `Cmd` elements can be accessed as if the `Cmd` were an array of strings for 0.6 and below ([#21197]).

* `Val(x)` constructs `Val{x}()`. ([#22475])

* `chol` and `chol!` for `UniformScalings` ([#22633]).
Expand Down
11 changes: 11 additions & 0 deletions src/Compat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,17 @@ else
const collect = Base.collect
end

# https://github.com/JuliaLang/julia/pull/21197
if VERSION < v"0.7.0-DEV.257"
# allow the elements of the Cmd to be accessed as an array or iterator
for f in (:length, :endof, :start, :eachindex, :eltype, :first, :last)
@eval Base.$f(cmd::Cmd) = $f(cmd.exec)
end
for f in (:next, :done, :getindex)
@eval Base.$f(cmd::Cmd, i) = $f(cmd.exec, i)
end
end

# https://github.com/JuliaLang/julia/pull/21378
if VERSION < v"0.6.0-pre.beta.455"
import Base: ==, isless
Expand Down
11 changes: 11 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1882,6 +1882,17 @@ let
@test_throws MethodError Dates.Month(1) < Dates.Day(1)
end

# PR #21197
let c = `ls -l "foo bar"`
@test collect(c) == ["ls", "-l", "foo bar"]
@test first(c) == "ls" == c[1]
@test last(c) == "foo bar" == c[3] == c[end]
@test c[1:2] == ["ls", "-l"]
@test eltype(c) == String
@test length(c) == 3
@test eachindex(c) == 1:3
end

# PR 22629
@test logdet(0.5) == log(det(0.5))

Expand Down

0 comments on commit c8df172

Please sign in to comment.