I have a case when I need to check that all files in my app's test suite are compilable.
I'm trying to create a list of all files and then compile them, but it turns out I can't do it without starting ExUnit.
find apps/*/test -name "*.exs" | xargs elixirc
== Compilation error in file apps/api/test/api/request_validators/validator_test.exs ==
** (RuntimeError) cannot use ExUnit.Case without starting the ExUnit application, please call ExUnit.start() or explicitly start the :ex_unit app
expanding macro: ExUnit.Case.__using__/1
How to check that all test files are compilable without actually running tests?
The proper solution would be to indeed start ExUnit, compile all the files and examine the outcome.
mix run -e 'ExUnit.start(); exit({:shutdown, (if match?({:ok, _, _}, Kernel.ParallelCompiler.compile(Path.wildcard("test/**/*.exs"))), do: 0, else: 1)})'
That way you might also explicitly specify the error code to return.
I've found an answer.
Just run tests with some tag that doesn't exist. This will compile all tests but none of them will be actually run
mix test --only whatever
UPDATE: this only works for umbrella apps. For a regular app, nonexistent tag leads to an error code 1 (see comments to this question).
It's possible to create a workaround: have an empty test that is always green and mark it with the tag.
See also the accepted answer for a better solution.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With