0

I followed the following steps to create my project

  1. Create the project using the following dune command

    dune init proj --kind=lib mymaps

  2. Then added 2 files under the "lib" directory

mymaps.mli

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

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 = []
  1. Added the following file under the "tests" directory

mymaps_tests.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

However when I go to command line and say dune build it says

File "test/dune", line 2, characters 7-13:
2 |  (name mymaps))
       ^^^^^^
Error: Module "Mymaps" doesn't exist.     

Here is the link to GitHub for my work https://github.com/abhsrivastava/mymaps

I am following a tutorial on YouTube and I didn't see them implement any modules for the test project, they straight wrote the test. Not sure why is it looking for another Mymaps under test.

Knows Not Much
  • 30,395
  • 60
  • 197
  • 373
  • can you check, there is a `space` in your command between `my` and `maps`, which I think you want to name the project -- `dune init proj --kind=lib my maps`... it should have been `dune init proj --kind=lib mymaps`.... – Nalin Ranjan Mar 04 '22 at 06:18

1 Answers1

0

I think I found out the issue. the name of the test file should be the same as the name of the project. I renamed my tests file to "mymaps.ml" and then the error went away.

Knows Not Much
  • 30,395
  • 60
  • 197
  • 373
  • 1
    I'm more surprised that dune doesn't complain about having two projects with the same name. You might want to consider renaming the test project to `mymaps_test` instead. – glennsl Mar 04 '22 at 07:37