Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use OUnit module in OCaml - Unbound module OUnit error

I'm trying to use OUnit with OCaml.

The unit code source (unit.ml) is as follows:

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. Why is this? How can I use the OUnit in OCaml. I installed OUnit with opam.

like image 541
prosseek Avatar asked Mar 21 '23 09:03

prosseek


1 Answers

You should use for example:

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

ocamlfind is an utility that encapsulates lookup of installed libraries. You can also avoid composing compiler-invocation yourself and use a build tool.

like image 180
gasche Avatar answered Apr 02 '23 12:04

gasche