【问题标题】:Running OUnit tests using dune使用 dune 运行 OUnit 测试
【发布时间】:2018-11-15 10:34:19
【问题描述】:

我在运行 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.

我可以看到错误出现是因为沙丘不知道f.ml,因此不知道沙丘文件中的f

我怎样才能让 dune 编译 f.ml 以使 test/dune 知道我在 test/f_test.ml 中使用的 f 库?如何正确运行单元测试?

【问题讨论】:

    标签: ocaml ounit ocaml-dune


    【解决方案1】:

    一种可能是将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 运行测试。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多