OUnit2 Unbound Module

773 views Asked by At

I am writing my first Ocaml+OUnit2+Dune project. but in my unit test when I say open Mymaps it says "Unbound module Mymaps"

The structure of my project is as follows

mymaps
  |
  |-> lib
       |-> dune
       |-> mymaps.mli
       |-> mymaps.ml
  |-> test
       |->mymaps_test.ml
       |-> dune
  |->dune-project
  |->mymaps.opam

content of mymaps_test.ml

open OUnit2
open Mymaps
let empty_test = "empty has no bindings" >:: (fun _ -> assert_equal [] (empty))
let mymap_tests = [empty_test]
let suite = "maps suite" >::: mymap_tests
let _ = run_test_tt_main suite

content of mymaps.mli

type ('k, 'v) t
val empty : ('k, 'v) t
val insert : 'k -> 'v -> ('k, 'v) t -> ('k, 'v) t

content of mymaps.ml

type ('k, 'v) t = ('k * 'v) list
let rec insert k v m = match m with 
  | [] -> [(k, v)]
  | (eK, eV) :: tl -> let (nK, nV) = if (eK = k) then (k, v) else (eK, eV) in 
                        (nK, nV) :: insert k v tl
let empty = []

Contents of test/dune file

(test
 (name mymaps_test)
 (libraries ounit2))

Contents of lib/dune file

(library
 (public_name mymaps)
 (name mymaps))

Here is the link to Github https://github.com/abhsrivastava/mymaps.git

Please let me know why my test is not able to open the module. Why is it saying Unbound module Mymaps. (I also tried lower case mymaps, and MyMaps, but it just cannot see it).

1

There are 1 answers

0
glennsl On BEST ANSWER

You need to list mymaps in the libraries stanza of the test project, as you would with any other project in your workspace. There's nothing else indicating that this is the library you mean to test.

(test
 (name mymaps_test)
 (libraries mymaps ounit2))