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

Fix test deprecations on 0.7 #560

Merged
merged 8 commits into from
May 30, 2018
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,8 @@ Currently, the `@compat` macro supports the following syntaxes:
* `transcode` converts between UTF-xx string encodings in Julia 0.5 (as a lightweight
alternative to the LegacyStrings package) ([#17323])

* `∘` (typically used infix as `f ∘ g`) for function composition can be used in 0.5 and earlier ([#17155])

* `>:`, a supertype operator for symmetry with `issubtype` (`A >: B` is equivalent to `B <: A`), can be used in 0.5 and earlier ([#20407]).

* The method of `!` to negate functions (typically used as a unary operator, as in `!isinteger`) can be used in 0.5 and earlier ([#17155]).

* `iszero(x)` efficiently checks whether `x == zero(x)` (including arrays) can be used in 0.5 and earlier ([#19950]).

* `.&` and `.|` are short syntax for `broadcast(&, xs...)` and `broadcast(|, xs...)` (respectively) in Julia 0.6 (only supported on Julia 0.5 and above) ([#17623])
Expand Down Expand Up @@ -304,6 +300,8 @@ Currently, the `@compat` macro supports the following syntaxes:
* `Compat.rmul!` provides a subset of the functionality of `LinearAlgebra.rmul!` for
use with Julia 0.6 ([#25701], [#25812]).

* `isbits(t::Type)` is now `isbitstype(t)` ([#26850]).

## Renaming

* `Display` is now `AbstractDisplay` ([#24831]).
Expand Down Expand Up @@ -502,7 +500,6 @@ includes this fix. Find the minimum version from there.
[#13681]: https://github.com/JuliaLang/julia/issues/13681
[#16564]: https://github.com/JuliaLang/julia/issues/16564
[#16986]: https://github.com/JuliaLang/julia/issues/16986
[#17155]: https://github.com/JuliaLang/julia/issues/17155
[#17302]: https://github.com/JuliaLang/julia/issues/17302
[#17323]: https://github.com/JuliaLang/julia/issues/17323
[#17510]: https://github.com/JuliaLang/julia/issues/17510
Expand Down Expand Up @@ -638,4 +635,5 @@ includes this fix. Find the minimum version from there.
[#26486]: https://github.com/JuliaLang/julia/issues/26486
[#26660]: https://github.com/JuliaLang/julia/issues/26660
[#26670]: https://github.com/JuliaLang/julia/issues/26670
[#26850]: https://github.com/JuliaLang/julia/issues/26850
[#27077]: https://github.com/JuliaLang/julia/issues/27077
14 changes: 6 additions & 8 deletions src/Compat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -281,14 +281,6 @@ if VERSION < v"0.6.0-dev.1256"
Base.take!(io::Base.AbstractIOBuffer) = takebuf_array(io)
end

# julia #17155 function composition and negation
@static if VERSION < v"0.6.0-dev.1883"
export ∘
∘(f, g) = (x...)->f(g(x...))
@compat Base.:!(f::Function) = (x...)->!f(x...)
end


if VERSION < v"0.6.0-dev.1632"
# To work around unsupported syntax on Julia 0.4
include_string("export .&, .|")
Expand Down Expand Up @@ -1871,6 +1863,12 @@ end
const isletter = isalpha
end

# https://github.com/JuliaLang/julia/pull/26850
if !isdefined(Base, :isbitstype) # 0.7.0-DEV.4905
export isbitstype
isbitstype(::Type{T}) where {T} = isbits(T)
end

# 0.7.0-DEV.4762
@static if !isdefined(Base, Symbol("@cfunction"))
macro cfunction(f, rt, tup)
Expand Down
52 changes: 28 additions & 24 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -199,19 +199,26 @@ end
@test @__DIR__() == dirname(@__FILE__)

# PR #17302
# To be removed when 0.5/0.6 support is dropped.
# To be removed when 0.6 support is dropped.
f17302(a::Number) = a
f17302(a::Number, b::Number) = a + b
Compat.@dep_vectorize_1arg Real f17302
Compat.@dep_vectorize_2arg Real f17302
@test_throws MethodError f17302([1im])
@test_throws MethodError f17302([1im], [1im])
mktemp() do fname, f
redirect_stderr(f) do
@test f17302([1.0]) == [1.0]
@test f17302(1.0, [1]) == [2.0]
@test f17302([1.0], 1) == [2.0]
@test f17302([1.0], [1]) == [2.0]
@static if VERSION ≥ v"0.7.0-DEV.2988"
@test (@test_logs (:warn, "`f17302(x::(Base.AbstractArray){T}) where T <: Real` is deprecated, use `f17302.(x)` instead.") f17302([1.0])) == [1.0]
@test (@test_logs (:warn, "`f17302(x::Real, y::(Base.AbstractArray){T1}) where T1 <: Real` is deprecated, use `f17302.(x, y)` instead.") f17302(1.0, [1])) == [2.0]
@test (@test_logs (:warn, "`f17302(x::(Base.AbstractArray){T1}, y::Real) where T1 <: Real` is deprecated, use `f17302.(x, y)` instead.") f17302([1.0], 1)) == [2.0]
@test (@test_logs (:warn, "`f17302(x::(Base.AbstractArray){T1}, y::(Base.AbstractArray){T2}) where {T1 <: Real, T2 <: Real}` is deprecated, use `f17302.(x, y)` instead.") f17302([1.0], [1])) == [2.0]
else
mktemp() do fname, f
redirect_stderr(f) do
@test f17302([1.0]) == [1.0]
@test f17302(1.0, [1]) == [2.0]
@test f17302([1.0], 1) == [2.0]
@test f17302([1.0], [1]) == [2.0]
end
end
end

Expand Down Expand Up @@ -323,13 +330,6 @@ let s = "Koala test: 🐨"
end
end

# julia#17155, tests from Base Julia
@test (Compat.Unicode.uppercase∘hex)(239487) == "3A77F"
let str = "aBcDeFgHiJ"
@test filter(!Compat.Unicode.isupper, str) == replace(str, r"[A-Z]" => "")
@test filter(!Compat.Unicode.islower, str) == replace(str, r"[a-z]" => "")
end

# julia#19950, tests from Base (#20028)
for T in (Float16, Float32, Float64, BigFloat, Int8, Int16, Int32, Int64, Int128,
BigInt, UInt8, UInt16, UInt32, UInt64, UInt128)
Expand Down Expand Up @@ -434,15 +434,15 @@ let X = reshape(1:24,2,3,4), Y = 4:-1:1
@test isa(x[1:3],SubArray)
@test x[2] === 11
@test Dict((1:3) => 4)[1:3] === 4
x[1:2] = 0
x[1:2] .= 0
@test x == [0,0,19,4]
x[1:2] .= 5:6
@test x == [5,6,19,4]
f!(x[3:end])
@test x == [5,6,35,4]
x[Y[2:3]] .= 7:8
@test x == [5,8,7,4]
@dotcompat x[(3,)..., ()...] += 3 # @. should convert to .+=, test compatibility with @views
@dotcompat x[([3],)..., ()...] += 3 # @. should convert to .+=, test compatibility with @views
@test x == [5,8,10,4]
i = Int[]
# test that lhs expressions in update operations are evaluated only once:
Expand All @@ -461,15 +461,15 @@ let X = reshape(1:24,2,3,4), Y = 4:-1:1
@test isa(x[1:3],SubArray)
@test x[2] === 11
@test Dict((1:3) => 4)[1:3] === 4
x[1:2] = 0
x[1:2] .= 0
@test x == [0,0,19,4]
x[1:2] .= 5:6
@test x == [5,6,19,4]
f!(x[3:end])
@test x == [5,6,35,4]
x[Y[2:3]] .= 7:8
@test x == [5,8,7,4]
@dotcompat x[(3,)..., ()...] += 3 # @. should convert to .+=, test compatibility with @views
@dotcompat x[([3],)..., ()...] += 3 # @. should convert to .+=, test compatibility with @views
@test x == [5,8,10,4]
i = Int[]
# test that lhs expressions in update operations are evaluated only once:
Expand Down Expand Up @@ -520,7 +520,7 @@ end
@test Compat.TypeUtils.isabstract(Abstract20418)
@compat primitive type Primitive20418{T} <: Ref{T} 16 end
@test !Compat.TypeUtils.isabstract(Primitive20418)
@test isbits(Primitive20418{Int})
@test isbitstype(Primitive20418{Int})
@test sizeof(Primitive20418{Int}) == 2

# PR #20500
Expand Down Expand Up @@ -1083,8 +1083,8 @@ end
@test occursin('W', "Hello, World!")

# 0.7.0-DEV.3449
let A = [2.0 1.0; 1.0 3.0], b = [1.0, 2.0], x = [0.2, 0.6]
@test cholfact(A) \ b ≈ x
let A = [2.0 1.0; 1.0 3.0], b = [2.0, 3.0]
@test diag(A) == b
end

# 0.7.0-DEV.3173
Expand Down Expand Up @@ -1120,7 +1120,7 @@ x = Compat.Dates.Second(172799)
@test round(x, Compat.Dates.Second) == Compat.Dates.Second(172799)
@test round(x, Compat.Dates.Millisecond) == Compat.Dates.Millisecond(172799000)

x = Dates.Nanosecond(2000999999)
x = Compat.Dates.Nanosecond(2000999999)
@test floor(x, Compat.Dates.Second) == Compat.Dates.Second(2)
@test floor(x, Compat.Dates.Millisecond) == Compat.Dates.Millisecond(2000)
@test floor(x, Compat.Dates.Microsecond) == Compat.Dates.Microsecond(2000999)
Expand Down Expand Up @@ -1151,7 +1151,7 @@ x = Compat.Dates.Hour(36)
@test_throws DomainError round(x, Compat.Dates.Day, RoundNearest)
@test_throws DomainError round(x, Compat.Dates.Day, RoundNearestTiesAway)
@test_throws DomainError round(x, Compat.Dates.Day, RoundToZero)
@test round(x, Dates.Day) == round(x, Compat.Dates.Day, RoundNearestTiesUp)
@test round(x, Compat.Dates.Day) == round(x, Compat.Dates.Day, RoundNearestTiesUp)

x = Compat.Dates.Hour(86399)
for p in [Compat.Dates.Week, Compat.Dates.Day, Compat.Dates.Hour, Compat.Dates.Second, Compat.Dates.Millisecond, Compat.Dates.Microsecond, Compat.Dates.Nanosecond]
Expand All @@ -1172,7 +1172,7 @@ for p in [Compat.Dates.Year, Compat.Dates.Month]
end

# 0.7.0-DEV.3025
let c = CartesianIndices(1:3, 1:2), l = LinearIndices(1:3, 1:2)
let c = CartesianIndices((1:3, 1:2)), l = LinearIndices((1:3, 1:2))
@test LinearIndices(c) == collect(l)
@test CartesianIndices(l) == collect(c)
@test first(c) == CartesianIndex(1, 1)
Expand Down Expand Up @@ -1732,6 +1732,10 @@ end
@test isletter('β')
@test !isletter('3')

# 0.7.0-DEV.4905
@test isbitstype(Int)
@test !isbitstype(Vector{Int})

# 0.7.0-DEV.4762
let ptr = @cfunction(+, Int, (Int, Int))
@test ptr isa Ptr{Cvoid}
Expand Down