Skip to content

Commit

Permalink
Merge pull request #26 from sonerdy/25-macro-verification
Browse files Browse the repository at this point in the history
Fixing issues w/ macro verification
  • Loading branch information
brandonjoyce authored Aug 19, 2017
2 parents 69f815b + fd31fb1 commit e48a6cd
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
14 changes: 9 additions & 5 deletions lib/double.ex
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,15 @@ defmodule Double do
if double_opts[:verify] do
source = Registry.source_for("#{dbl}")
source_functions = source.module_info(:functions)
source_functions = case source_functions[:behaviour_info] do
nil -> source_functions
_ ->
behaviours = source.behaviour_info(:callbacks)
source_functions |> Keyword.merge(behaviours)
source_functions = if source_functions[:__info__] do
source_functions ++ source.__info__(:macros)
else
source_functions
end
source_functions = if source_functions[:behaviour_info] do
source_functions ++ source.behaviour_info(:callbacks)
else
source_functions
end
stub_arity = :erlang.fun_info(func)[:arity]
matching_function = Enum.find(source_functions, fn({k, v}) ->
Expand Down
14 changes: 14 additions & 0 deletions test/double_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,20 @@ defmodule DoubleTest do
allow(dbl, :non_existent_function, fn(_) -> :ok end)
end
end

test "works with modules having macros" do
dbl = Logger
|> double
|> allow(:info, fn(_msg) -> :ok end) # Logger.info/1 is a macro

assert :ok = dbl.info(nil)

dbl = Mix.Task
|> double
|> allow(:run, fn(_, _) -> :ok end)

assert :ok = dbl.run(nil, nil)
end
end

test "works normally when called within another process" do
Expand Down

0 comments on commit e48a6cd

Please sign in to comment.