2014-01-06 69 views
1

我犯了更新软件的错误,现在我无法运行任何OUnit测试。模块案例名称混淆

我想我已经设法将问题归结为一个简单的REPL会话。

$ ocaml -I /opt/local/lib/ocaml/site-lib/oUnit 
     OCaml version 4.01.0 

# Ounit.assert_equal;; 
Error: Wrong file naming: /opt/local/lib/ocaml/site-lib/oUnit/ounit.cmi 
contains the compiled interface for 
Ounit when OUnit was expected 
# OUnit.assert_equal;; 
Error: Reference to undefined global `OUnit' 

任何想法我做错了吗?

我在Mac笔记本电脑上运行此项,该笔记本电脑具有默认的case-insensitive/case-preserving文件系统,但与包含路径的情况下dinking没有帮助。因此


我的大问题表现:

ocamlbuild \ 
    -libs \ 
    nums,str,unix,oUnit,graph \ 
    -cflags \ 
    -g,-w,+a-4,-warn-error,+a-4,-I,/opt/local/lib/ocaml/site-lib/oUnit,-I,/opt/local/lib/ocaml/site-lib/ocamlgraph \ 
    -lflags \ 
    -g,-I,/opt/local/lib/ocaml/site-lib/oUnit,-I,/opt/local/lib/ocaml/site-lib/ocamlgraph \ 
    ./AllTests.native 

Error: No implementations provided for the following modules: 
    OUnitCore referenced from /opt/local/lib/ocaml/site-lib/oUnit/oUnit.cmxa(OUnit2), 
     /opt/local/lib/ocaml/site-lib/oUnit/oUnit.cmxa(OUnit) 
    OUnitLoggerStd referenced from /opt/local/lib/ocaml/site-lib/oUnit/oUnit.cmxa(OUnit) 
    OUnitUtils referenced from /opt/local/lib/ocaml/site-lib/oUnit/oUnit.cmxa(OUnit2), 
     /opt/local/lib/ocaml/site-lib/oUnit/oUnit.cmxa(OUnit) 
    OUnitConf referenced from /opt/local/lib/ocaml/site-lib/oUnit/oUnit.cmxa(OUnit2), 
     /opt/local/lib/ocaml/site-lib/oUnit/oUnit.cmxa(OUnit) 
    OUnitAssert referenced from /opt/local/lib/ocaml/site-lib/oUnit/oUnit.cmxa(OUnit2), 
     /opt/local/lib/ocaml/site-lib/oUnit/oUnit.cmxa(OUnit) 
    OUnitBracket referenced from /opt/local/lib/ocaml/site-lib/oUnit/oUnit.cmxa(OUnit2), 
     /opt/local/lib/ocaml/site-lib/oUnit/oUnit.cmxa(OUnit) 
    OUnitTest referenced from /opt/local/lib/ocaml/site-lib/oUnit/oUnit.cmxa(OUnit2), 
     /opt/local/lib/ocaml/site-lib/oUnit/oUnit.cmxa(OUnit) 
    OUnitRunner referenced from /opt/local/lib/ocaml/site-lib/oUnit/oUnit.cmxa(OUnit) 
    OUnitChooser referenced from /opt/local/lib/ocaml/site-lib/oUnit/oUnit.cmxa(OUnit) 
    OUnitLogger referenced from /opt/local/lib/ocaml/site-lib/oUnit/oUnit.cmxa(OUnit2), 
     /opt/local/lib/ocaml/site-lib/oUnit/oUnit.cmxa(OUnit) 
    OUnitTestData referenced from /opt/local/lib/ocaml/site-lib/oUnit/oUnit.cmxa(OUnit2) 
Command exited with code 2. 
Compilation unsuccessful after building 646 targets (645 cached) in 00:00:02. 

回答

3

你的第一个错误可能是因为您的操作系统不在文件名中区分案件,但OCaml的作用:

$ ocamlobjinfo `ocamlfind query oUnit`/oUnit.cmi 
File /mnt/home/jun/.opam/system/lib/oUnit/oUnit.cmi 
Unit name: OUnit 
Interfaces imported: 
    cb146e345f0b34fc8ad4b5afe69d1f20 OUnit 
    ... 

你可以看到该模块被称为“OUnit”而不是“Ounit”。

第二个错误显然是因为该库尚未加载到REPL中。 REPL知道函数的存在,但没有加载代码。

ocaml -I `ocamlfind query oUnit` unix.cma oUnitAdvanced.cma oUnit.cma 
     OCaml version 4.01.0 

# OUnit.assert_equal;; 
- : ?cmp:('a -> 'a -> bool) -> 
    ?printer:('a -> string) -> 
    ?pp_diff:(Format.formatter -> 'a * 'a -> unit) -> 
    ?msg:string -> 'a -> 'a -> unit 
= <fun> 
+0

谢谢产生。看起来像我的REPL不会重现整个问题。有关我应该如何获得'ocamlbuild'链接的想法?我需要'-libs'列表中的'ounitadvanced'吗? –

0

我改变我的ocamlbuild调用使用-use-ocamlfind这似乎解决所有的路径困惑解决了这个问题:如果您加载它所依赖的库,这些可被访问。

我也卸载了所有OCaml模块,而是安装了OPAM,然后通过OPAM安装了OUnit和其他,然后重新登录,以便我的环境保持原始状态。

,对我现在的作品构建命令是

ocamlbuild \ 
    -use-ocamlfind \ 
    -libs graph \ 
    -pkgs str,unix,ounit \ 
    -cflags -g,-w,+a-4,-warn-error,+a-4,-I,/opt/local/lib/ocaml/site-lib/ocamlgraph \ 
    -lflags -g,-I,/opt/local/lib/ocaml/site-lib/ocamlgraph \ 
    ./AllTests.native 

由我的更新构建脚本

(* Usage: ocaml make.ml [<ModuleToBuild>.{byte,native}] *) 

#load "unix.cma";; 

let args = match Array.to_list Sys.argv with 
    | []  -> failwith "no program on argv" 
    | _::[] -> ["AllTests.byte"] 
    | _::argv -> argv 

let library_paths = [ 
    (* TODO: Figure out why `opam install ocamlgraph` fails *) 
    "-I"; "/opt/local/lib/ocaml/site-lib/ocamlgraph"; 
] 

(* If the -p flag is first in the argument list, then replace it 
    with a host of flags that enable profiling via ocamlprof. *) 
let args, c_opt_flags, l_opt_flags = 
    match args with 
    | "-p"::rest -> 
     (* Treat the targets as debug and profile targets. *) 
     "-tags"::"debug,profile" 
     (* Use profiling versions of the compilers which instrument 
     various flow control constructs with entry counters. *) 
     ::"-ocamlc"::"ocamlcp" 
     ::"-ocamlopt"::"ocamloptp" 
     ::rest, 
     (* Instrument all available points. *) 
     ["-P"; "a"], 
     (* Link with a wrapper that dumps profiling data if program 
     exits noramlly. *) 
     ["-p"] 
    | _ -> args, [], [] 

let standard_flags = [ 
    "-use-ocamlfind"; 
    (* TODO: Figure out why `opam install ocamlgraph` fails *) 
    "-libs"; "graph"; 
    "-pkgs"; "str,unix,ounit"; (* TODO: graph *) 
    "-cflags"; (String.concat "," (
    [ 
     "-g"; 
     "-w"; "+a-4"; 
     "-warn-error"; "+a-4"; 
    ] 
    @ c_opt_flags 
    @ library_paths)); 
    "-lflags"; (String.concat "," (
    [ 
     "-g"; 
    ] 
    @ l_opt_flags 
    @ library_paths)); 
] 

let build_command = "ocamlbuild" 

let argv = build_command::(standard_flags @ args) 

let _ = begin 
    Printf.printf "%s\n" (String.concat " \\\n\t" argv); 
    flush stdout; 
    Unix.execvp build_command (Array.of_list argv); 
end;;