Skip to content

Commit 6b6dfc9

Browse files
authored
Merge pull request #307 from JuliaLang/anj/06
Fix Compat on master by updating walkdir
2 parents 586d784 + 64f9b01 commit 6b6dfc9

File tree

4 files changed

+59
-53
lines changed

4 files changed

+59
-53
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ Currently, the `@compat` macro supports the following syntaxes:
108108

109109
* `Compat.isapprox` with `nans` keyword argument [#20022](https://github.com/JuliaLang/julia/pull/20022)
110110

111+
* `take!` method for `Task`s since some functions now return `Channel`s instead of `Task`s [#19841](https://github.com/JuliaLang/julia/pull/19841).
112+
111113
## Renamed functions
112114

113115
* `pointer_to_array` and `pointer_to_string` have been replaced with `unsafe_wrap(Array, ...)` and `unsafe_wrap(String, ...)` respectively

appveyor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ install:
3434
build_script:
3535
# Need to convert from shallow to complete for Pkg.clone to work
3636
- IF EXIST .git\shallow (git fetch --unshallow)
37-
- C:\projects\julia\bin\julia -F -e "versioninfo();
37+
- C:\projects\julia\bin\julia -e "versioninfo();
3838
Pkg.clone(pwd(), \"Compat\"); Pkg.build(\"Compat\")"
3939

4040
test_script:

src/Compat.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,9 @@ if VERSION < v"0.5.0-dev+961"
194194
Task(_it)
195195
end
196196
end
197+
if VERSION < v"0.6.0-dev.2043"
198+
Base.take!(t::Task) = consume(t)
199+
end
197200

198201
function rewrite_show(ex)
199202
if isexpr(ex, :call)

test/runtests.jl

Lines changed: 53 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -101,32 +101,35 @@ end
101101
@test round(Int, 3//4) == 1
102102
@test round(Int, 1) == 1
103103
@test round(Int, 1.1) == 1
104-
@test round(Int, [1, 1]) == [1, 1]
105-
@test round(Int, [1.1, 1.1]) == [1, 1]
106-
@test round(Int, [1 1]) == [1 1]
107-
@test round(Int, [1.1 1.1]) == [1 1]
108-
@test round(Int, fill(1.1, 2, 3, 4)) == fill(1, 2, 3, 4)
109104
@test ceil(Int, 1) == 1
110105
@test ceil(Int, 1.1) == 2
111-
@test ceil(Int, [1, 1]) == [1, 1]
112-
@test ceil(Int, [1.1, 1.1]) == [2, 2]
113-
@test ceil(Int, [1 1]) == [1 1]
114-
@test ceil(Int, [1.1 1.1]) == [2 2]
115-
@test ceil(Int, fill(1.1, 2, 3, 4)) == fill(2, 2, 3, 4)
116106
@test floor(Int, 1) == 1
117107
@test floor(Int, 1.1) == 1
118-
@test floor(Int, [1, 1]) == [1, 1]
119-
@test floor(Int, [1.1, 1.1]) == [1, 1]
120-
@test floor(Int, [1 1]) == [1 1]
121-
@test floor(Int, [1.1 1.1]) == [1 1]
122-
@test floor(Int, fill(1.1, 2, 3, 4)) == fill(1, 2, 3, 4)
123108
@test trunc(Int, 1) == 1
124109
@test trunc(Int, 1.1) == 1
125-
@test trunc(Int, [1, 1]) == [1, 1]
126-
@test trunc(Int, [1.1, 1.1]) == [1, 1]
127-
@test trunc(Int, [1 1]) == [1 1]
128-
@test trunc(Int, [1.1 1.1]) == [1 1]
129-
@test trunc(Int, fill(1.1, 2, 3, 4)) == fill(1, 2, 3, 4)
110+
111+
if VERSION < v"0.6.0-dev.1825"
112+
@test round(Int, [1, 1]) == [1, 1]
113+
@test round(Int, [1.1, 1.1]) == [1, 1]
114+
@test round(Int, [1 1]) == [1 1]
115+
@test round(Int, [1.1 1.1]) == [1 1]
116+
@test round(Int, fill(1.1, 2, 3, 4)) == fill(1, 2, 3, 4)
117+
@test ceil(Int, [1, 1]) == [1, 1]
118+
@test ceil(Int, [1.1, 1.1]) == [2, 2]
119+
@test ceil(Int, [1 1]) == [1 1]
120+
@test ceil(Int, [1.1 1.1]) == [2 2]
121+
@test ceil(Int, fill(1.1, 2, 3, 4)) == fill(2, 2, 3, 4)
122+
@test floor(Int, [1, 1]) == [1, 1]
123+
@test floor(Int, [1.1, 1.1]) == [1, 1]
124+
@test floor(Int, [1 1]) == [1 1]
125+
@test floor(Int, [1.1 1.1]) == [1 1]
126+
@test floor(Int, fill(1.1, 2, 3, 4)) == fill(1, 2, 3, 4)
127+
@test trunc(Int, [1, 1]) == [1, 1]
128+
@test trunc(Int, [1.1, 1.1]) == [1, 1]
129+
@test trunc(Int, [1 1]) == [1 1]
130+
@test trunc(Int, [1.1 1.1]) == [1 1]
131+
@test trunc(Int, fill(1.1, 2, 3, 4)) == fill(1, 2, 3, 4)
132+
end
130133

131134
# n % Type
132135
for T in Any[Int16, Int32, UInt32, Int64, UInt64]
@@ -575,9 +578,6 @@ for T = (Float32, Float64)
575578
@test [Compat.linspace(-u,-u,1);] == [-u]
576579
@test [Compat.linspace(-u,u,2);] == [-u,u]
577580
@test [Compat.linspace(-u,u,3);] == [-u,0,u]
578-
@test [Compat.linspace(-u,u,4);] == [-u,0,0,u]
579-
@test [Compat.linspace(-u,u,4);][2] === -z
580-
@test [Compat.linspace(-u,u,4);][3] === z
581581
@test first(Compat.linspace(-u,-u,0)) == -u
582582
@test last(Compat.linspace(-u,-u,0)) == -u
583583
@test first(Compat.linspace(u,-u,0)) == u
@@ -586,12 +586,8 @@ for T = (Float32, Float64)
586586
@test [Compat.linspace(u,u,1);] == [u]
587587
@test [Compat.linspace(u,-u,2);] == [u,-u]
588588
@test [Compat.linspace(u,-u,3);] == [u,0,-u]
589-
@test [Compat.linspace(u,-u,4);] == [u,0,0,-u]
590-
@test [Compat.linspace(u,-u,4);][2] === z
591-
@test [Compat.linspace(u,-u,4);][3] === -z
592589
v = [Compat.linspace(-u,u,12);]
593590
@test length(v) == 12
594-
@test issorted(v) && unique(v) == [-u,0,0,u]
595591
@test [-3u:u:3u;] == [Compat.linspace(-3u,3u,7);] == [-3:3;].*u
596592
@test [3u:-u:-3u;] == [Compat.linspace(3u,-3u,7);] == [3:-1:-3;].*u
597593
end
@@ -981,29 +977,29 @@ cd(dirwalk) do
981977
follow_symlink_vec = has_symlinks ? [true, false] : [false]
982978
has_symlinks && symlink(abspath("sub_dir2"), joinpath("sub_dir1", "link"))
983979
for follow_symlinks in follow_symlink_vec
984-
task = walkdir(".", follow_symlinks=follow_symlinks)
985-
root, dirs, files = consume(task)
980+
chnl = walkdir(".", follow_symlinks=follow_symlinks)
981+
root, dirs, files = take!(chnl)
986982
@test root == "."
987983
@test dirs == ["sub_dir1", "sub_dir2"]
988984
@test files == ["file1", "file2"]
989985

990-
root, dirs, files = consume(task)
986+
root, dirs, files = take!(chnl)
991987
@test root == joinpath(".", "sub_dir1")
992988
@test dirs == (has_symlinks ? ["link", "subsub_dir1", "subsub_dir2"] : ["subsub_dir1", "subsub_dir2"])
993989
@test files == ["file1", "file2"]
994990

995-
root, dirs, files = consume(task)
991+
root, dirs, files = take!(chnl)
996992
if follow_symlinks
997993
@test root == joinpath(".", "sub_dir1", "link")
998994
@test dirs == []
999995
@test files == ["file_dir2"]
1000-
root, dirs, files = consume(task)
996+
root, dirs, files = take!(chnl)
1001997
end
1002998
for i=1:2
1003999
@test root == joinpath(".", "sub_dir1", "subsub_dir$i")
10041000
@test dirs == []
10051001
@test files == []
1006-
root, dirs, files = consume(task)
1002+
root, dirs, files = take!(chnl)
10071003
end
10081004

10091005
@test root == joinpath(".", "sub_dir2")
@@ -1012,51 +1008,51 @@ cd(dirwalk) do
10121008
end
10131009

10141010
for follow_symlinks in follow_symlink_vec
1015-
task = walkdir(".", follow_symlinks=follow_symlinks, topdown=false)
1016-
root, dirs, files = consume(task)
1011+
chnl = walkdir(".", follow_symlinks=follow_symlinks, topdown=false)
1012+
root, dirs, files = take!(chnl)
10171013
if follow_symlinks
10181014
@test root == joinpath(".", "sub_dir1", "link")
10191015
@test dirs == []
10201016
@test files == ["file_dir2"]
1021-
root, dirs, files = consume(task)
1017+
root, dirs, files = take!(chnl)
10221018
end
10231019
for i=1:2
10241020
@test root == joinpath(".", "sub_dir1", "subsub_dir$i")
10251021
@test dirs == []
10261022
@test files == []
1027-
root, dirs, files = consume(task)
1023+
root, dirs, files = take!(chnl)
10281024
end
10291025
@test root == joinpath(".", "sub_dir1")
10301026
@test dirs == (has_symlinks ? ["link", "subsub_dir1", "subsub_dir2"] : ["subsub_dir1", "subsub_dir2"])
10311027
@test files == ["file1", "file2"]
10321028

1033-
root, dirs, files = consume(task)
1029+
root, dirs, files = take!(chnl)
10341030
@test root == joinpath(".", "sub_dir2")
10351031
@test dirs == []
10361032
@test files == ["file_dir2"]
10371033

1038-
root, dirs, files = consume(task)
1034+
root, dirs, files = take!(chnl)
10391035
@test root == "."
10401036
@test dirs == ["sub_dir1", "sub_dir2"]
10411037
@test files == ["file1", "file2"]
10421038
end
10431039
#test of error handling
1044-
task_error = walkdir(".")
1045-
task_noerror = walkdir(".", onerror=x->x)
1046-
root, dirs, files = consume(task_error)
1040+
chnl_error = walkdir(".")
1041+
chnl_noerror = walkdir(".", onerror=x->x)
1042+
root, dirs, files = take!(chnl_error)
10471043
@test root == "."
10481044
@test dirs == ["sub_dir1", "sub_dir2"]
10491045
@test files == ["file1", "file2"]
10501046

10511047
rm(joinpath("sub_dir1"), recursive=true)
1052-
@test_throws SystemError consume(task_error) # throws an error because sub_dir1 do not exist
1048+
@test_throws SystemError take!(chnl_error) # throws an error because sub_dir1 do not exist
10531049

1054-
root, dirs, files = consume(task_noerror)
1050+
root, dirs, files = take!(chnl_noerror)
10551051
@test root == "."
10561052
@test dirs == ["sub_dir1", "sub_dir2"]
10571053
@test files == ["file1", "file2"]
10581054

1059-
root, dirs, files = consume(task_noerror) # skips sub_dir1 as it no longer exist
1055+
root, dirs, files = take!(chnl_noerror) # skips sub_dir1 as it no longer exist
10601056
@test root == joinpath(".", "sub_dir2")
10611057
@test dirs == []
10621058
@test files == ["file_dir2"]
@@ -1164,10 +1160,13 @@ end
11641160
let a = rand(1:10, 10)
11651161
@test mapreduce(identity, dot, a) == mapreduce(identity, @functorize(dot), a)
11661162
end
1167-
@test isa(@functorize(centralizedabs2fun)(1), @functorize(centralizedabs2fun))
1168-
@test isa(@functorize(centralizedabs2fun)(1.0), @functorize(centralizedabs2fun))
1169-
let a = rand(1:10, 10)
1170-
@eval @test mapreduce(x -> abs2(x - 1), +, $(a)) == mapreduce(@functorize(centralizedabs2fun)(1), +, $(a))
1163+
1164+
if VERSION < v"0.6.0-dev.2521"
1165+
@test isa(@functorize(centralizedabs2fun)(1), @functorize(centralizedabs2fun))
1166+
@test isa(@functorize(centralizedabs2fun)(1.0), @functorize(centralizedabs2fun))
1167+
let a = rand(1:10, 10)
1168+
@eval @test mapreduce(x -> abs2(x - 1), +, $(a)) == mapreduce(@functorize(centralizedabs2fun)(1), +, $(a))
1169+
end
11711170
end
11721171

11731172
# Threads.@threads
@@ -1190,7 +1189,7 @@ let x = rand(3), y = rand(3)
11901189
@test @compat(sin.(cos.(x))) == map(x -> sin(cos(x)), x)
11911190
@test @compat(atan2.(sin.(y),x)) == broadcast(atan2,map(sin,y),x)
11921191
end
1193-
let x0 = Array(Float64), v, v0
1192+
let x0 = Array{Float64}(), v, v0
11941193
x0[1] = rand()
11951194
v0 = @compat sin.(x0)
11961195
@test isa(v0, Array{Float64,0})
@@ -1334,8 +1333,10 @@ end
13341333
@test allunique([1, 2, 3])
13351334
@test !allunique([1, 2, 1])
13361335
@test allunique(1:3)
1337-
@test allunique(FloatRange(0.0, 0.0, 0.0, 1.0))
1338-
@test !allunique(FloatRange(0.0, 0.0, 2.0, 1.0))
1336+
if VERSION < v"0.6.0-dev.2390"
1337+
@test allunique(FloatRange(0.0, 0.0, 0.0, 1.0))
1338+
@test !allunique(FloatRange(0.0, 0.0, 2.0, 1.0))
1339+
end
13391340

13401341
# Add test for Base.view
13411342
let a = rand(10,10)

0 commit comments

Comments
 (0)