Skip to content
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
1 change: 1 addition & 0 deletions REQUIRE
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
julia 0.4
Compat 0.25
12 changes: 7 additions & 5 deletions src/Mocking.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ __precompile__(true)

module Mocking

import Compat: invokelatest

include("expr.jl")

export @patch, @mock, Patch, apply
Expand Down Expand Up @@ -182,15 +184,15 @@ macro mock(expr)
args_var = gensym("args")

# Note: The fix to Julia issue #265 (PR #17057) introduced changes where no compiled
# calls could be made to functions compiled afterwards. Since the `apply` do block
# syntax compiles the do block function before evaluating the do "outer" function this
# means our patch functions will be compiled after the "inner" function.
# Also note that we need to QuoteNode args_var to handle Symbols in args_var.
# calls could be made to functions compiled afterwards. Since the `Mocking.apply`
# do-block syntax compiles the body of the do-block function before evaluating the
# "outer" function this means our patch functions will be compiled after the "inner"
# function.
result = quote
local $env_var = Mocking.get_active_env()
local $args_var = tuple($(args...))
if Mocking.ismocked($env_var, $func_name, $args_var)
eval(Expr(:call, $env_var.mod.$func, map(QuoteNode, $args_var)...))
Mocking.invokelatest($env_var.mod.$func, $args_var...)
else
$func($args_var...)
end
Expand Down