I wanted to use Kaputt for unit testing of OCaml code, but encountered an error during compilation:Error: Unbound module Kaputt

The OCaml version is as follows:
The OCaml toplevel, version 4.02.3

The Kaputt version is as follows:
kaputt 1.2

The test files are as follows:
(adder.ml)
let add a b = a + b

(* adder_test.ml *)
open Kaputt

let suite = “adder_tests”

let test_add_two_plus_two () =
assert_equal ~msg:“2 + 2 must be 4” 4 (adder.add 2 2)

let () =
Kaputt.run suite

The compilation command is as follows:
ocamlc -o adder adder.ml
ocamlc -o adder_test adder_test.ml

Compilation error:
File “adder_test.ml”, line 2, characters 5-11:
Error: Unbound module Kaputt

You need to make your build system aware that you want to load the kaputt findlib package or add the necessary includes and archives to the compiler incantation yourself.

In the first line of the adder_test.ml file, I used the open Kaputt statement to introduce Kaputt, but encountered an error while executing the compile command: Unbound module Kaputt.
How should I solve this problem?

1 Like

Opening a module does not let the compiler find it. You have to specify a bunch of things on the command line. One way of doing this is via ocamlfind.

I don’t know what the name of the library is. Try to spot it in ocamlfind list. But something like:

ocamlfind ocamlc -package kaputt -linkpkg -o adder adder.ml

should work.

1 Like