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

Any way to keep the original source clean? #73

Open
tk3369 opened this issue Oct 20, 2019 · 7 comments
Open

Any way to keep the original source clean? #73

tk3369 opened this issue Oct 20, 2019 · 7 comments

Comments

@tk3369
Copy link

tk3369 commented Oct 20, 2019

Let's say I have a function that looks like this:

function do_something_useful(a, b, c)
    d = @mock(first_part(a, b))
    if @mock(second_part(c, d))
        @mock(third_part())
    else
        @mock(forth_part())
    end
end

As you can see, I have to put @mock everywhere if I want to be able to patch all of them. The trouble is that the code does not look clean anymore. Would it be possible to do something like:

@mockfuns first_part second_part third_part forth_path 

@mock function do_something_useful(a, b, c)
    d = first_part(a, b)
    if second_part(c, d)
        third_part()
    else
        forth_part()
    end
end
@omus
Copy link
Member

omus commented Oct 20, 2019

An approach like the would be possible but would make the macro processing more complicated than it is now. Something that is being looking into is using Cassette.jl to avoid having to use the @mock macro at all. Unfortunately that approach can have some performance impacts when running tests.

An alternative that may work for you would be to just mock do_something_useful calls instead of mocking each function within.

@tk3369
Copy link
Author

tk3369 commented Oct 20, 2019

Is the Cassette version still being worked on?

How bad is the performance impact? Depending on the use case, performance may or may not be a concern....

@oxinabox
Copy link
Member

Should probably make I new Cassette based version.
After the 0.7 changes

@oxinabox
Copy link
Member

SimpleMock.jl is based on Cassettevand already works @tk3369

@tk3369
Copy link
Author

tk3369 commented Oct 20, 2019

Maybe another option is to make the IDE hide the @mock(...) part of the code 😉

@omus
Copy link
Member

omus commented Jul 15, 2024

We did the experiment with Cassette some time ago at this point but unfortunately there was too much of a performance reduction in comparison to using the @mock macro: #53 (comment)

@oxinabox
Copy link
Member

Doing it with CassetteOverlays.jl could be a good solution.
It shouldn't have any of the issues Cassette has.

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

No branches or pull requests

3 participants