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

Change direct :erlang calls to Elixir function calls #75

Merged
merged 1 commit into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading