From cf86781ad2a38de625f1ccd8a5207ef441bb63a1 Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Tue, 4 Sep 2018 10:02:43 +0400 Subject: [PATCH] Add tests for all permutations of virtual modules field All permutations of: * presence of implementation * presence in virtual_modules * presence in modules_without_implementation Signed-off-by: Rudi Grinberg --- .../test-cases/variants/module-fields/test.ml | 60 +++++++++++++++++++ test/blackbox-tests/test-cases/variants/run.t | 45 ++++++++++++++ 2 files changed, 105 insertions(+) create mode 100644 test/blackbox-tests/test-cases/variants/module-fields/test.ml diff --git a/test/blackbox-tests/test-cases/variants/module-fields/test.ml b/test/blackbox-tests/test-cases/variants/module-fields/test.ml new file mode 100644 index 00000000..54b51089 --- /dev/null +++ b/test/blackbox-tests/test-cases/variants/module-fields/test.ml @@ -0,0 +1,60 @@ +module List = ListLabels +open Printf + +let write_file ~file ~contents = + let ch = open_out file in + output_string ch contents; + close_out_noerr ch + +let lib_stanza ~modules_without_implementation ~virtual_modules = + sprintf "(library\n (name foo)%s%s)" + (if modules_without_implementation then + "\n (modules_without_implementation m)" + else + "") + (if virtual_modules then + "\n (virtual_modules m)" + else + "") + +let chdir dir ~f = + let old_dir = Sys.getcwd () in + begin try + Sys.chdir dir; + f () + with e -> + Sys.chdir old_dir; + raise e + end; + Sys.chdir old_dir + +let gen_test ~impl ~modules_without_implementation ~virtual_modules = + printf "impl: %b. modules_without_implementation: %b. virtual_modules: %b\n%!" + impl modules_without_implementation virtual_modules; + let dir = + sprintf "%b-%b-%b" impl modules_without_implementation virtual_modules + in + let _ = Sys.command (sprintf "mkdir -p %s" dir) in + chdir dir ~f:(fun () -> + write_file ~file:"dune-project" + ~contents:"(lang dune 1.2)\n\ + (using in_development_do_not_use_variants 0.1)"; + write_file ~file:"m.mli" ~contents:""; + if impl then + write_file ~file:"m.ml" ~contents:""; + write_file ~file:"dune" ~contents:( + lib_stanza ~modules_without_implementation ~virtual_modules); + ignore (Sys.command "dune build"); + print_endline "-------------------------" + ) + +let bools = [true; false] + +let () = + List.iter bools ~f:(fun impl -> + List.iter bools ~f:(fun modules_without_implementation -> + List.iter bools ~f:(fun virtual_modules -> + gen_test ~impl ~modules_without_implementation ~virtual_modules + ) + ) + ) diff --git a/test/blackbox-tests/test-cases/variants/run.t b/test/blackbox-tests/test-cases/variants/run.t index 285a1ad2..4df2a7ec 100644 --- a/test/blackbox-tests/test-cases/variants/run.t +++ b/test/blackbox-tests/test-cases/variants/run.t @@ -15,3 +15,48 @@ virtual libraries may not implement their virtual modules ^^^ Error: Module Foo has an implementation, it cannot be listed here [1] + + $ cd module-fields && ocaml test.ml + impl: true. modules_without_implementation: true. virtual_modules: true + File "dune", line 3, characters 33-34: + 3 | (modules_without_implementation m) + ^ + Error: Module M has an implementation, it cannot be listed here + ------------------------- + impl: true. modules_without_implementation: true. virtual_modules: false + File "dune", line 3, characters 33-34: + 3 | (modules_without_implementation m)) + ^ + Error: Module M has an implementation, it cannot be listed here + ------------------------- + impl: true. modules_without_implementation: false. virtual_modules: true + File "dune", line 3, characters 18-19: + 3 | (virtual_modules m)) + ^ + Error: Module M has an implementation, it cannot be listed here + ------------------------- + impl: true. modules_without_implementation: false. virtual_modules: false + ------------------------- + impl: false. modules_without_implementation: true. virtual_modules: true + File "dune", line 4, characters 18-19: + 4 | (virtual_modules m)) + ^ + Error: These modules appear in the virtual_libraries and modules_without_implementation fields: + - m + This is not possible. + ------------------------- + impl: false. modules_without_implementation: true. virtual_modules: false + ------------------------- + impl: false. modules_without_implementation: false. virtual_modules: true + ------------------------- + impl: false. modules_without_implementation: false. virtual_modules: false + File "dune", line 1, characters 0-21: + 1 | (library + 2 | (name foo)) + Warning: Some modules don't have an implementation. + You need to add the following field to this stanza: + + (modules_without_implementation m) + + This will become an error in the future. + -------------------------