How to mock LFE-compiled module?

37 views
Skip to first unread message

Damian Dobroczyński

unread,
Sep 19, 2018, 9:32:07 AM9/19/18
to Lisp Flavoured Erlang
... because meck needs abstract forms and they are absent in LFE-generated beams.
Is there any way library or something to handle this case?

--D.

Robert Virding

unread,
Sep 19, 2018, 9:42:18 AM9/19/18
to Lisp Flavoured Erlang
There are no problems using meck together with LFE. The abstract you need for creating mock functions with meck:expect(Mod, Func, Fun) can directly be done using lambdas. For example like

(meck:expect 'dog 'bark (lambda () "Woof!"))

The lambda form returns a a fun. Is this what you meant?

Robert

Damian Dobroczyński

unread,
Sep 19, 2018, 10:03:11 AM9/19/18
to Lisp Flavoured Erlang
Sorry I was not very detailed in my previous post.

I have regular Erlang files with proper properties. They use LFE modules. I tried to mock one of the modules (say, foo):

meck:new(foo, [passthrough]),
meck:expect(foo, bar, 0, something)

I'm obtaining during meck:new(foo, [passthrough]):

exception exit: {abstract_code_not_found,foo}
      in function  meck_proc:backup_original/4 (/home/damian/src/erl/foo-project/_build/test/lib/meck/src/meck_proc.erl, line 406)
      in call from meck_proc:init/1 (/home/damian/src/erl/foo-project/_build/test/lib/meck/src/meck_proc.erl, line 212)
      in call from gen_server:init_it/2 (gen_server.erl, line 374)
      in call from gen_server:init_it/6 (gen_server.erl, line 342)

The same happens in LFE-shell.

B. regards,
--D
Reply all
Reply to author
Forward
0 new messages