Skip to content

Commit

Permalink
Add Sys.is<os>
Browse files Browse the repository at this point in the history
  • Loading branch information
ararslan committed Jul 19, 2017
1 parent 1d33d04 commit d0f4b25
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@ Currently, the `@compat` macro supports the following syntaxes:

* `takebuf_array` is now a method of `take!`. `takebuf_string(io)` becomes `String(take!(io))` ([#19088])

* `is_apple`, `is_bsd`, `is_linux`, `is_unix`, and `is_windows` are now `Sys.isapple`, `Sys.isbsd`,
`Sys.islinux`, `Sys.isunix`, and `Sys.iswindows`, respectively. These are available in the `Compat.Sys`
submodule. ([#22182])

## New macros

* `@__DIR__` has been added ([#18380])
Expand Down Expand Up @@ -285,4 +289,5 @@ includes this fix. Find the minimum version from there.
[#21257]: https://github.com/JuliaLang/julia/issues/21257
[#21346]: https://github.com/JuliaLang/julia/issues/21346
[#22064]: https://github.com/JuliaLang/julia/issues/22064
[#22182]: https://github.com/JuliaLang/julia/issues/22182
[#22475]: https://github.com/JuliaLang/julia/issues/22475
13 changes: 13 additions & 0 deletions src/Compat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -618,4 +618,17 @@ include("deprecated.jl")
# https://github.com/JuliaLang/julia/pull/21746
const macros_have_sourceloc = VERSION >= v"0.7-" && length(:(@test).args) == 2

# https://github.com/JuliaLang/julia/pull/22182
module Sys
if VERSION < v"0.7.0-DEV.914"
isapple(k::Symbol=Base.Sys.KERNEL) = k in (:Darwin, :Apple)
isbsd(k::Symbol=Base.Sys.KERNEL) = isapple(k) || k in (:FreeBSD, :OpenBSD, :NetBSD, :DragonFly)
islinux(k::Symbol=Base.Sys.KERNEL) = k == :Linux
isunix(k::Symbol=Base.Sys.KERNEL) = isbsd(k) || islinux(k)
iswindows(k::Symbol=Base.Sys.KERNEL) = k in (:Windows, :NT)
else
import Base.Sys: isapple, isbsd, islinux, isunix, iswindows
end
end

end # module Compat
15 changes: 12 additions & 3 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,11 @@ let x = rand(rng, Int64, 3,4)
@test x == rand(rng, Int64, (3,4))
end

extrapath = is_windows() ? joinpath(JULIA_HOME,"..","Git","usr","bin")*";" : ""
extrapath = Compat.Sys.iswindows() ? joinpath(JULIA_HOME,"..","Git","usr","bin")*";" : ""
@compat withenv("PATH" => extrapath * ENV["PATH"]) do
cmd1 = pipeline(`echo hello`, `sort`)
cmd2 = pipeline(`true`, `true`)
if is_windows()
if Compat.Sys.iswindows()
try # use busybox-w32
success(`busybox`)
cmd1 = pipeline(`busybox echo hello`, `busybox sort`)
Expand Down Expand Up @@ -921,7 +921,7 @@ cd(dirwalk) do
touch(joinpath("sub_dir1", "file$i"))
end
touch(joinpath("sub_dir2", "file_dir2"))
has_symlinks = is_unix() ? true : (isdefined(Base, :WINDOWS_VISTA_VER) && Base.windows_version() >= Base.WINDOWS_VISTA_VER)
has_symlinks = Compat.Sys.isunix() ? true : (isdefined(Base, :WINDOWS_VISTA_VER) && Base.windows_version() >= Base.WINDOWS_VISTA_VER)
follow_symlink_vec = has_symlinks ? [true, false] : [false]
has_symlinks && symlink(abspath("sub_dir2"), joinpath("sub_dir1", "link"))
for follow_symlinks in follow_symlink_vec
Expand Down Expand Up @@ -1228,6 +1228,15 @@ end
@test Compat.repeat(1:2, outer=[2]) == [1, 2, 1, 2]
@test Compat.repeat([1,2], inner=(2,)) == [1, 1, 2, 2]

for os in [:apple, :bsd, :linux, :unix, :windows]
from_base = if VERSION >= v"0.7.0-DEV.914"
Expr(:., Expr(:., :Base, Base.Meta.quot(:Sys)), Base.Meta.quot(Symbol("is", os)))
else # VERSION >= v"0.5.0-dev+4267"
Expr(:., :Base, Base.Meta.quot(Symbol("is_", os)))
end
@eval @test Compat.Sys.$(Symbol("is", os))() == $from_base()
end

io = IOBuffer()
@test @compat(get(io, :limit, false)) == false
@test @compat(get(io, :compact, false)) == false
Expand Down

0 comments on commit d0f4b25

Please sign in to comment.