diff options
author | Hilko Bengen <bengen@debian.org> | 2015-12-24 17:43:01 +0100 |
---|---|---|
committer | Hilko Bengen <bengen@debian.org> | 2015-12-24 17:43:01 +0100 |
commit | 44a51253c8ed5480787020df05895e63b38b2b95 (patch) | |
tree | 7e1b41385784aa54014d7217c96127a3c34b39c8 | |
parent | 684c165a05dd5005fd3bab773e74d926a1e8ca65 (diff) |
Imported Upstream version 113.00.00
-rw-r--r-- | CHANGES.md | 19 | ||||
-rw-r--r-- | INSTALL.txt | 4 | ||||
-rw-r--r-- | _oasis | 18 | ||||
-rw-r--r-- | _tags | 19 | ||||
-rw-r--r-- | lib_test/pa_ounit_test.ml | 13 | ||||
-rw-r--r-- | lib_test/test.expected | 28 | ||||
-rw-r--r-- | myocamlbuild.ml | 93 | ||||
-rw-r--r-- | runtime-lib/META (renamed from lib/META) | 9 | ||||
-rw-r--r-- | runtime-lib/pa_ounit_lib.mldylib (renamed from lib/pa_ounit_lib.mldylib) | 0 | ||||
-rw-r--r-- | runtime-lib/pa_ounit_lib.mllib (renamed from lib/pa_ounit_lib.mllib) | 0 | ||||
-rw-r--r-- | runtime-lib/pa_ounit_lib.mlpack (renamed from lib/pa_ounit_lib.mlpack) | 0 | ||||
-rw-r--r-- | runtime-lib/runtime.ml (renamed from lib/runtime.ml) | 57 | ||||
-rw-r--r-- | runtime-lib/runtime.mli (renamed from lib/runtime.mli) | 5 | ||||
-rw-r--r-- | setup.ml | 202 | ||||
-rw-r--r-- | src/pa_ounit.ml (renamed from syntax/pa_ounit.ml) | 80 | ||||
-rw-r--r-- | src/pa_ounit.mli | 3 | ||||
-rw-r--r-- | src/pa_ounit_syntax.mldylib (renamed from syntax/pa_ounit_syntax.mldylib) | 0 | ||||
-rw-r--r-- | src/pa_ounit_syntax.mllib (renamed from syntax/pa_ounit_syntax.mllib) | 0 | ||||
-rw-r--r-- | test/failures.ml | 21 | ||||
-rw-r--r-- | test/order.ml (renamed from lib_test/test.ml) | 0 | ||||
-rw-r--r-- | test/test.expected | 34 |
21 files changed, 373 insertions, 232 deletions
@@ -1,3 +1,22 @@ +## 113.00.00 + +- Add `-pa-ounit-drop-with-deadcode` option + +## 112.35.00 + +- Made `Pa_ounit_runtime` not depend on `OUnit` anymore. + + The dependency hasn't been needed in more than 2 years. + +## 112.24.00 + +- Added `-verbose` switch to time unit tests, so we can easily see which ones + are taking a long time. + +## 112.17.00 + +- only spend time to format test description when tests are run + ## 111.28.00 - Added a flag to disable embedding of unit tests/inline benchmarks. diff --git a/INSTALL.txt b/INSTALL.txt index 752de4b..19830b7 100644 --- a/INSTALL.txt +++ b/INSTALL.txt @@ -1,5 +1,5 @@ (* OASIS_START *) -(* DO NOT EDIT (digest: e3fb4c0dc642a0fa3a3b5f364e807c65) *) +(* DO NOT EDIT (digest: 19a52aeb37aeed4193b8687ec31fc8a1) *) This is the INSTALL file for the pa_ounit distribution. @@ -13,7 +13,7 @@ In order to compile this package, you will need: * ocaml (>= 4.00.0) * findlib (>= 1.3.2) -* oUnit for library pa_ounit_lib +* compiler-libs for library pa_ounit_syntax Installing ========== @@ -2,11 +2,11 @@ OASISFormat: 0.3 OCamlVersion: >= 4.00.0 FindlibVersion: >= 1.3.2 Name: pa_ounit -Version: 111.28.00 +Version: 113.00.00 Synopsis: OCaml inline testing. -Authors: Jane Street Capital LLC <opensource@janestreet.com> -Copyrights: (C) 2009-2013 Jane Street Capital LLC <opensource@janestreet.com> -Maintainers: Jane Street Capital LLC <opensource@janestreet.com> +Authors: Jane Street Group, LLC <opensource@janestreet.com> +Copyrights: (C) 2009-2013 Jane Street Group LLC <opensource@janestreet.com> +Maintainers: Jane Street Group, LLC <opensource@janestreet.com> License: Apache-2.0 LicenseFile: LICENSE.txt Homepage: https://github.com/janestreet/pa_ounit @@ -16,21 +16,21 @@ XStdFilesREADME: false BuildTools: ocamlbuild, camlp4o Library pa_ounit_lib - Path: lib + Path: runtime-lib FindlibName: pa_ounit Pack: true Modules: Runtime - BuildDepends: oUnit XMETADescription: Runtime support for pa_ounit Library pa_ounit_syntax - Path: syntax + Path: src Modules: Pa_ounit FindlibName: syntax FindlibParent: pa_ounit_lib BuildDepends: camlp4.extend, camlp4.lib, - camlp4.quotations + camlp4.quotations, + compiler-libs.common XMETAType: syntax - XMETARequires: camlp4 + XMETARequires: camlp4, compiler-libs.common XMETADescription: Syntax extension writing inline tests @@ -1,8 +1,9 @@ # OASIS_START -# DO NOT EDIT (digest: c31af085e1c232fd301f1f9edb315386) +# DO NOT EDIT (digest: 1f8239e59a87bbe613afdbdeafac3835) # Ignore VCS directories, you can use the same kind of rule outside # OASIS_START/STOP if you want to exclude directories that contains # useless stuff for the build process +true: annot, bin_annot <**/.svn>: -traverse <**/.svn>: not_hygienic ".bzr": -traverse @@ -14,13 +15,13 @@ "_darcs": -traverse "_darcs": not_hygienic # Library pa_ounit_lib -"lib/pa_ounit_lib.cmxs": use_pa_ounit_lib -"lib/runtime.cmx": for-pack(Pa_ounit_lib) -<lib/*.ml{,i}>: package(oUnit) +"runtime-lib/pa_ounit_lib.cmxs": use_pa_ounit_lib +"runtime-lib/runtime.cmx": for-pack(Pa_ounit_lib) # Library pa_ounit_syntax -"syntax/pa_ounit_syntax.cmxs": use_pa_ounit_syntax -<syntax/*.ml{,i}>: package(camlp4.extend) -<syntax/*.ml{,i}>: package(camlp4.lib) -<syntax/*.ml{,i}>: package(camlp4.quotations) +"src/pa_ounit_syntax.cmxs": use_pa_ounit_syntax +<src/*.ml{,i,y}>: package(camlp4.extend) +<src/*.ml{,i,y}>: package(camlp4.lib) +<src/*.ml{,i,y}>: package(camlp4.quotations) +<src/*.ml{,i,y}>: package(compiler-libs.common) # OASIS_STOP -<syntax/pa_ounit.ml>: syntax_camlp4o +<src/pa_ounit.ml>: syntax_camlp4o diff --git a/lib_test/pa_ounit_test.ml b/lib_test/pa_ounit_test.ml deleted file mode 100644 index 05ad23b..0000000 --- a/lib_test/pa_ounit_test.ml +++ /dev/null @@ -1,13 +0,0 @@ -TEST = false -TEST = raise Exit -TEST_MODULE "name" = struct - TEST = false - TEST = false - TEST = raise Exit - TEST_MODULE = struct - let () = raise Exit - end -end -TEST_MODULE = struct - let () = raise Exit -end diff --git a/lib_test/test.expected b/lib_test/test.expected deleted file mode 100644 index 61148c0..0000000 --- a/lib_test/test.expected +++ /dev/null @@ -1,28 +0,0 @@ -File "pa_ounit_test.ml", line 1, characters 0-12: <<false>> is false. - -File "pa_ounit_test.ml", line 2, characters 0-17: <<raise Exit>> threw Pervasives.Exit. - Raised at file "pa_ounit_test.ml", line 2, characters 13-17 - Called from file "runtime.ml", line XXX, characters XXX-XXX - -File "pa_ounit_test.ml", line 4, characters 2-14: <<false>> is false. - in TEST_MODULE at file "pa_ounit_test.ml", line 3, characters 0-134: name - -File "pa_ounit_test.ml", line 5, characters 2-14: <<false>> is false. - in TEST_MODULE at file "pa_ounit_test.ml", line 3, characters 0-134: name - -File "pa_ounit_test.ml", line 6, characters 2-19: <<raise Exit>> threw Pervasives.Exit. - Raised at file "pa_ounit_test.ml", line 6, characters 15-19 - Called from file "runtime.ml", line XXX, characters XXX-XXX - in TEST_MODULE at file "pa_ounit_test.ml", line 3, characters 0-134: name - -TEST_MODULE threw Pervasives.Exit. - Raised at file "pa_ounit_test.ml", line 8, characters 19-23 - Called from file "runtime.ml", line XXX, characters XXX-XXX - Re-raised at file "runtime.ml", line XXX, characters XXX-XXX - in TEST_MODULE at file "pa_ounit_test.ml", line 3, characters 0-134: name - -TEST_MODULE threw Pervasives.Exit. - Raised at file "pa_ounit_test.ml", line 12, characters 17-21 - Called from file "runtime.ml", line XXX, characters XXX-XXX - Re-raised at file "runtime.ml", line XXX, characters XXX-XXX - diff --git a/myocamlbuild.ml b/myocamlbuild.ml index 388a0a4..559593d 100644 --- a/myocamlbuild.ml +++ b/myocamlbuild.ml @@ -1,5 +1,5 @@ (* OASIS_START *) -(* DO NOT EDIT (digest: 1533d6862a81a55a777d143530f81f39) *) +(* DO NOT EDIT (digest: 52699fa15a989aa1b89ba1604eb238dd) *) module OASISGettext = struct (* # 22 "src/oasis/OASISGettext.ml" *) @@ -249,6 +249,9 @@ module MyOCamlbuildFindlib = struct *) open Ocamlbuild_plugin + type conf = + { no_automatic_syntax: bool; + } (* these functions are not really officially exported *) let run_and_read = @@ -315,7 +318,7 @@ module MyOCamlbuildFindlib = struct (* This lists all supported packages. *) let find_packages () = - List.map before_space (split_nl & run_and_read "ocamlfind list") + List.map before_space (split_nl & run_and_read (exec_from_conf "ocamlfind" ^ " list")) (* Mock to list available syntaxes. *) @@ -338,7 +341,7 @@ module MyOCamlbuildFindlib = struct ] - let dispatch = + let dispatch conf = function | After_options -> (* By using Before_options one let command line options have an higher @@ -357,31 +360,39 @@ module MyOCamlbuildFindlib = struct * -linkpkg *) flag ["ocaml"; "link"; "program"] & A"-linkpkg"; - (* For each ocamlfind package one inject the -package option when - * compiling, computing dependencies, generating documentation and - * linking. *) - List.iter - begin fun pkg -> - let base_args = [A"-package"; A pkg] in - (* TODO: consider how to really choose camlp4o or camlp4r. *) - let syn_args = [A"-syntax"; A "camlp4o"] in - let args = - (* Heuristic to identify syntax extensions: whether they end in - ".syntax"; some might not. - *) - if Filename.check_suffix pkg "syntax" || - List.mem pkg well_known_syntax then - syn_args @ base_args - else - base_args - in - flag ["ocaml"; "compile"; "pkg_"^pkg] & S args; - flag ["ocaml"; "ocamldep"; "pkg_"^pkg] & S args; - flag ["ocaml"; "doc"; "pkg_"^pkg] & S args; - flag ["ocaml"; "link"; "pkg_"^pkg] & S base_args; - flag ["ocaml"; "infer_interface"; "pkg_"^pkg] & S args; - end - (find_packages ()); + if not (conf.no_automatic_syntax) then begin + (* For each ocamlfind package one inject the -package option when + * compiling, computing dependencies, generating documentation and + * linking. *) + List.iter + begin fun pkg -> + let base_args = [A"-package"; A pkg] in + (* TODO: consider how to really choose camlp4o or camlp4r. *) + let syn_args = [A"-syntax"; A "camlp4o"] in + let (args, pargs) = + (* Heuristic to identify syntax extensions: whether they end in + ".syntax"; some might not. + *) + if Filename.check_suffix pkg "syntax" || + List.mem pkg well_known_syntax then + (syn_args @ base_args, syn_args) + else + (base_args, []) + in + flag ["ocaml"; "compile"; "pkg_"^pkg] & S args; + flag ["ocaml"; "ocamldep"; "pkg_"^pkg] & S args; + flag ["ocaml"; "doc"; "pkg_"^pkg] & S args; + flag ["ocaml"; "link"; "pkg_"^pkg] & S base_args; + flag ["ocaml"; "infer_interface"; "pkg_"^pkg] & S args; + + (* TODO: Check if this is allowed for OCaml < 3.12.1 *) + flag ["ocaml"; "compile"; "package("^pkg^")"] & S pargs; + flag ["ocaml"; "ocamldep"; "package("^pkg^")"] & S pargs; + flag ["ocaml"; "doc"; "package("^pkg^")"] & S pargs; + flag ["ocaml"; "infer_interface"; "package("^pkg^")"] & S pargs; + end + (find_packages ()); + end; (* Like -package but for extensions syntax. Morover -syntax is useless * when linking. *) @@ -546,12 +557,13 @@ module MyOCamlbuildBase = struct (* When ocaml link something that use the C library, then one need that file to be up to date. + This holds both for programs and for libraries. *) - dep ["link"; "ocaml"; "program"; tag_libstubs lib] - [dir/"lib"^(nm_libstubs lib)^"."^(!Options.ext_lib)]; + dep ["link"; "ocaml"; tag_libstubs lib] + [dir/"lib"^(nm_libstubs lib)^"."^(!Options.ext_lib)]; - dep ["compile"; "ocaml"; "program"; tag_libstubs lib] - [dir/"lib"^(nm_libstubs lib)^"."^(!Options.ext_lib)]; + dep ["compile"; "ocaml"; tag_libstubs lib] + [dir/"lib"^(nm_libstubs lib)^"."^(!Options.ext_lib)]; (* TODO: be more specific about what depends on headers *) (* Depends on .h files *) @@ -580,31 +592,36 @@ module MyOCamlbuildBase = struct () - let dispatch_default t = + let dispatch_default conf t = dispatch_combine [ dispatch t; - MyOCamlbuildFindlib.dispatch; + MyOCamlbuildFindlib.dispatch conf; ] end -# 594 "myocamlbuild.ml" +# 606 "myocamlbuild.ml" open Ocamlbuild_plugin;; let package_default = { MyOCamlbuildBase.lib_ocaml = - [("pa_ounit_lib", ["lib"], []); ("pa_ounit_syntax", ["syntax"], [])]; + [ + ("pa_ounit_lib", ["runtime-lib"], []); + ("pa_ounit_syntax", ["src"], []) + ]; lib_c = []; flags = []; includes = [] } ;; -let dispatch_default = MyOCamlbuildBase.dispatch_default package_default;; +let conf = {MyOCamlbuildFindlib.no_automatic_syntax = false} + +let dispatch_default = MyOCamlbuildBase.dispatch_default conf package_default;; -# 609 "myocamlbuild.ml" +# 626 "myocamlbuild.ml" (* OASIS_STOP *) Ocamlbuild_plugin.dispatch dispatch_default;; diff --git a/lib/META b/runtime-lib/META index 0826346..c3f8563 100644 --- a/lib/META +++ b/runtime-lib/META @@ -1,17 +1,16 @@ # OASIS_START -# DO NOT EDIT (digest: 9e6720d18de7d049354425eb682a2fac) -version = "111.28.00" +# DO NOT EDIT (digest: 1dcd1e0f062281ca84f6b34fcca8bd5a) +version = "113.00.00" description = "Runtime support for pa_ounit" -requires = "oUnit" archive(byte) = "pa_ounit_lib.cma" archive(byte, plugin) = "pa_ounit_lib.cma" archive(native) = "pa_ounit_lib.cmxa" archive(native, plugin) = "pa_ounit_lib.cmxs" exists_if = "pa_ounit_lib.cma" package "syntax" ( - version = "111.28.00" + version = "113.00.00" description = "Syntax extension writing inline tests" - requires = "camlp4" + requires = "camlp4 compiler-libs.common" archive(syntax, preprocessor) = "pa_ounit_syntax.cma" archive(syntax, toploop) = "pa_ounit_syntax.cma" archive(syntax, preprocessor, native) = "pa_ounit_syntax.cmxa" diff --git a/lib/pa_ounit_lib.mldylib b/runtime-lib/pa_ounit_lib.mldylib index f42b948..f42b948 100644 --- a/lib/pa_ounit_lib.mldylib +++ b/runtime-lib/pa_ounit_lib.mldylib diff --git a/lib/pa_ounit_lib.mllib b/runtime-lib/pa_ounit_lib.mllib index f42b948..f42b948 100644 --- a/lib/pa_ounit_lib.mllib +++ b/runtime-lib/pa_ounit_lib.mllib diff --git a/lib/pa_ounit_lib.mlpack b/runtime-lib/pa_ounit_lib.mlpack index 34ff41a..34ff41a 100644 --- a/lib/pa_ounit_lib.mlpack +++ b/runtime-lib/pa_ounit_lib.mlpack diff --git a/lib/runtime.ml b/runtime-lib/runtime.ml index b69db87..e7d3d21 100644 --- a/lib/runtime.ml +++ b/runtime-lib/runtime.ml @@ -19,7 +19,7 @@ type end_pos = int let action : [ | `Ignore | `Run_lib of string * (filename * line_number option * bool ref) list -| `Collect of OUnit.test list ref +| `Collect of (unit -> unit) list ref ] ref = ref `Ignore let module_descr = ref [] let verbose = ref false @@ -31,6 +31,8 @@ let stop_on_error = ref false let log = ref None +let time_sec = ref 0. + let displayed_descr descr filename line start_pos end_pos = Printf.sprintf "File %S, line %d, characters %d-%d%s" filename line start_pos end_pos descr @@ -111,11 +113,28 @@ let () = | _ -> () +let testing = + match !action with + | `Run_lib _ -> true + | `Ignore -> false + | `Collect _ -> assert false + +let time f = + let before_sec = Sys.time () in + let res = + try f () + with e -> + time_sec := Sys.time () -. before_sec; + raise e + in + time_sec := Sys.time () -. before_sec; + res + let with_descr (descr : descr) f = let prev = !module_descr in module_descr := descr :: prev; try - f (); + time f; module_descr := prev; with e -> module_descr := prev; @@ -167,7 +186,7 @@ let eprintf_or_delay fmt = ) fmt let test (descr : descr) def_filename def_line_number start_pos end_pos f = - let descr = displayed_descr descr def_filename def_line_number start_pos end_pos in + let descr () = displayed_descr descr def_filename def_line_number start_pos end_pos in match !action with | `Run_lib (lib, l) -> let should_run = @@ -177,21 +196,29 @@ let test (descr : descr) def_filename def_line_number start_pos end_pos f = | _ :: _ -> position_match def_filename def_line_number l end in if should_run then begin + let descr = descr () in incr tests_ran; begin match !log with | None -> () | Some ch -> Printf.fprintf ch "%s\n%s" descr (string_of_module_descr ()) end; if !verbose then begin - Printf.printf "%s\n%!" descr + Printf.printf "%s%!" descr end; + let print_time_taken () = + (* If !list_test_names, this is is a harmless zero. *) + if !verbose then Printf.printf " (%.3f sec)\n%!" !time_sec; + in try - if not !list_test_names && not (f ()) then begin + let failed = not !list_test_names && not (time f) in + print_time_taken (); + if failed then begin incr tests_failed; eprintf_or_delay "%s is false.\n%s\n%!" descr (string_of_module_descr ()) end with exn -> + print_time_taken (); let backtrace = backtrace_indented ~by:2 in incr tests_failed; let exn_str = Printexc.to_string exn in @@ -201,9 +228,7 @@ let test (descr : descr) def_filename def_line_number start_pos end_pos f = end | `Ignore -> () | `Collect r -> - r := OUnit.TestCase (fun () -> - if not (f ()) then failwith descr - ) :: !r + r := (fun () -> if not (time f) then failwith (descr ())) :: !r let set_lib static_lib = @@ -224,23 +249,23 @@ let unset_lib static_lib = if lib = static_lib then dynamic_lib := None let test_unit descr def_filename def_line_number start_pos end_pos f = - test descr def_filename def_line_number start_pos end_pos (fun () -> f (); true) + test descr def_filename def_line_number start_pos end_pos (fun () -> time f; true) let collect f = let prev_action = !action in let tests = ref [] in action := `Collect tests; try - f (); + time f; let tests = List.rev !tests in action := prev_action; - OUnit.TestList tests + tests with e -> action := prev_action; raise e let test_module descr def_filename def_line_number start_pos end_pos f = - let descr = displayed_descr descr def_filename def_line_number start_pos end_pos in + let descr () = displayed_descr descr def_filename def_line_number start_pos end_pos in match !action with | `Run_lib (lib, _) -> (* run test_modules, in case they define the test we are looking for (if we are @@ -248,7 +273,7 @@ let test_module descr def_filename def_line_number start_pos end_pos f = if Some lib = !dynamic_lib then begin incr test_modules_ran; try - with_descr descr f + with_descr (descr ()) f with exn -> let backtrace = backtrace_indented ~by:2 in incr test_modules_failed; @@ -259,10 +284,8 @@ let test_module descr def_filename def_line_number start_pos end_pos f = end | `Ignore -> () | `Collect r -> - r := ( - (* tEST_MODULE are going to be executed inline, unlike before *) - OUnit.TestLabel (descr, collect f) - ) :: !r + (* tEST_MODULE are going to be executed inline, unlike before *) + r := List.rev_append (collect f) !r let summarize () = begin match !action with diff --git a/lib/runtime.mli b/runtime-lib/runtime.mli index a5057db..be4dd12 100644 --- a/lib/runtime.mli +++ b/runtime-lib/runtime.mli @@ -10,5 +10,6 @@ val test_unit : descr -> filename -> line_number -> start_pos -> end_pos -> (uni val test_module : descr -> filename -> line_number -> start_pos -> end_pos -> (unit -> unit) -> unit val summarize : unit -> unit -(* this function is meant to be called by hand, it should be in an other module *) -val collect : (unit -> unit) -> OUnit.test +(* These functions are meant to be called by hand, they should be in an other module. *) +val collect : (unit -> unit) -> (unit -> unit) list +val testing : bool @@ -1,7 +1,7 @@ (* OASIS_START *) -(* DO NOT EDIT (digest: e854bb0345234a14ab5974badf814002) *) +(* DO NOT EDIT (digest: 690a779f4bed4ae359989daba1f887e6) *) (* - Regenerated by OASIS v0.4.4 + Regenerated by OASIS v0.4.5 Visit http://oasis.forge.ocamlcore.org for more information and documentation about functions used in this file. *) @@ -240,11 +240,9 @@ module OASISString = struct let replace_chars f s = - let buf = String.make (String.length s) 'X' in - for i = 0 to String.length s - 1 do - buf.[i] <- f s.[i] - done; - buf + let buf = Buffer.create (String.length s) in + String.iter (fun c -> Buffer.add_char buf (f c)) s; + Buffer.contents buf end @@ -1727,6 +1725,13 @@ module OASISFeatures = struct (fun () -> s_ "Allows the OASIS section comments and digest to be omitted in \ generated files.") + + let no_automatic_syntax = + create "no_automatic_syntax" alpha + (fun () -> + s_ "Disable the automatic inclusion of -syntax camlp4o for packages \ + that matches the internal heuristic (if a dependency ends with \ + a .syntax or is a well known syntax).") end module OASISUnixPath = struct @@ -2097,16 +2102,6 @@ module OASISLibrary = struct lst in - (* The headers that should be compiled along *) - let headers = - if lib.lib_pack then - [] - else - find_modules - lib.lib_modules - "cmi" - in - (* The .cmx that be compiled along *) let cmxs = let should_be_built = @@ -2132,12 +2127,32 @@ module OASISLibrary = struct [] in + (* The headers and annot/cmt files that should be compiled along *) + let headers = + let sufx = + if lib.lib_pack + then [".cmti"; ".cmt"; ".annot"] + else [".cmi"; ".cmti"; ".cmt"; ".annot"] + in + List.map + begin + List.fold_left + begin fun accu s -> + let dot = String.rindex s '.' in + let base = String.sub s 0 dot in + List.map ((^) base) sufx @ accu + end + [] + end + (find_modules lib.lib_modules "cmi") + in + (* Compute what libraries should be built *) let acc_nopath = (* Add the packed header file if required *) let add_pack_header acc = if lib.lib_pack then - [cs.cs_name^".cmi"] :: acc + [cs.cs_name^".cmi"; cs.cs_name^".cmti"; cs.cs_name^".cmt"] :: acc else acc in @@ -2497,13 +2512,13 @@ module OASISFindlib = struct in let library_name_of_findlib_name = - Lazy.lazy_from_fun - (fun () -> - (* Revert findlib_name_of_library_name. *) - MapString.fold - (fun k v mp -> MapString.add v k mp) - fndlb_name_of_lib_name - MapString.empty) + lazy begin + (* Revert findlib_name_of_library_name. *) + MapString.fold + (fun k v mp -> MapString.add v k mp) + fndlb_name_of_lib_name + MapString.empty + end in let library_name_of_findlib_name fndlb_nm = try @@ -2873,7 +2888,7 @@ module OASISFileUtil = struct end -# 2878 "setup.ml" +# 2893 "setup.ml" module BaseEnvLight = struct (* # 22 "src/base/BaseEnvLight.ml" *) @@ -2978,7 +2993,7 @@ module BaseEnvLight = struct end -# 2983 "setup.ml" +# 2998 "setup.ml" module BaseContext = struct (* # 22 "src/base/BaseContext.ml" *) @@ -5389,7 +5404,7 @@ module BaseSetup = struct end -# 5394 "setup.ml" +# 5409 "setup.ml" module InternalConfigurePlugin = struct (* # 22 "src/plugins/internal/InternalConfigurePlugin.ml" *) @@ -5825,6 +5840,17 @@ module InternalInstallPlugin = struct lst in + let make_fnames modul sufx = + List.fold_right + begin fun sufx accu -> + (String.capitalize modul ^ sufx) :: + (String.uncapitalize modul ^ sufx) :: + accu + end + sufx + [] + in + (** Install all libraries *) let install_libs pkg = @@ -5845,27 +5871,29 @@ module InternalInstallPlugin = struct OASISHostPath.of_unix bs.bs_path in List.fold_left - (fun acc modul -> - try - List.find - OASISFileUtil.file_exists_case - (List.map - (Filename.concat path) - [modul^".mli"; - modul^".ml"; - String.uncapitalize modul^".mli"; - String.capitalize modul^".mli"; - String.uncapitalize modul^".ml"; - String.capitalize modul^".ml"]) - :: acc - with Not_found -> - begin - warning - (f_ "Cannot find source header for module %s \ - in library %s") - modul cs.cs_name; - acc - end) + begin fun acc modul -> + begin + try + [List.find + OASISFileUtil.file_exists_case + (List.map + (Filename.concat path) + (make_fnames modul [".mli"; ".ml"]))] + with Not_found -> + warning + (f_ "Cannot find source header for module %s \ + in library %s") + modul cs.cs_name; + [] + end + @ + List.filter + OASISFileUtil.file_exists_case + (List.map + (Filename.concat path) + (make_fnames modul [".annot";".cmti";".cmt"])) + @ acc + end acc lib.lib_modules in @@ -5913,27 +5941,29 @@ module InternalInstallPlugin = struct OASISHostPath.of_unix bs.bs_path in List.fold_left - (fun acc modul -> - try - List.find - OASISFileUtil.file_exists_case - (List.map - (Filename.concat path) - [modul^".mli"; - modul^".ml"; - String.uncapitalize modul^".mli"; - String.capitalize modul^".mli"; - String.uncapitalize modul^".ml"; - String.capitalize modul^".ml"]) - :: acc - with Not_found -> - begin - warning - (f_ "Cannot find source header for module %s \ - in object %s") - modul cs.cs_name; - acc - end) + begin fun acc modul -> + begin + try + [List.find + OASISFileUtil.file_exists_case + (List.map + (Filename.concat path) + (make_fnames modul [".mli"; ".ml"]))] + with Not_found -> + warning + (f_ "Cannot find source header for module %s \ + in object %s") + modul cs.cs_name; + [] + end + @ + List.filter + OASISFileUtil.file_exists_case + (List.map + (Filename.concat path) + (make_fnames modul [".annot";".cmti";".cmt"])) + @ acc + end acc obj.obj_modules in @@ -6238,7 +6268,7 @@ module InternalInstallPlugin = struct end -# 6243 "setup.ml" +# 6273 "setup.ml" module OCamlbuildCommon = struct (* # 22 "src/plugins/ocamlbuild/OCamlbuildCommon.ml" *) @@ -6296,6 +6326,11 @@ module OCamlbuildCommon = struct else []; + if bool_of_string (tests ()) then + ["-tag"; "tests"] + else + []; + if bool_of_string (profile ()) then ["-tag"; "profile"] else @@ -6611,7 +6646,7 @@ module OCamlbuildDocPlugin = struct end -# 6616 "setup.ml" +# 6651 "setup.ml" open OASISTypes;; let setup_t = @@ -6636,7 +6671,7 @@ let setup_t = alpha_features = []; beta_features = []; name = "pa_ounit"; - version = "111.28.00"; + version = "113.00.00"; license = OASISLicense.DEP5License (OASISLicense.DEP5Unit @@ -6648,11 +6683,11 @@ let setup_t = license_file = Some "LICENSE.txt"; copyrights = [ - "(C) 2009-2013 Jane Street Capital LLC <opensource@janestreet.com>" + "(C) 2009-2013 Jane Street Group LLC <opensource@janestreet.com>" ]; maintainers = - ["Jane Street Capital LLC <opensource@janestreet.com>"]; - authors = ["Jane Street Capital LLC <opensource@janestreet.com>"]; + ["Jane Street Group"; "LLC <opensource@janestreet.com>"]; + authors = ["Jane Street Group"; "LLC <opensource@janestreet.com>"]; homepage = Some "https://github.com/janestreet/pa_ounit"; synopsis = "OCaml inline testing."; description = None; @@ -6702,9 +6737,9 @@ let setup_t = { bs_build = [(OASISExpr.EBool true, true)]; bs_install = [(OASISExpr.EBool true, true)]; - bs_path = "lib"; + bs_path = "runtime-lib"; bs_compiled_object = Best; - bs_build_depends = [FindlibPackage ("oUnit", None)]; + bs_build_depends = []; bs_build_tools = [ExternalTool "ocamlbuild"; ExternalTool "camlp4o"]; bs_c_sources = []; @@ -6733,13 +6768,14 @@ let setup_t = { bs_build = [(OASISExpr.EBool true, true)]; bs_install = [(OASISExpr.EBool true, true)]; - bs_path = "syntax"; + bs_path = "src"; bs_compiled_object = Best; bs_build_depends = [ FindlibPackage ("camlp4.extend", None); FindlibPackage ("camlp4.lib", None); - FindlibPackage ("camlp4.quotations", None) + FindlibPackage ("camlp4.quotations", None); + FindlibPackage ("compiler-libs.common", None) ]; bs_build_tools = [ExternalTool "ocamlbuild"; ExternalTool "camlp4o"]; @@ -6772,8 +6808,8 @@ let setup_t = plugin_data = [] }; oasis_fn = Some "_oasis"; - oasis_version = "0.4.4"; - oasis_digest = Some "F\168\166h\219\244\231\217\243W\204\253mo*\183"; + oasis_version = "0.4.5"; + oasis_digest = Some "\029\255\139\176b\165\n\145h\015\244\184\205\152Xi"; oasis_exec = None; oasis_setup_args = []; setup_update = false @@ -6781,6 +6817,6 @@ let setup_t = let setup () = BaseSetup.setup setup_t;; -# 6787 "setup.ml" +# 6823 "setup.ml" (* OASIS_STOP *) let () = setup () diff --git a/syntax/pa_ounit.ml b/src/pa_ounit.ml index 17e8067..2ff8239 100644 --- a/syntax/pa_ounit.ml +++ b/src/pa_ounit.ml @@ -5,7 +5,7 @@ let libname = ref None -let drop_tests = ref false +let drop_tests : [`No | `Deadcode | `Remove ] ref = ref `No let () = (* Beware that camlp4 has a broken command line parser and using the flag -ounit-ident will not work, because camlp4 will interpret that as @@ -15,23 +15,58 @@ let () = Camlp4.Options.add "-pa-ounit-lib" (Arg.String (fun s -> libname := Some s)) "A base name to use for generated identifiers\ (has to be globally unique in a program)."; - Camlp4.Options.add "-pa-ounit-drop" (Arg.Set drop_tests) "Drop unit tests" + Camlp4.Options.add "-pa-ounit-drop" + (Arg.Unit (fun () -> drop_tests:= `Remove)) + "Drop unit tests"; + Camlp4.Options.add "-pa-ounit-drop-with-deadcode" + (Arg.Unit (fun () -> drop_tests:= `Deadcode)) + "Drop unit tests by wrapping them inside deadcode to prevent unused variable warnings." open Camlp4.PreCast +let maybe_drop _loc expr = + match !drop_tests with + | `No -> <:str_item< value () = $expr$; >> + | `Deadcode -> <:str_item< value () = if False then $expr$ else (); >> + | `Remove -> <:str_item< >> + let libname () = match !libname with | None -> "dummy" (* would break for the external tree if I gave an error, I think *) | Some name -> name -let syntax_printer = - let module PP = Camlp4.Printers.OCaml.Make (Syntax) in - new PP.printer ~comments:false () +(* To allow us to validate the migration to ppx, we need to modify the [string_of_expr] + which is used for message strings, to use the ocaml compiler Ast printer - which is + what the ppx version uses. + + This was the original definition of: [string_of_expr] + + let syntax_printer = + let module PP = Camlp4.Printers.OCaml.Make (Syntax) in + new PP.printer ~comments:false () + + let string_of_expr expr = + let buffer = Buffer.create 16 in + Format.bprintf buffer "%a%!" syntax_printer#expr expr; + Buffer.contents buffer +*) -let string_of_expr expr = - let buffer = Buffer.create 16 in - Format.bprintf buffer "%a%!" syntax_printer#expr expr; - Buffer.contents buffer +let string_of_expr (expr: Ast.expr) : string = (* via ocaml AST *) + let module Convert = Camlp4.Struct.Camlp4Ast2OCamlAst.Make (Ast) in + (* The call to [Convert.str_item] may (incredibly!) mutate float strings contained in + the AST, so we map the AST first, copying the float strings... *) + let copy_floats_in_expr = object + inherit Ast.map as super + method! expr x = + match super#expr x with + | ExFlo (loc,string) -> ExFlo (loc,String.copy string) + | e -> e + end in + let expr = copy_floats_in_expr#expr expr in + let str : Ast.str_item = StExp (Ast.loc_of_expr expr,expr) in + match (Convert.str_item str) with + | [{pstr_desc = Pstr_eval (e,_); _}] -> Pprintast.string_of_expression e + | _ -> assert false let rec short_desc_of_expr ~max_len = function | <:expr< let $_$ in $e$ >> @@ -68,16 +103,12 @@ let descr _loc e_opt id_opt = <:expr< $int:string_of_int end_pos$ >> let apply_to_descr lid _loc e_opt id_opt more_arg = - if !drop_tests then - <:str_item< >> - else begin - let descr, filename, line, start_pos, end_pos = descr _loc e_opt id_opt in - <:str_item< - value () = - Pa_ounit_lib.Runtime.$lid:lid$ $descr$ $filename$ $line$ $start_pos$ $end_pos$ - $more_arg$; + let descr, filename, line, start_pos, end_pos = descr _loc e_opt id_opt in + maybe_drop _loc + <:expr< + Pa_ounit_lib.Runtime.$lid:lid$ $descr$ $filename$ $line$ $start_pos$ $end_pos$ + $more_arg$ >> - end EXTEND Gram GLOBAL: Syntax.str_item; @@ -96,12 +127,9 @@ let () = let current_str_parser, _ = Camlp4.Register.current_parser () in Camlp4.Register.register_str_item_parser (fun ?directive_handler _loc stream -> let ml = current_str_parser ?directive_handler _loc stream in - if !drop_tests then - ml - else - <:str_item< - value () = Pa_ounit_lib.Runtime.set_lib $str:libname ()$; - $ml$; - value () = Pa_ounit_lib.Runtime.unset_lib $str:libname ()$; - >> + <:str_item< + $maybe_drop _loc <:expr<Pa_ounit_lib.Runtime.set_lib $str:libname ()$>>$; + $ml$; + $maybe_drop _loc <:expr<Pa_ounit_lib.Runtime.unset_lib $str:libname ()$>>$; + >> ) diff --git a/src/pa_ounit.mli b/src/pa_ounit.mli new file mode 100644 index 0000000..256fed7 --- /dev/null +++ b/src/pa_ounit.mli @@ -0,0 +1,3 @@ + +val libname : unit -> string +val string_of_expr : Camlp4.PreCast.Ast.expr -> string diff --git a/syntax/pa_ounit_syntax.mldylib b/src/pa_ounit_syntax.mldylib index ebf78f1..ebf78f1 100644 --- a/syntax/pa_ounit_syntax.mldylib +++ b/src/pa_ounit_syntax.mldylib diff --git a/syntax/pa_ounit_syntax.mllib b/src/pa_ounit_syntax.mllib index ebf78f1..ebf78f1 100644 --- a/syntax/pa_ounit_syntax.mllib +++ b/src/pa_ounit_syntax.mllib diff --git a/test/failures.ml b/test/failures.ml new file mode 100644 index 0000000..c685ffd --- /dev/null +++ b/test/failures.ml @@ -0,0 +1,21 @@ +let () = + match Sys.getenv "ENABLE_FAILURES" with + | exception Not_found -> () + | (_ : string) -> + let module M = struct + TEST = false + TEST = raise Exit + TEST_MODULE "name" = struct + TEST = false + TEST = false + TEST = raise Exit + TEST_MODULE = struct + let () = raise Exit + end + end + TEST_MODULE = struct + let () = raise Exit + end + end in + () +;; diff --git a/lib_test/test.ml b/test/order.ml index fe77ec6..fe77ec6 100644 --- a/lib_test/test.ml +++ b/test/order.ml diff --git a/test/test.expected b/test/test.expected new file mode 100644 index 0000000..0e8804b --- /dev/null +++ b/test/test.expected @@ -0,0 +1,34 @@ +File "failures.ml", line 6, characters 6-18: <<false>> is false. + +File "failures.ml", line 7, characters 6-23: <<raise Exit>> threw Pervasives.Exit. + Raised at file "failures.ml", line 7, characters 19-23 + Called from file "runtime.ml", line XXX, characters XXX-XXX + Re-raised at file "runtime.ml", line XXX, characters XXX-XXX + +File "failures.ml", line 9, characters 8-20: <<false>> is false. + in TEST_MODULE at file "failures.ml", line 8, characters 6-182: name + +File "failures.ml", line 10, characters 8-20: <<false>> is false. + in TEST_MODULE at file "failures.ml", line 8, characters 6-182: name + +File "failures.ml", line 11, characters 8-25: <<raise Exit>> threw Pervasives.Exit. + Raised at file "failures.ml", line 11, characters 21-25 + Called from file "runtime.ml", line XXX, characters XXX-XXX + Re-raised at file "runtime.ml", line XXX, characters XXX-XXX + in TEST_MODULE at file "failures.ml", line 8, characters 6-182: name + +TEST_MODULE threw Pervasives.Exit. + Raised at file "failures.ml", line 13, characters 25-29 + Called from file "runtime.ml", line XXX, characters XXX-XXX + Re-raised at file "runtime.ml", line XXX, characters XXX-XXX + Re-raised at file "runtime.ml", line XXX, characters XXX-XXX + in TEST_MODULE at file "failures.ml", line 8, characters 6-182: name + +TEST_MODULE threw Pervasives.Exit. + Raised at file "failures.ml", line 17, characters 23-27 + Called from file "runtime.ml", line XXX, characters XXX-XXX + Re-raised at file "runtime.ml", line XXX, characters XXX-XXX + Re-raised at file "runtime.ml", line XXX, characters XXX-XXX + +FAILED 5 / 11 tests, 2 TEST_MODULES +code: 2 |