【问题标题】:Use OUnit module in OCaml - Unbound module OUnit error在 OCaml 中使用 OUnit 模块 - 未绑定模块 OUnit 错误
【发布时间】:2013-12-06 19:56:47
【问题描述】:

我正在尝试将 OUnit 与 OCaml 一起使用。

单元代码源码(unit.ml)如下:

open OUnit

let empty_list = []
let list_a = [1;2;3]

let test_list_length _ =
  assert_equal 1 (List.length empty_list);
  assert_equal 3 (List.length list_a)
    (* etc, etc *)

let test_list_append _ =
  let list_b = List.append empty_list [1;2;3] in
  assert_equal list_b list_a

let suite = "OUnit Example" >::: ["test_list_length" >:: test_list_length;
                                  "test_list_append" >:: test_list_append]
let _ =
  run_test_tt_main suite

使用ocamlc unit.ml,我收到一条错误消息Error: Unbound module OUnit。为什么是这样?如何在 OCaml 中使用 OUnit。我用opam 安装了OUnit。

【问题讨论】:

    标签: unit-testing ocaml opam ounit


    【解决方案1】:

    你应该使用例如:

    ocamlfind ocamlc -package oUnit -linkpkg -o unit unit.ml
    

    ocamlfind 是一个封装已安装库查找的实用程序。您还可以避免自己编写编译器调用并使用构建工具。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-09-19
      • 2012-11-21
      • 2020-04-18
      • 2013-08-28
      • 2016-01-16
      • 1970-01-01
      • 1970-01-01
      • 2012-09-18
      相关资源
      最近更新 更多