ocaml - 使用 dune 运行 OUnit 测试
问题描述
我在运行 OUnit 测试时遇到了困难,主要是因为我对沙丘和 OUnit 都不熟悉。dune
我跑步时抱怨dune runtest
:
File "test/dune", line 4, characters 13-14:
Error: Library "f" not found.
Hint: try: dune external-lib-deps --missing @runtest
这是项目结构:
├── dune
├── f.ml # This is the source file.
└── test
├── dune
└── f_test.ml # This is the test.
这是dune
:
(executable
(name f))
这是test/dune
:
(test
(name f_test)
(libraries oUnit f)) ; <- `f` here causes problems.
我可以看到出现错误是因为 dune 不知道f.ml
,因此不知道f
dune 文件中的 about 。
如何以了解我使用的库f.ml
的方式进行 dune 编译?如何正确运行单元测试?test/dune
f
test/f_test.ml
解决方案
一种可能是拆分f
成私有库和可执行文件,然后测试拆分库。
编辑:
例如,项目结构可以更新为
├── dune
├── f.ml # f only contains the I/O glue code.
├── lib
| ├── dune
| └── a.ml # a implements the features that need to be tested.
└── test
├── dune
└── test.ml # This is the test.
和dune
(executable (name main) (libraries Lib))
对于测试,test/dune
:
(test (name test) (libraries Lib oUnit))
最后lib/dune
(library (name Lib))
使用此设置,可以使用dune runtest
.
推荐阅读
- flutter - ListView 中的项目得到它的高度
- javascript - Firebase 实时数据库第一个查询没有响应
- flutter - MissingPluginException(在通道flutter_audio_recorder上找不到方法hasPermissions的实现)
- c++ - 使用 makefile 和 VS Code 包含第三方头文件和库
- ruby-on-rails - 升级到 Rails 6 后的 Websockets 不稳定测试
- ssms - 使用 sp_helptext 重新检查后,SQL Server 过程缩进发生变化
- meshlab - Meshlab 2020.03 - 面内的点拾取
- xml - 如何在 AUTOSAR 标准中确定 ARXML 文件是属于 CAN 网络还是以太网网络
- c - 从函数返回结构的更好方法是什么?
- travis-ci - Travis,是否可以将 cron 计划的构建和检查 github 更改结合起来?