Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for automatic recompilation of dependent functions #10

Merged
merged 1 commit into from
Dec 23, 2016
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
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