Skip to content

Commit

Permalink
Merge pull request #209 from andreasnoack/anj/osname
Browse files Browse the repository at this point in the history
Add Compat entry for KERNEL
  • Loading branch information
tkelman committed May 25, 2016
2 parents c4920a1 + 85f8862 commit b2bb3ab
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,8 @@ Currently, the `@compat` macro supports the following syntaxes:

* `repeat` now accepts any `AbstractArray` [#14082](https://github.com/JuliaLang/julia/pull/14082): `Compat.repeat` supports this new API on Julia 0.3 and 0.4, and calls `Base.repeat` on 0.5.

* `OS_NAME` is now `Sys.KERNEL`. OS information available as `is_apple`, `is_bsd`, `is_linux`, `is_unix`, and `is_windows`. [16219](https://github.com/JuliaLang/julia/pull/16219)

## New types

* [`Nullable` types](http://julia.readthedocs.org/en/latest/manual/types/?highlight=nullable#nullable-types-representing-missing-values) and their associated operations.
Expand Down
17 changes: 17 additions & 0 deletions src/Compat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1202,4 +1202,21 @@ else
const repeat = Base.repeat
end

if VERSION < v"0.5.0-dev+4267"
if OS_NAME == :Windows
const KERNEL = :NT
else
const KERNEL = OS_NAME
end

@eval is_apple() = $(KERNEL == :Darwin)
@eval is_linux() = $(KERNEL == :Linux)
@eval is_bsd() = $(KERNEL in (:FreeBSD, :OpenBSD, :NetBSD, :Darwin, :Apple))
@eval is_unix() = $(is_linux() || is_bsd())
@eval is_windows() = $(KERNEL == :NT)
export is_apple, is_linux, is_bsd, is_unix, is_windows
else
const KERNEL = Sys.KERNEL
end

end # module
14 changes: 14 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1169,3 +1169,17 @@ end
@test Compat.repeat(1:2, inner=2) == [1, 1, 2, 2]
@test Compat.repeat(1:2, outer=[2]) == [1, 2, 1, 2]
@test Compat.repeat([1,2], inner=(2,)) == [1, 1, 2, 2]

if VERSION < v"0.5.0-dev+4267"
if OS_NAME == :Windows
@test is_windows()
elseif OS_NAME == :Darwin
@test is_apple() && is_bsd() && is_unix()
elseif OS_NAME == :FreeBSD
@test is_bsd() && is_unix()
elseif OS_NAME == :Linux
@test is_linux() && is_unix()
end
else
@test Compat.KERNEL == Sys.KERNEL
end

0 comments on commit b2bb3ab

Please sign in to comment.