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

Tweaks to tests (mmap robustness, don't use at-test_throw return type) #13090

Merged
merged 2 commits into from
Sep 12, 2015
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
28 changes: 19 additions & 9 deletions test/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3109,15 +3109,25 @@ Base.convert(::Type{Foo11874},x::Int) = float(x)

# issue #9233
let
err = @test_throws TypeError NTuple{Int, 1}
@test err.func == :NTuple
@test err.expected == Int
@test err.got == Int

err = @test_throws TypeError NTuple{0x1, Int}
@test err.func == :NTuple
@test err.expected == Int
@test err.got == 0x1
try
NTuple{Int, 1}
@test false
catch err
@test isa(err, TypeError)
@test err.func == :NTuple
@test err.expected == Int
@test err.got == Int
end

try
NTuple{0x1, Int}
@test false
catch err
@test isa(err, TypeError)
@test err.func == :NTuple
@test err.expected == Int
@test err.got == 0x1
end
end

# 11996
Expand Down
38 changes: 25 additions & 13 deletions test/misc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,13 @@ let res = assert(true)
@test res === nothing
end
let
ex = @test_throws AssertionError begin
try
assert(false)
error("unexpected")
catch ex
@test isa(ex, AssertionError)
@test isempty(ex.msg)
end
@test isempty(ex.msg)
end

# test @assert macro
Expand All @@ -48,44 +50,54 @@ end
@test_throws AssertionError (@assert false "this is a test" "another test")
@test_throws AssertionError (@assert false :a)
let
ex = @test_throws AssertionError begin
try
@assert 1 == 2
error("unexpected")
catch ex
@test isa(ex, AssertionError)
@test contains(ex.msg, "1 == 2")
end
@test contains(ex.msg, "1 == 2")
end
# test @assert message
let
ex = @test_throws AssertionError begin
try
@assert 1 == 2 "this is a test"
error("unexpected")
catch ex
@test isa(ex, AssertionError)
@test ex.msg == "this is a test"
end
@test ex.msg == "this is a test"
end
# @assert only uses the first message string
let
ex = @test_throws AssertionError begin
try
@assert 1 == 2 "this is a test" "this is another test"
error("unexpected")
catch ex
@test isa(ex, AssertionError)
@test ex.msg == "this is a test"
end
@test ex.msg == "this is a test"
end
# @assert calls string() on second argument
let
ex = @test_throws AssertionError begin
try
@assert 1 == 2 :random_object
error("unexpected")
catch ex
@test isa(ex, AssertionError)
@test !contains(ex.msg, "1 == 2")
@test contains(ex.msg, "random_object")
end
@test !contains(ex.msg, "1 == 2")
@test contains(ex.msg, "random_object")
end
# if the second argument is an expression, c
let deepthought(x, y) = 42
ex = @test_throws AssertionError begin
try
@assert 1 == 2 string("the answer to the ultimate question: ",
deepthought(6, 9))
catch ex
@test isa(ex, AssertionError)
@test ex.msg == "the answer to the ultimate question: 42"
end
@test ex.msg == "the answer to the ultimate question: 42"
end

let # test the process title functions, issue #9957
Expand Down
48 changes: 25 additions & 23 deletions test/mmap.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@ s = open(file, "w") do f
end
t = "Hello World".data
@test Mmap.mmap(file, Array{UInt8,3}, (11,1,1)) == reshape(t,(11,1,1))
gc()
gc(); gc()
@test Mmap.mmap(file, Array{UInt8,3}, (1,11,1)) == reshape(t,(1,11,1))
gc()
gc(); gc()
@test Mmap.mmap(file, Array{UInt8,3}, (1,1,11)) == reshape(t,(1,1,11))
gc()
gc(); gc()
@test_throws ArgumentError Mmap.mmap(file, Array{UInt8,3}, (11,0,1)) # 0-dimension results in len=0
@test Mmap.mmap(file, Vector{UInt8}, (11,)) == t
gc()
gc(); gc()
@test Mmap.mmap(file, Array{UInt8,2}, (1,11)) == t'
gc()
gc(); gc()
@test_throws ArgumentError Mmap.mmap(file, Array{UInt8,2}, (0,12))
m = Mmap.mmap(file, Array{UInt8,3}, (1,2,1))
@test m == reshape("He".data,(1,2,1))
m=nothing; gc()
finalize(m); m=nothing; gc()

# constructors
@test length(Mmap.mmap(file)) == 12
Expand All @@ -45,15 +45,15 @@ s = open(file)
@test length(Mmap.mmap(s, Vector{Int8}, 12, 0; shared=false)) == 12
close(s)
@test_throws ErrorException Mmap.mmap(file, Vector{Ref}) # must be bit-type
gc()
gc(); gc()

s = open(f->f,file,"w")
@test_throws ArgumentError Mmap.mmap(file) # requested len=0 on empty file
@test_throws ArgumentError Mmap.mmap(file,Vector{UInt8},0)
m = Mmap.mmap(file,Vector{UInt8},12)
m[:] = "Hello World\n".data
Mmap.sync!(m)
m=nothing; gc()
finalize(m); m=nothing; gc()
@test open(readall,file) == "Hello World\n"

s = open(file, "r")
Expand All @@ -70,30 +70,30 @@ close(s)
for i = 0x01:0x0c
@test length(Mmap.mmap(file, Vector{UInt8}, i)) == Int(i)
end
gc()
gc(); gc()

sz = filesize(file)
m = Mmap.mmap(file, Vector{UInt8}, sz+1)
@test length(m) == sz+1 # test growing
@test m[end] == 0x00
m=nothing; gc()
finalize(m); m=nothing; gc()
sz = filesize(file)
m = Mmap.mmap(file, Vector{UInt8}, 1, sz)
@test length(m) == 1
@test m[1] == 0x00
m=nothing; gc()
finalize(m); m=nothing; gc()
sz = filesize(file)
# test where offset is actually > than size of file; file is grown with zeroed bytes
m = Mmap.mmap(file, Vector{UInt8}, 1, sz+1)
@test length(m) == 1
@test m[1] == 0x00
m=nothing; gc()
finalize(m); m=nothing; gc()

# Uncomment out once #11351 is resolved
# s = open(file, "r")
# m = Mmap.mmap(s)
# @test_throws ReadOnlyMemoryError m[5] = Vector{UInt8}('x') # tries to setindex! on read-only array
# m=nothing; gc()
# finalize(m); m=nothing; gc()

s = open(file, "w") do f
write(f, "Hello World\n")
Expand All @@ -102,7 +102,7 @@ end
s = open(file, "r")
m = Mmap.mmap(s)
close(s)
m=nothing; gc()
finalize(m); m=nothing; gc()
m = Mmap.mmap(file)
s = open(file, "r+")
c = Mmap.mmap(s)
Expand All @@ -112,6 +112,7 @@ Mmap.sync!(c)
close(s)
@test m[1] == UInt8('J')
@test d[1] == UInt8('J')
finalize(m); finalize(c); finalize(d)
m=nothing; c=nothing; d=nothing; gc()

s = open(file, "w") do f
Expand All @@ -122,10 +123,10 @@ s = open(file, "r")
@test isreadonly(s) == true
c = Mmap.mmap(s, Vector{UInt8}, (11,))
@test c == "Hello World".data
c=nothing; gc()
finalize(c); c=nothing; gc()
c = Mmap.mmap(s, Vector{UInt8}, (UInt16(11),))
@test c == "Hello World".data
c=nothing; gc()
finalize(c); c=nothing; gc()
@test_throws ArgumentError Mmap.mmap(s, Vector{UInt8}, (Int16(-11),))
@test_throws ArgumentError Mmap.mmap(s, Vector{UInt8}, (typemax(UInt),))
close(s)
Expand All @@ -139,22 +140,22 @@ s = open(file, "r")
str = readline(s)
close(s)
@test startswith(str, "Hellx World")
c=nothing; gc()
finalize(c); c=nothing; gc()

c = Mmap.mmap(file)
@test c == "Hellx World\n".data
c=nothing; gc()
finalize(c); c=nothing; gc()
c = Mmap.mmap(file, Vector{UInt8}, 3)
@test c == "Hel".data
c=nothing; gc()
finalize(c); c=nothing; gc()
s = open(file, "r")
c = Mmap.mmap(s, Vector{UInt8}, 6)
@test c == "Hellx ".data
close(s)
c=nothing; gc()
finalize(c); c=nothing; gc()
c = Mmap.mmap(file, Vector{UInt8}, 5, 6)
@test c == "World".data
c=nothing; gc()
finalize(c); c=nothing; gc()

s = open(file, "w")
write(s, "Hello World\n")
Expand All @@ -167,7 +168,7 @@ for i = 1:12
@test m[i] == t.data[i]
end
@test_throws BoundsError m[13]
m=nothing; gc()
finalize(m); m=nothing; gc()

m = Mmap.mmap(file,Vector{UInt8},6)
@test m[1] == "H".data[1]
Expand All @@ -177,7 +178,7 @@ m = Mmap.mmap(file,Vector{UInt8},6)
@test m[5] == "o".data[1]
@test m[6] == " ".data[1]
@test_throws BoundsError m[7]
m=nothing; gc()
finalize(m); m=nothing; gc()

m = Mmap.mmap(file,Vector{UInt8},2,6)
@test m[1] == "W".data[1]
Expand Down Expand Up @@ -283,3 +284,4 @@ n = similar(m, (2,2))
n = similar(m, 12)
@test length(n) == 12
@test size(n) == (12,)
finalize(m); m = nothing; gc()