Skip to content

Commit

Permalink
fix depwarns (#23)
Browse files Browse the repository at this point in the history
* fix depwarns
  • Loading branch information
jw3126 authored Jun 21, 2018
1 parent 07d7528 commit ac88195
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 49 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ os:
- linux
- osx
julia:
- 0.6
- nightly
notifications:
email: false
Expand Down
2 changes: 1 addition & 1 deletion REQUIRE
Original file line number Diff line number Diff line change
@@ -1 +1 @@
julia 0.6
julia 0.7-
1 change: 1 addition & 0 deletions src/ArgCheck.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
__precompile__()
module ArgCheck

using Base.Meta
export @argcheck, @check, CheckError

Expand Down
4 changes: 2 additions & 2 deletions src/checks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ error_message(info::ComparisonErrorInfo) = fancy_error_message(info)

function pretty_string(data)
io = IOBuffer()
ioc = IOContext(io; limit=true, compact=true)
ioc = IOContext(io, :limit=>true, :compact=>true)
show(ioc, data)
seekstart(io)
String(take!(io))
Expand All @@ -216,6 +216,6 @@ function fancy_error_message(info)
else
"$code must hold. Got"
end
unshift!(lines, firstline)
pushfirst!(lines, firstline)
join(lines, '\n')
end
77 changes: 39 additions & 38 deletions test/checks.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using ArgCheck: pretty_string

macro catch_exception_object(code)
quote
err = try
Expand Down Expand Up @@ -85,32 +86,32 @@ end
err = @catch_exception_object @argcheck x == y MyError
@test err isa MyError
msg = err.msg
@test contains(msg, string(x))
@test contains(msg, string(y))
@test contains(msg, "x")
@test contains(msg, "y")
@test contains(msg, "==")
@test occursin(string(x), msg)
@test occursin(string(y), msg)
@test occursin("x", msg)
@test occursin("y", msg)
@test occursin("==", msg)

x = 1.2
y = 1.34
z = -345.234
err = @catch_exception_object @argcheck x < y < z
msg = err.msg
@test contains(msg, string(z))
@test contains(msg, string(y))
@test contains(msg, "y")
@test contains(msg, "z")
@test contains(msg, "<")
@test !contains(msg, string(x))
@test occursin(string(z), msg)
@test occursin(string(y), msg)
@test occursin("y", msg)
@test occursin("z", msg)
@test occursin("<", msg)
@test !occursin(string(x), msg)

(a,b) = false
err = @catch_exception_object @argcheck x y z
msg = err.msg
@test contains(msg, "x")
@test contains(msg, "y")
@test contains(msg, string(x))
@test contains(msg, string(y))
@test contains(msg, "")
@test occursin("x", msg)
@test occursin("y", msg)
@test occursin(string(x), msg)
@test occursin(string(y), msg)
@test occursin("", msg)

s = randstring()
arr = rand(1000:9999, 1000)
Expand All @@ -119,9 +120,9 @@ end
@test typeof(err) == CheckError
msg = err.msg
@test length(msg) < 2000
@test contains(msg, pretty_string(x))
@test contains(msg, pretty_string(arr))
@test contains(msg, pretty_string(s))
@test occursin(pretty_string(x), msg)
@test occursin(pretty_string(arr), msg)
@test occursin(pretty_string(s), msg)
end

# In
Expand All @@ -134,30 +135,30 @@ let
z = -345.234
err = @catch_exception_object @argcheck falsy([x y; z z])
msg = err.msg
@test contains(msg, string(x))
@test contains(msg, string(z))
@test contains(msg, string(y))
@test contains(msg, "y")
@test contains(msg, "z")
@test contains(msg, "x")
@test contains(msg, "f")
@test occursin(string(x), msg)
@test occursin(string(z), msg)
@test occursin(string(y), msg)
@test occursin("y", msg)
@test occursin("z", msg)
@test occursin("x", msg)
@test occursin("f", msg)

fail_function(args...) = false
err = @catch_exception_object @argcheck fail_function(x,y,z) DimensionMismatch
msg = err.msg

@test err isa DimensionMismatch
@test contains(msg, string(x))
@test contains(msg, string(z))
@test contains(msg, string(y))
@test contains(msg, "y")
@test contains(msg, "z")
@test contains(msg, "x")
@test contains(msg, "Got")
@test contains(msg, "fail_function")
@test occursin(string(x), msg)
@test occursin(string(z), msg)
@test occursin(string(y), msg)
@test occursin("y", msg)
@test occursin("z", msg)
@test occursin("x", msg)
@test occursin("Got", msg)
@test occursin("fail_function", msg)

err = @catch_exception_object @argcheck issorted([2,1])
@test !contains(err.msg, "Got")
@test !occursin("Got", err.msg)
end

@testset "complicated calls" begin
Expand Down Expand Up @@ -196,9 +197,9 @@ end
data = rand(10000:99999, 1000)
str = pretty_string(data)
@test length(str) < 1000
@test contains(str, string(last(data)))
@test contains(str, string(first(data)))
@test !contains(str, "\n")
@test occursin(string(last(data)), str)
@test occursin(string(first(data)),str)
@test !occursin("\n",str)

data = randn()
@test parse(Float64,pretty_string(data)) === data
Expand Down
4 changes: 2 additions & 2 deletions test/perf.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function fallback_argcheck(x)
@argcheck x
end
function comparison_argcheck(x)
@argcheck x == 42
@argcheck x == x
end
function call_argcheck(x)
@argcheck truthy(x)
Expand All @@ -17,7 +17,7 @@ function fallback_assert(x)
@assert x
end
function comparison_assert(x)
@assert x == 42
@assert x == x
end
function call_assert(x)
@assert truthy(x)
Expand Down
8 changes: 3 additions & 5 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
using ArgCheck
if VERSION < v"0.7.0-"
using Base.Test
else
using Test
end

using Test
using Random

include("checks.jl")
include("perf.jl")

0 comments on commit ac88195

Please sign in to comment.