In the test suite for Makeup, I need some dummy lexers to test some of the combinators. I could define all the lexers in test_helper.exs, but even with only 2 lexers the file is already quite big, and I’ll have add even more lexers to tesl all combinators. I’ve moved the lexers into their own files and I’m currently doing this:
Is this the right way to do it? I think there’s no problem in invoking the compiler directly, but I wonder if there is a more standard way I don’t know.
Are they containing scripts, or are you defining modules in them?
If they are defining proper modules, I tend to do it like this:
# mix.exs
defmodule Foo.MixProject do
# ...
def project do
[
# ...
elixirc_path: compiler_paths(Mix.env())
]
end
def compiler_paths(:test), do: ["test/helpers"] ++ compiler_paths(:prod)
def compiler_paths(_), do: ["lib"]
# ...
end
Then I just create files with modules in them below test/helpers/, but as *.ex rather than *.exs. I haven’t had problems with this setup so far.
Also this picks up new files as you create them, ne need to remember to update them in a list. Ne need to remember correct path and filename, you can just use their modules as you would use a module from your application.