diff --git a/.travis.yml b/.travis.yml index 4a4a6cf..99bf245 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,7 +4,6 @@ os: - linux - osx julia: - - 0.6 - nightly notifications: email: false diff --git a/REQUIRE b/REQUIRE index 137767a..4aa321c 100644 --- a/REQUIRE +++ b/REQUIRE @@ -1 +1 @@ -julia 0.6 +julia 0.7- diff --git a/src/ArgCheck.jl b/src/ArgCheck.jl index fdcf84e..bd98592 100644 --- a/src/ArgCheck.jl +++ b/src/ArgCheck.jl @@ -1,5 +1,6 @@ __precompile__() module ArgCheck + using Base.Meta export @argcheck, @check, CheckError diff --git a/src/checks.jl b/src/checks.jl index 7dd7be5..e8e4336 100644 --- a/src/checks.jl +++ b/src/checks.jl @@ -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)) @@ -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 diff --git a/test/checks.jl b/test/checks.jl index 338565b..5a0207f 100644 --- a/test/checks.jl +++ b/test/checks.jl @@ -1,4 +1,5 @@ using ArgCheck: pretty_string + macro catch_exception_object(code) quote err = try @@ -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) @@ -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 @@ -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 @@ -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 diff --git a/test/perf.jl b/test/perf.jl index d1249db..a3c303c 100644 --- a/test/perf.jl +++ b/test/perf.jl @@ -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) @@ -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) diff --git a/test/runtests.jl b/test/runtests.jl index 5813487..44986b6 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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")