Using Module Attributes for Code Generation
Learn about module attributes and how they help in keeping track of test cases.
We'll cover the following...
Before we can implement the test
macro, we need to address a missing piece of our implementation. A user can define multiple test cases, but we have can’t track each test-case definition for inclusion within MathTest.run/0
. Fortunately, Elixir solves this use case via module attributes.
Utilizing module attributes
Module attributes allow us to store data in the module at compile time. They are often used in places where constants would be applied in other languages, but Elixir provides other tricks for us to exploit during compilation. We can keep an appended list of registration during the compile phase by taking advantage of the accumulate: true
...