Skip to content

Commit

Permalink
Alternative names
Browse files Browse the repository at this point in the history
Signed-off-by: Hugo Heuzard <[email protected]>
  • Loading branch information
hhugo committed Jan 27, 2025
1 parent 6006844 commit 52fd9bd
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 19 deletions.
11 changes: 7 additions & 4 deletions src/dune_rules/dir_status.ml
Original file line number Diff line number Diff line change
Expand Up @@ -178,12 +178,15 @@ let directory_targets_of_library
| false -> Path.Build.Map.empty
| true ->
let dir_target =
let lib_name = Lib_name.Local.to_string (snd name) in
let lib_name = snd name in
let inline_test_dir =
let inline_test_name = sprintf "%s.inline-tests" lib_name in
Path.Build.relative dir ("." ^ inline_test_name)
Path.Build.relative
dir
(Inline_tests_info.inline_test_dirname lib_name)
in
Path.Build.relative inline_test_dir ("run" ^ Js_of_ocaml.Ext.wasm_dir)
Path.Build.relative
inline_test_dir
(Inline_tests_info.inline_test_runner ^ Js_of_ocaml.Ext.wasm_dir)
in
Path.Build.Map.singleton dir_target loc)
>>= when_enabled ~dir ~enabled_if
Expand Down
19 changes: 10 additions & 9 deletions src/dune_rules/inline_tests.ml
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,13 @@ include Sub_system.Register_end_point (struct
in
let loc = lib.buildable.loc in
let lib_name = snd lib.name in
let inline_test_name =
sprintf "%s.inline-tests" (Lib_name.Local.to_string lib_name)
let inline_test_dir =
Path.Build.relative dir (Inline_tests_info.inline_test_dirname lib_name)
in
let inline_test_dir = Path.Build.relative dir ("." ^ inline_test_name) in
let name = "run" in
let obj_dir = Obj_dir.make_exe ~dir:inline_test_dir ~name in
let runner_name = Inline_tests_info.inline_test_runner in
let obj_dir = Obj_dir.make_exe ~dir:inline_test_dir ~name:"t" in
let main_module =
let name = Module_name.of_string name in
let name = Module_name.of_string "main" in
Module.generated ~kind:Impl ~src_dir:inline_test_dir [ name ]
in
let modules = Modules.With_vlib.singleton_exe main_module in
Expand Down Expand Up @@ -212,7 +211,7 @@ include Sub_system.Register_end_point (struct
in
Exe.build_and_link
cctx
~program:{ name; main_module_name = Module.name main_module; loc }
~program:{ name = runner_name; main_module_name = Module.name main_module; loc }
~linkages
~link_args
~promote:None
Expand Down Expand Up @@ -269,7 +268,7 @@ include Sub_system.Register_end_point (struct
| Native | Best | Byte -> None
| Jsoo _ -> Some Jsoo_rules.runner
in
let exe = Path.build (Path.Build.relative inline_test_dir (name ^ ext)) in
let exe = Path.build (Path.Build.relative inline_test_dir (runner_name ^ ext)) in
let open Action_builder.O in
let+ action =
match custom_runner with
Expand Down Expand Up @@ -301,7 +300,9 @@ include Sub_system.Register_end_point (struct
| Jsoo Wasm ->
Action_builder.path
(Path.build
(Path.Build.relative inline_test_dir (name ^ Js_of_ocaml.Ext.wasm_dir)))
(Path.Build.relative
inline_test_dir
(runner_name ^ Js_of_ocaml.Ext.wasm_dir)))
in
Action.chdir (Path.build dir) action
in
Expand Down
6 changes: 6 additions & 0 deletions src/dune_rules/inline_tests_info.ml
Original file line number Diff line number Diff line change
Expand Up @@ -183,3 +183,9 @@ module Tests = struct
purposes *)
let encode _t = assert false
end

let inline_test_dirname lib_name =
sprintf ".%s.inline-tests" (Lib_name.Local.to_string lib_name)
;;

let inline_test_runner = "inline-test-runner"
3 changes: 3 additions & 0 deletions src/dune_rules/inline_tests_info.mli
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,6 @@ module Tests : sig

include Sub_system_info.S with type t := t
end

val inline_test_dirname : Lib_name.Local.t -> string
val inline_test_runner : string
8 changes: 4 additions & 4 deletions test/blackbox-tests/test-cases/inline_tests/parallel.t/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ First, build silently to avoid some noise
See that `test1/runtest`, which uses `fake_backend_1, only runs one inline test runner

$ dune build --display short @test1/runtest 2>&1 | grep alias
run alias test1/runtest
inline-test-runner alias test1/runtest

See that `test2/runtest`, which uses `fake_backend_2`, runs one inline test runner per partition

$ dune build --display short @test2/runtest 2>&1 | grep alias
run alias test2/runtest
run alias test2/runtest
run alias test2/runtest
inline-test-runner alias test2/runtest
inline-test-runner alias test2/runtest
inline-test-runner alias test2/runtest

See that we indeed have 3 partitions

Expand Down
4 changes: 2 additions & 2 deletions test/blackbox-tests/test-cases/inline_tests/simple.t
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
File "dune", line 9, characters 1-40:
9 | (inline_tests (backend backend_simple)))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Fatal error: exception File ".foo_simple.inline-tests/run.ml-gen", line 1, characters 40-46: Assertion failed
Fatal error: exception File ".foo_simple.inline-tests/main.ml-gen", line 1, characters 40-46: Assertion failed
[1]

The expected behavior for the following three tests is to output nothing: the tests are disabled or ignored.
Expand All @@ -41,5 +41,5 @@ The expected behavior for the following three tests is to output nothing: the te
File "dune", line 9, characters 1-40:
9 | (inline_tests (backend backend_simple)))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Fatal error: exception File ".foo_simple.inline-tests/run.ml-gen", line 1, characters 40-46: Assertion failed
Fatal error: exception File ".foo_simple.inline-tests/main.ml-gen", line 1, characters 40-46: Assertion failed
[1]

0 comments on commit 52fd9bd

Please sign in to comment.