Skip to content

Commit

Permalink
Merge pull request #34 from invenia/cv/julia-0.7-errors
Browse files Browse the repository at this point in the history
Address some Julia 0.7 syntax changes
  • Loading branch information
omus authored Jan 11, 2018
2 parents 742aeca + d976aa9 commit 3f133f3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/Mocking.jl
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,11 @@ function convert(::Type{Expr}, p::Patch)

# Generate imports for all required modules
for (i, m) in enumerate(p.modules)
exprs[i] = Expr(:import, splitbinding(m)...)
if VERSION > v"0.7.0-DEV.3187"
exprs[i] = Expr(:import, Expr(:., splitbinding(m)...))
else
exprs[i] = Expr(:import, splitbinding(m)...)
end
end

# Generate the new method which will call the user's patch function. We need to perform
Expand Down Expand Up @@ -201,6 +205,7 @@ get_active_env() = PATCH_ENV::PatchEnv

macro mock(expr)
isa(expr, Expr) || error("argument is not an expression")
expr.head == :do && (expr = rewrite_do(expr))
expr.head == :call || error("expression is not a function call")
ENABLED::Bool || return esc(expr) # @mock is a no-op when Mocking is not ENABLED

Expand Down
7 changes: 7 additions & 0 deletions src/expr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,10 @@ function call_parameters(expr::Expr)
end
return positional
end

# New do-block syntax introduced in: https://github.com/JuliaLang/julia/pull/23718
function rewrite_do(expr::Expr)
expr.head == :do || error("expression is not a do-block")
call, body = expr.args
Expr(:call, call.args[1], body, call.args[2:end]...)
end

0 comments on commit 3f133f3

Please sign in to comment.