diff --git a/.travis.yml b/.travis.yml index c858dd6..b077f9b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,7 +4,8 @@ os: - linux - osx julia: - - 0.6 + - 0.7 + - nightly notifications: email: false # uncomment the following lines to override the default test script diff --git a/REQUIRE b/REQUIRE index 137767a..4edebbc 100644 --- a/REQUIRE +++ b/REQUIRE @@ -1 +1 @@ -julia 0.6 +julia 0.7.0-alpha diff --git a/appveyor.yml b/appveyor.yml index cfd58c2..8ca2b6a 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,7 +1,7 @@ environment: matrix: - - JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.4/julia-0.4-latest-win32.exe" - - JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.4/julia-0.4-latest-win64.exe" + - JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.7/julia-0.7-latest-win32.exe" + - JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.7/julia-0.7-latest-win64.exe" - JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x86/julia-latest-win32.exe" - JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x64/julia-latest-win64.exe" diff --git a/src/Retry.jl b/src/Retry.jl index cfe1385..c07b733 100644 --- a/src/Retry.jl +++ b/src/Retry.jl @@ -1,10 +1,10 @@ -module Retry - __precompile__(true) +module Retry + export @repeat, @protected, efield, ecode -efield(x, f, default=nothing) = f in fieldnames(x) ? getfield(x, f) : default +efield(x, f, default=nothing) = f in fieldnames(typeof(x)) ? getfield(x, f) : default ecode(x) = efield(x, :code) include("repeat_try.jl") diff --git a/src/protected_try.jl b/src/protected_try.jl index 7dd5a93..9976a4f 100644 --- a/src/protected_try.jl +++ b/src/protected_try.jl @@ -72,7 +72,7 @@ macro protected(try_expr::Expr) end # Check for nothing exception at start of catch block... - unshift!(catch_block.args, :($exception == nothing && rethrow($exception))) + pushfirst!(catch_block.args, :($exception == nothing && rethrow($exception))) # Check rethrow flag at end of catch block... push!(catch_block.args, :($exception == nothing || rethrow($exception))) diff --git a/src/repeat_try.jl b/src/repeat_try.jl index c67fbc6..2555c46 100644 --- a/src/repeat_try.jl +++ b/src/repeat_try.jl @@ -77,56 +77,42 @@ # Check that "expr" is "try ... catch err ... [finalise ...] end" -function check_try_catch(expr, require_exception_variable::Bool) - - @assert expr.head == :try "" * - """Expected "try/catch" expression as argument.""" - - @assert expr.args[3].head == :block - +function check_try_catch(expr::Expr, require_exception_variable::Bool) + if expr.head !== :try + throw(ArgumentError("Expected a `try`/`catch` expression argument")) + end if require_exception_variable - @assert typeof(expr.args[2]) == Symbol "" * - """Expected exception vairable name.""" + expr.args[2] isa Symbol || throw(ArgumentError("Expected exception variable name")) else - if typeof(expr.args[2]) != Symbol + if !isa(expr.args[2], Symbol) @assert expr.args[2] == false expr.args[2] = :err end end - - - return (try_block, exception, catch_block) = expr.args + return (expr.args...,) end # Check that "expr" is "@macrocall if ... end". -function check_macro_if(expr) - - @assert expr.head == :macrocall && - ((length(expr.args) == 2 && # Julia <= 0.6 - typeof(expr.args[2]) == Expr && - expr.args[2].head == :if) || - (length(expr.args) == 3 && # Julia >= 0.7 - typeof(expr.args[2]) == Expr && - typeof(expr.args[3]) == Expr && - expr.args[2].head == :line && - expr.args[3].head == :if)) "" * - """$(expr.args[1]) expects "if" expression as argument.""" - - if_expr = expr.args[end] - - @assert length(if_expr.args) == 2 && - if_expr.args[2].head == :block "" * - """"else" not allowed in $(expr.args[1]) expression.""" - - return if_expr +function check_macro_if(expr::Expr) + if !(expr.head == :macrocall && length(expr.args) == 3) + throw(ArgumentError("Expected macro call with a single expression argument")) + end + (macroname::Symbol, lineinfo::LineNumberNode, ifexpr::Expr) = expr.args + if ifexpr.head !== :if + throw(ArgumentError("$macroname: expecting an `if` expression")) + end + if !(length(ifexpr.args) == 2 && ifexpr.args[2].head == :block) + throw(ArgumentError("$macroname: `else` expression is not allowed")) + end + return ifexpr end function esc_args!(expr::Expr) for (i, arg) in enumerate(expr.args) - if isa(arg, Symbol) || arg.head != :line + if isa(arg, Symbol) || !isa(arg, LineNumberNode) expr.args[i] = esc(arg) end end @@ -185,14 +171,14 @@ macro repeat(max, try_expr::Expr) # Replace @ignore/@retry macro call with modified if expression... catch_block.args[i] = if_expr - elseif expr.head != :line + elseif !isa(expr, LineNumberNode) catch_block.args[i] = esc(expr) end end # Check for nothing exception at start of catch block... insert!(catch_block.args, 2, :($exception == nothing && rethrow())) - unshift!(catch_block.args, :(ignore = false)) + pushfirst!(catch_block.args, :(ignore = false)) # Rethrow at end of catch block... push!(catch_block.args, :(ignore || rethrow($exception))) diff --git a/test/runtests.jl b/test/runtests.jl index e0fc688..87d88ef 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -8,7 +8,7 @@ using Retry -using Base.Test +using Test mutable struct TestException <: Exception