Skip to content

Commit

Permalink
Update direct :erlang calls with Elixir functions
Browse files Browse the repository at this point in the history
  • Loading branch information
brain-geek authored and edgurgel committed Jul 16, 2024
1 parent 738ed32 commit 5bbfaf3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions lib/mimic.ex
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ defmodule Mimic do
"""
@spec stub(module(), atom(), function()) :: module
def stub(module, function_name, function) do
arity = :erlang.fun_info(function)[:arity]
arity = Function.info(function)[:arity]
raise_if_not_exported_function!(module, function_name, arity)

module
Expand Down Expand Up @@ -228,7 +228,7 @@ defmodule Mimic do
def expect(module, fn_name, num_calls, func)
when is_atom(module) and is_atom(fn_name) and is_integer(num_calls) and num_calls >= 1 and
is_function(func) do
arity = :erlang.fun_info(func)[:arity]
arity = Function.info(func)[:arity]
raise_if_not_exported_function!(module, fn_name, arity)

module
Expand Down Expand Up @@ -258,7 +258,7 @@ defmodule Mimic do
"""
@spec reject(function) :: module
def reject(function) when is_function(function) do
fun_info = :erlang.fun_info(function)
fun_info = Function.info(function)
arity = fun_info[:arity]
module = fun_info[:module]
fn_name = fun_info[:name]
Expand Down Expand Up @@ -294,7 +294,7 @@ defmodule Mimic do
@spec reject(module, atom, non_neg_integer) :: module
def reject(module, function_name, arity) do
raise_if_not_exported_function!(module, function_name, arity)
func = :erlang.make_fun(module, function_name, arity)
func = Function.capture(module, function_name, arity)

module
|> Server.expect(function_name, arity, 0, func)
Expand Down
2 changes: 1 addition & 1 deletion lib/mimic/server.ex
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ defmodule Mimic.Server do
arity = Enum.count(args)
original_module = Mimic.Module.original(module)

if :erlang.function_exported(original_module, fn_name, arity) do
if function_exported?(original_module, fn_name, arity) do
caller_pids = [self() | Process.get(:"$callers", [])]

case allowed_pid(caller_pids, module) do
Expand Down

0 comments on commit 5bbfaf3

Please sign in to comment.