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

Add Sys.is<os> #380

Merged
merged 1 commit into from
Jul 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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