首页 > 解决方案 > 检查所有测试文件是否可编译

问题描述

当我需要检查我的应用程序测试套件中的所有文件是否可编译时,我有一个案例。

我正在尝试创建所有文件的列表,然后编译它们,但事实证明,如果不启动 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

如何在不实际运行测试的情况下检查所有测试文件是否可编译?

标签: elixirex-unit

解决方案


正确的解决方案是确实开始ExUnit,编译所有文件并检查结果。

mix run -e 'ExUnit.start(); exit({:shutdown, (if match?({:ok, _, _}, Kernel.ParallelCompiler.compile(Path.wildcard("test/**/*.exs"))), do: 0, else: 1)})'

这样,您还可以显式指定要返回的错误代码。


推荐阅读