diff --git a/src/Mocking.jl b/src/Mocking.jl index 526d834..054c3b3 100644 --- a/src/Mocking.jl +++ b/src/Mocking.jl @@ -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 diff --git a/test/closure.jl b/test/closure.jl index 4e29116..e190060 100644 --- a/test/closure.jl +++ b/test/closure.jl @@ -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 diff --git a/test/concept.jl b/test/concept.jl index a49925d..45a4c7d 100644 --- a/test/concept.jl +++ b/test/concept.jl @@ -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