ExUnit issues with Protocol

My directory structure is:
lib/expr/interp.ex
lib/expr.ex

where interp.ex is a protocol with implementation which uses expr.ex.

I have a interp_test.exs and when I run “mix test” the errors results:

** (FunctionClauseError) no function clause matching in IO.chardata_to_string/1
(elixir) lib/io.ex:445: IO.chardata_to_string(nil)
(elixir) lib/path.ex:289: Path.relative_to/2
test/interp_test.exs:5: (module)
(elixir) lib/code.ex:370: Code.require_file/2
(elixir) lib/kernel/parallel_require.ex:57: anonymous fn/2 in Kernel.ParallelRequire.spawn_requires/5

===============
The first 5 lines of the interp_test.exs is:

require Expr.Interp

defmodule InterpTest do
use ExUnit.Case
doctest Expr.Interp

=================

I marked this as an issue with Protocol because before I changed to Protocols the tests work without issues. Before Protocol interp was a Module with one function.

Thanks

Can you paste the complete/relevant code here on in a GitHub Gist? That would make it easier to figure out what’s wrong.

With protocols the most common reason for this kind of behaviour is because of protocol consolidation. Try adding the following to your mix.exs's project definition:

def project do                                                          
  [                                                                     
    app: ...
    consolidate_protocols: Mix.env() != :test,                          

This makes sure that protocols are not consolidated at compile time in your test env.

However, I am just guessing. Please share your full code so that we can debug it better :slight_smile:

1 Like

That did the trick. “mix test” works as expected. Thanks for your help.

1 Like