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

Support implicit mocking over broadcasted functions #80

Open
glennmoy opened this issue Jun 17, 2020 · 1 comment
Open

Support implicit mocking over broadcasted functions #80

glennmoy opened this issue Jun 17, 2020 · 1 comment

Comments

@glennmoy
Copy link

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
@iamed2
Copy link
Contributor

iamed2 commented Jun 17, 2020

Another way of handling this would be for @mock to find and replace usage of the function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants