Skip to content

Support implicit mocking over broadcasted functions #80

@glennmoy

Description

@glennmoy

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions