appunite / mockery

Simple mocking library for asynchronous testing in Elixir.

Home Page:https://hex.pm/packages/mockery

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Create an alternative for tuple calls before OTP21 release

amatalai opened this issue · comments

@amatalai Can you add some more context?

@teamon ofc, yes

Due to this PR erlang/otp#1499 it will be necessary to add something like @compile :tuple_calls in order to use tuple calls. At the moment Mockery is using tuple calls to pass some data about mocks to function which handles most of logic and it means that you would need to add this compile attribute to every module where you want to mock something. It seems unacceptable to me.

I have an idea to replace tuple calls by generating small module with :"$handle_undefined_function" that will mimic tuple call behavior. In fact I already have working solution locally, but I'm not completely satisfied with it yet.

That's one of my early implementations https://gist.github.com/teamon/bad0891c02c26ed774890e04bb998e15#file-twin-ex-L9 (still running in one project, waiting to be replaced by mockery ;])

I know it. Your implementation is where I learned about $handle_undefined_function 😈

Btw, Dialyzer is complaining about the tuple syntax

The call {'Elixir.Mockery.Proxy', 'Elixir.MyDep', 'nil'}:'new'...) requires that {'Elixir.Mockery.Proxy', 'Elixir.MyDep', 'nil'} is of type atom() not {'Elixir.Mockery.Proxy', 'Elixir.MyDep', 'nil'}

@amatalai any chance to publish your work in progress to github branch? ;)

It's known that dialyzer is complaining about tuple calls.

My wip solution needs some cleanup, but I'll try to publish it in next few days.

Sorry for delay. It turned out that it's impossible to get rid of compiler warnings in my previous work in progress solution.

I'll try to add alternative way to prepare module for mocking (with macro) and leave current one as is for those who don't mind using @compile :tuple_calls in otp21

released Mockery 2.2 to hex