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 <rudi.grinberg@gmail.com>
This commit is contained in:
parent
15e06f8008
commit
cf86781ad2
|
@ -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
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
|
@ -15,3 +15,48 @@ virtual libraries may not implement their virtual modules
|
||||||
^^^
|
^^^
|
||||||
Error: Module Foo has an implementation, it cannot be listed here
|
Error: Module Foo has an implementation, it cannot be listed here
|
||||||
[1]
|
[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.
|
||||||
|
-------------------------
|
||||||
|
|
Loading…
Reference in New Issue