From 59b2ff127d549f7f96303392eedde30fa744da47 Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Tue, 24 Nov 2020 20:04:59 -0800 Subject: [PATCH] add modules_without_implementation tests Signed-off-by: Rudi Grinberg --- .../test-cases/github3766.t/run.t | 88 +++++++++++++++++++ .../test-cases/github3766.t/test.ml | 15 +++- 2 files changed, 99 insertions(+), 4 deletions(-) diff --git a/test/blackbox-tests/test-cases/github3766.t/run.t b/test/blackbox-tests/test-cases/github3766.t/run.t index 7a7684f11719..7ec4441623e4 100644 --- a/test/blackbox-tests/test-cases/github3766.t/run.t +++ b/test/blackbox-tests/test-cases/github3766.t/run.t @@ -86,3 +86,91 @@ A single test case is in test.ml % OCAMLPATH=_build/install/default/lib dune exec --build-dir=_b2 ./exe/b.exe exe working + + $ ./test.exe mli_only_no_stubs --mli-only < (library + > (public_name foo) + > (modules_without_implementation foo)) + > EOF + -> creating dune-project + # build the library and see if .a is present + -> creating dune + -> creating mli_only_no_stubs.mli + % dune build --root . @install + File "lib/dune", line 3, characters 33-36: + 3 | (modules_without_implementation foo)) + ^^^ + Error: Module Foo doesn't exist. + [1] + % ls _build/install/default/lib/foo/*.a + ls: _build/install/default/lib/foo/*.a: No such file or directory + [1] + + # create a dummy executable to test + -> creating dune + -> creating b.ml + + # make sure that this library is usable locally + % dune exec ./exe/b.exe + File "lib/dune", line 3, characters 33-36: + 3 | (modules_without_implementation foo)) + ^^^ + Error: Module Foo doesn't exist. + [1] + + # make sure that this library is usable externally + % rm -rf lib + % OCAMLPATH=_build/install/default/lib dune exec --build-dir=_b2 ./exe/b.exe + File "exe/dune", line 5, characters 12-15: + 5 | (libraries foo)) + ^^^ + Error: Library "foo" not found. + Hint: try: + dune external-lib-deps --missing --build-dir _b2 ./exe/b.exe + [1] + + + $ ./test.exe mli_only_no_stubs --mli-only --stub baz < (library + > (public_name foo) + > (foreign_stubs (language c) (names baz)) + > (modules_without_implementation foo)) + > EOF + -> creating dune-project + # build the library and see if .a is present + -> creating dune + -> creating baz.c + -> creating mli_only_no_stubs.mli + % dune build --root . @install + File "lib/dune", line 4, characters 33-36: + 4 | (modules_without_implementation foo)) + ^^^ + Error: Module Foo doesn't exist. + [1] + % ls _build/install/default/lib/foo/*.a + ls: _build/install/default/lib/foo/*.a: No such file or directory + [1] + + # create a dummy executable to test + -> creating dune + -> creating b.ml + + # make sure that this library is usable locally + % dune exec ./exe/b.exe + File "lib/dune", line 4, characters 33-36: + 4 | (modules_without_implementation foo)) + ^^^ + Error: Module Foo doesn't exist. + [1] + + # make sure that this library is usable externally + % rm -rf lib + % OCAMLPATH=_build/install/default/lib dune exec --build-dir=_b2 ./exe/b.exe + File "exe/dune", line 5, characters 12-15: + 5 | (libraries foo)) + ^^^ + Error: Library "foo" not found. + Hint: try: + dune external-lib-deps --missing --build-dir _b2 ./exe/b.exe + [1] + diff --git a/test/blackbox-tests/test-cases/github3766.t/test.ml b/test/blackbox-tests/test-cases/github3766.t/test.ml index 943a9935cf7a..0c576eb772a0 100644 --- a/test/blackbox-tests/test-cases/github3766.t/test.ml +++ b/test/blackbox-tests/test-cases/github3766.t/test.ml @@ -1,5 +1,7 @@ open! Stdune +let mli_only = ref false + let stub = ref None let name = ref "" @@ -7,19 +9,23 @@ let name = ref "" let () = let anon s = name := s in let set_stub s = stub := Some s in - let args = [ ("--stub", Arg.String set_stub, "C stub") ] in + let args = + [ ("--stub", Arg.String set_stub, "C stub") + ; ("--mli-only", Arg.Set mli_only, "mli only") + ] + in Arg.parse (Arg.align args) anon "./test.exe [--stub]" let stub = !stub +let mli_only = !mli_only + let name = !name let stanza = Io.read_all stdin let cwd () = Path.external_ (Path.External.cwd ()) -(* let dir = Path.relative cwd name *) - let chdir dir = Unix.chdir (Path.to_absolute_filename dir) let prefix = "test.exe." @@ -78,7 +84,8 @@ let () = in_dir "lib" ~f:(fun () -> file "dune" stanza; Option.iter stub ~f:(fun name -> - file (name ^ ".c") "void foo() {}")); + file (name ^ ".c") "void foo() {}"); + if mli_only then file (name ^ ".mli") "type x = unit"); cmd "dune build --root . @install"; cmd "ls _build/install/default/lib/foo/*.a");