Skip to content

Commit acd19fa

Browse files
tkfjw3126
authored andcommitted
Fix some tests and suppress warnings in Julia 0.7 (#31)
* Remove StaticArrays.setindex hack It's included in StaticArrays v0.7.0: JuliaArrays/StaticArrays.jl#370 * Skip test_quicktypes.jl in 0.7 * Use __module__ in Julia 0.7 * "using Test" in Julia 0.7 * Fix deprecated warnings in test_core.jl * Clarify broken tests due to dot-call syntax * Simplify settable macro
1 parent 4d661e8 commit acd19fa

File tree

6 files changed

+46
-15
lines changed

6 files changed

+46
-15
lines changed

src/Setfield.jl

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
__precompile__(true)
22
module Setfield
33

4-
# hack to support static arrays
5-
if Pkg.installed("StaticArrays") != nothing
6-
import StaticArrays
7-
Base.setindex(arr::StaticArrays.StaticArray, args...) = StaticArrays.setindex(arr,args...)
8-
end
9-
104
if isdefined(Base, :getproperty)
115
using Base: getproperty
126
else

src/settable.jl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ export @settable
22
using MacroTools: prewalk, splitdef, combinedef
33

44
macro settable(ex)
5-
esc(settable(ex))
5+
if VERSION < v"0.7-"
6+
__module__ = current_module()
7+
end
8+
esc(settable(__module__, ex))
69
end
710

811
function arg_type(ex)::Tuple
@@ -96,8 +99,7 @@ function add_posonly_constructor(ex::Expr)::Expr
9699
end
97100
end
98101

99-
function settable(code)::Expr
100-
M = current_module()
102+
function settable(M, code)::Expr
101103
code = macroexpand(M, code)
102104
MacroTools.postwalk(code) do ex
103105
ret = if isstructdef(ex)

test/runtests.jl

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,20 @@
11
module TestSetfield
22

3+
@static if VERSION < v"0.7-"
4+
using Base.Test
5+
else
6+
using Test
7+
end
8+
9+
macro test_deprecated07(ex)
10+
if VERSION < v"0.7-"
11+
return esc(ex)
12+
else
13+
return esc(:(Test.@test_deprecated $ex))
14+
end
15+
end
16+
317
using Setfield
4-
using Base.Test
518

619
@testset "core" begin
720
include("test_core.jl")
@@ -22,8 +35,10 @@ end
2235
include("test_kwonly.jl")
2336
end
2437

38+
@static if VERSION < v"0.7-"
2539
@testset "QuickTypes.jl" begin
2640
include("test_quicktypes.jl")
2741
end
42+
end
2843

2944
end # module

test/test_core.jl

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,11 +187,26 @@ end
187187
@test v_init[1] == 2
188188
@test v === v_init
189189

190+
# Julia 0.7 with --depwarn=error:
191+
is_deperror07 = VERSION >= v"0.7-" && Base.JLOptions().depwarn == 2
192+
190193
v = randn(3)
191-
@set! v[:] = 1
194+
# @set! v[:] .= 0 # dot-call not supported
195+
@test_broken v == [0,0,0.]
196+
if is_deperror07
197+
v[:] .= 1
198+
else
199+
v = @test_deprecated07 (@set! v[:] = 1; v)
200+
end
192201
@test v == [1,1,1.]
193-
@set! v[2:3] = 4
202+
if is_deperror07
203+
v[2:3] .= 4
204+
else
205+
v = @test_deprecated07 (@set! v[2:3] = 4; v)
206+
end
194207
@test v == [1,4,4]
208+
# @set! v[1:2] .= 5 # dot-call not supported
209+
@test_broken v == [5,5,4]
195210
end
196211

197212
@testset "@set vs @set!" begin
@@ -253,6 +268,6 @@ end
253268
@testset "show_generic" begin
254269
l = @lens _[1]
255270
s = sprint(Setfield.show_generic,l)
256-
l2 = eval(parse(s))
271+
l2 = eval(Meta.parse(s))
257272
@test l == l2
258273
end

test/test_kwonly.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using Kwonly
2-
using Base.Test
32
using Setfield
43

54
@settable struct AKW

test/test_quicktypes.jl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
module TestQuicktypes
2+
3+
@static if VERSION < v"0.7-"
4+
using Base.Test
5+
else
6+
using Test
7+
end
8+
29
import Base: ==
3-
using Base.Test
410
import MacroTools
511

612
using QuickTypes

0 commit comments

Comments
 (0)