Skip to content

Commit

Permalink
Merge pull request #10 from invenia/redefinition-fixes
Browse files Browse the repository at this point in the history
Fixes for automatic recompilation of dependent functions
  • Loading branch information
omus authored Dec 23, 2016
2 parents 6329744 + 0944c4c commit 7b7bc78
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/Mocking.jl
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,16 @@ macro mock(expr)
env_var = gensym("env")
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.
result = quote
local $env_var = Mocking.get_active_env()
local $args_var = tuple($(args...))
if Mocking.ismocked($env_var, $func_name, $args_var)
$env_var.mod.$func($args_var...)
eval(Expr(:call, $env_var.mod.$func, map(QuoteNode, $args_var)...))
else
$func($args_var...)
end
Expand Down
2 changes: 1 addition & 1 deletion test/closure.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
let magic
magic(x) = false
sentinel = gensym()
sentinel = gensym("sentinel")
@test magic(sentinel) == false

# Getting closers to work means having a function created in the current scope
Expand Down
2 changes: 1 addition & 1 deletion test/concept.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Mocking.set_active_env(pe)
@test (@mock multiply(0x2)) == 0x4
@test (@mock multiply(2//1)) == 4//1

# Use convienient syntax
# Use convenient syntax
apply(patches) do
@test (@mock multiply(2)) == 8
@test (@mock multiply(0x2)) == 0x6
Expand Down

0 comments on commit 7b7bc78

Please sign in to comment.