Mocking.jl
Mocking.jl copied to clipboard
Support implicit mocking over broadcasted functions
For some foo(x)
, mocking does not support the broadcasted expression:
julia> foo(x) = # do stuff
julia> function bar(X)
return @mock foo.(X)
end
ERROR: LoadError: expression is not a function call
Stacktrace:
[1] error(::String) at ./error.jl:33
[2] @mock(::LineNumberNode, ::Module, ::Any) at /Users/glenn/.julia/packages/Mocking/U41JO/src/mock.jl:6
in expression starting at REPL[8]:2
So one needs to call broadcast
explicitly in the function call and in the patch:
function bar(X)
return @mock broadcast(foo, X)
end
# currently works
patch = @patch broadcast(foo, X) = # do stuff
Whereas it would be nice if the patch for unbroadcasted foo
could also implicitly handle the broadcasted case so one then doesn't have to create two different patches:
function bar(X)
return @mock foo.(X)
end
# should work for @mock foo(x) and @mock foo.(X)
patch = @patch f(x) = # do stuff
Another way of handling this would be for @mock
to find and replace usage of the function.