简体   繁体   English

在OCaml中使用OUnit模块 - 未绑定模块OUnit错误

[英]Use OUnit module in OCaml - Unbound module OUnit error

I'm trying to use OUnit with OCaml. 我正在尝试将OUnit与OCaml一起使用。

The unit code source (unit.ml) is as follows: 单位代码源(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

With ocamlc unit.ml , I got an error message Error: Unbound module OUnit . 使用ocamlc unit.ml ,我收到一条错误消息Error: Unbound module OUnit Why is this? 为什么是这样? How can I use the OUnit in OCaml. 如何在OCaml中使用OUnit。 I installed OUnit with opam . 我用opam安装了opam

You should use for example: 你应该使用例如:

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

ocamlfind is an utility that encapsulates lookup of installed libraries. ocamlfind是一个封装已安装库查找的实用程序。 You can also avoid composing compiler-invocation yourself and use a build tool. 您还可以避免自己编写编译器调用并使用构建工具。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM