Skip to content

Commit

Permalink
add modules_without_implementation tests
Browse files Browse the repository at this point in the history
Signed-off-by: Rudi Grinberg <[email protected]>
  • Loading branch information
rgrinberg committed Nov 25, 2020
1 parent 71c8b11 commit 59b2ff1
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 4 deletions.
88 changes: 88 additions & 0 deletions test/blackbox-tests/test-cases/github3766.t/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -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 <<EOF
> (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 <<EOF
> (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]

15 changes: 11 additions & 4 deletions test/blackbox-tests/test-cases/github3766.t/test.ml
Original file line number Diff line number Diff line change
@@ -1,25 +1,31 @@
open! Stdune

let mli_only = ref false

let stub = ref None

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 <name> [--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."
Expand Down Expand Up @@ -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");

Expand Down

0 comments on commit 59b2ff1

Please sign in to comment.