Check all test files are compilable

153 Views Asked by At

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?

2

There are 2 best solutions below

5
On BEST ANSWER

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.

6
On

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.