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

crashfy:untuple/1 strips {ok, _} tuple result of behavior functions #20

Closed
stwind opened this issue Jul 30, 2013 · 3 comments
Closed

crashfy:untuple/1 strips {ok, _} tuple result of behavior functions #20

stwind opened this issue Jul 30, 2013 · 3 comments
Assignees
Labels

Comments

@stwind
Copy link
Contributor

stwind commented Jul 30, 2013

Most of time in my cases a mock behavior function returns a {ok, _} or {error, _} tuple as result.

But sel_gen_server:call will by default untuple the result to determine it is an exception or not, so to get around this I have to wrap the result with another {ok, _} layer. Like:

f(Fun) ->
    {arity, Arity} = erlang:fun_info(Fun, arity),
    f(Arity, Fun).

f(0, Fun) -> fun() -> {ok, Fun()} end;
f(1, Fun) -> fun(A) -> {ok, Fun(A)} end;
f(2, Fun) -> fun(A,B) -> {ok, Fun(A,B)} end;
f(3, Fun) -> fun(A,B,C) -> {ok, Fun(A,B,C)} end;
f(4, Fun) -> fun(A,B,C,D) -> {ok, Fun(A,B,C,D)} end;
f(5, Fun) -> fun(A,B,C,D,E) -> {ok, Fun(A,B,C,D,E)} end;
f(6, Fun) -> fun(A,B,C,D,E,F) -> {ok, Fun(A,B,C,D,E,F)} end;
f(7, Fun) -> fun(A,B,C,D,E,F,G) -> {ok, Fun(A,B,C,D,E,F,G)} end.

And here is my typical setup of moka: https://gist.github.com/stwind/6109054

I think here just using a built-in gen_server:call will be fine

@ghost ghost assigned samuelrivas Jul 30, 2013
@samuelrivas
Copy link
Owner

It is fixed in the branch wip-tagged-returns. I will merge it to master later

@samuelrivas
Copy link
Owner

Should be fixed in 1.0.3. It will break your tests (sorry about that) but since it was actually a bug I thought that increasing the patch level would be more appropriate than bumping the major version.

Thanks for the bug report!

@samuelrivas
Copy link
Owner

This has been closed forever ...

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

No branches or pull requests

2 participants