elixir - 检查所有测试文件是否可编译
问题描述
当我需要检查我的应用程序测试套件中的所有文件是否可编译时,我有一个案例。
我正在尝试创建所有文件的列表,然后编译它们,但事实证明,如果不启动 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
如何在不实际运行测试的情况下检查所有测试文件是否可编译?
解决方案
正确的解决方案是确实开始ExUnit
,编译所有文件并检查结果。
mix run -e 'ExUnit.start(); exit({:shutdown, (if match?({:ok, _, _}, Kernel.ParallelCompiler.compile(Path.wildcard("test/**/*.exs"))), do: 0, else: 1)})'
这样,您还可以显式指定要返回的错误代码。
推荐阅读
- xcode - 错误 无法构建 iOS 项目。我们运行了“xcodebuild”命令,但它以错误代码 65 退出
- php - 为什么 PHP pack("h*", 0x41) 函数打印错误的 ASCII 文本
- laravel - Laravel 在 User 类中使用外部数据
- javascript - 模态正文内容不显示
- scala - 如何调用使用 MTL 和 Parallel 的函数?
- sql - 删除重复的记录,只留下最新的记录
- python - 鉴于 PEP 560,为什么泛型类型仍在 Python 3.7 中使用元类?
- ros - 如何发布镜像 tf?
- java - WebSocket 和 Leap Motion
- selenium - 如何在侦听器类中获取驱动程序实例