Testing 将模块与makefile(Ocaml)一起使用时出现问题

Testing 将模块与makefile(Ocaml)一起使用时出现问题,testing,makefile,module,functional-programming,ocaml,Testing,Makefile,Module,Functional Programming,Ocaml,我在测试文件中使用模块时遇到问题。我在这里创建了一个更简单的版本,它仍然复制了这个问题 (* person.ml *) module Person = struct type person = {name: string; age: int} let create_person name age = {name=name; age=age} end (*当我在终端中键入“make”时*) ocamlbuild-pkg oUnit test.byte&&./test.

我在测试文件中使用模块时遇到问题。我在这里创建了一个更简单的版本,它仍然复制了这个问题

(* person.ml *)
module Person = struct
    type person = {name: string; age: int}

    let create_person name age = {name=name; age=age}

end




(*当我在终端中键入“make”时*)
ocamlbuild-pkg oUnit test.byte&&./test.byte
+/Users/user/.opam/4.03.0/bin/ocamlc.opt-c-I/Users/user/.opam/4.03.0/lib/oUnit-I/Users/user/user/.opam/4.03.0/lib/ocaml-o test.cmo test.ml
文件“test.ml”,第4行,字符13-26:
错误:未绑定值创建\u person
命令已退出,代码为2。
提示:此生成未启用子目录的递归遍历,
因为工作目录看起来不像ocamlbuild项目(否
“_标记”或“myocamlbuild.ml”文件)。如果子目录中有模块,
您应该添加选项“-r”或创建一个空的“\u tags”文件。
要仅对某些子目录启用递归遍历,可以使用
以下“\u标记”文件:
正确:-导线测量
或:导线测量
在00:00:00中生成4个目标(2个已缓存)后编译失败。
make:**[测试]错误10

问题源于person\u create可通过person.create\u person访问这一事实,而不仅仅是person\u create。在ocaml中,文件已经是一个模块。因此,当您打开Person时,您将打开文件名为Person.ml的模块。在该模块中,您创建了一个名为Person的模块,在该模块中定义Person\u create。因此,要么删除文件中的Person模块,要么键入“Person.create\u Person”而不是create\u Person。

在utop中测试时,#use指令就像一个include。因此,您会丢失文件名,打开person后,person\u create可以直接访问。

问题在于person\u create可以通过person.create\u person访问,而不仅仅是person\u create。在ocaml中,文件已经是一个模块。因此,当您打开Person时,您将打开文件名为Person.ml的模块。在该模块中,您创建了一个名为Person的模块,在该模块中定义Person\u create。因此,要么删除文件中的Person模块,要么键入“Person.create\u Person”而不是create\u Person。
在utop中测试时,#use指令就像一个include。因此,您将丢失文件名,并且一旦打开person,就可以直接访问您创建的person

(*makefile *)
test:
    ocamlbuild -pkgs oUnit,yojson,str,ANSITerminal test.byte && ./test.byte

check:
    bash checkenv.sh

clean:
    ocamlbuild -clean
(* test.ml *)
open OUnit2
open Person

let person = create_person "john" 40
(* utop *)
#use "person.ml"
open Person
let person = create_person "john" 40

Output: val person : person = {name = "john"; age = 40}  
(* when I type in "make" in the terminal *)

ocamlbuild -pkg oUnit test.byte && ./test.byte
+ /Users/user/.opam/4.03.0/bin/ocamlc.opt -c -I /Users/user/.opam/4.03.0/lib/oUnit -I /Users/user/.opam/4.03.0/lib/ocaml -o test.cmo test.ml
File "test.ml", line 4, characters 13-26:
Error: Unbound value create_person
Command exited with code 2.
Hint: Recursive traversal of subdirectories was not enabled for this build,
  as the working directory does not look like an ocamlbuild project (no
  '_tags' or 'myocamlbuild.ml' file). If you have modules in subdirectories,
  you should add the option "-r" or create an empty '_tags' file.

  To enable recursive traversal for some subdirectories only, you can use the
  following '_tags' file:

      true: -traverse
      <dir1> or <dir2>: traverse

Compilation unsuccessful after building 4 targets (2 cached) in 00:00:00.
make: *** [test] Error 10