elixirex-unit

Check all test files are compilable


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?


Solution

  • 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.