Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reconsolidate protocols in Elixir 1.2 or higher

I have a macro that creates a module, a struct for the module, and implements a protocol for that struct.

In my suite I have a simple test module that calls the macro, and then makes assertions on the generated module/struct/protocol implementation. One test calls the protocol function with the struct to assert that it has been implemented. Prior to 1.2 this worked, but now it fails, and I get the following warning when running the suite.

test/dogma/rule_builder_test.exs:7: warning: the Dogma.Rule \
protocol has already been consolidated, an implementation for \
Dogma.RuleBuilderTest.MagicTestRule has no effect

I have removed this test for now, as I believe the rest of my suite tests this functionality sufficiently, but I'm curious if there is a way to make this work again, or at least silence the warning.

I played around with Process.consilodate/2, but was unsuccessful.

like image 639
lpil Avatar asked Jan 23 '16 13:01

lpil


Video Answer


1 Answers

Starting in Elixir 1.2, Mix consolidates protocols by default, which can cause the problem described here:

https://github.com/elixir-lang/elixir/blob/v1.2/CHANGELOG.md#workflow-improvements

It sounds to me like you have a different flavor of this same problem, but the fix is most likely the same. Set consolidate_protocols: false in your project config (only when running in the test environment).

like image 110
Cameron Price Avatar answered Oct 14 '22 03:10

Cameron Price