From 52fd9bda99d657baba9e5bc8926a9f4fe7c09a10 Mon Sep 17 00:00:00 2001 From: Hugo Heuzard Date: Tue, 21 Jan 2025 10:23:32 +0100 Subject: [PATCH] Alternative names Signed-off-by: Hugo Heuzard --- src/dune_rules/dir_status.ml | 11 +++++++---- src/dune_rules/inline_tests.ml | 19 ++++++++++--------- src/dune_rules/inline_tests_info.ml | 6 ++++++ src/dune_rules/inline_tests_info.mli | 3 +++ .../test-cases/inline_tests/parallel.t/run.t | 8 ++++---- .../test-cases/inline_tests/simple.t | 4 ++-- 6 files changed, 32 insertions(+), 19 deletions(-) diff --git a/src/dune_rules/dir_status.ml b/src/dune_rules/dir_status.ml index b7b0213c2cc..e627bc02ab6 100644 --- a/src/dune_rules/dir_status.ml +++ b/src/dune_rules/dir_status.ml @@ -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 diff --git a/src/dune_rules/inline_tests.ml b/src/dune_rules/inline_tests.ml index aa38a315dc6..947a35d4d23 100644 --- a/src/dune_rules/inline_tests.ml +++ b/src/dune_rules/inline_tests.ml @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/src/dune_rules/inline_tests_info.ml b/src/dune_rules/inline_tests_info.ml index 47e247aa7ba..3ba8e4bf738 100644 --- a/src/dune_rules/inline_tests_info.ml +++ b/src/dune_rules/inline_tests_info.ml @@ -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" diff --git a/src/dune_rules/inline_tests_info.mli b/src/dune_rules/inline_tests_info.mli index 2135df4aa88..b7747aac756 100644 --- a/src/dune_rules/inline_tests_info.mli +++ b/src/dune_rules/inline_tests_info.mli @@ -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 diff --git a/test/blackbox-tests/test-cases/inline_tests/parallel.t/run.t b/test/blackbox-tests/test-cases/inline_tests/parallel.t/run.t index dd82ca0d6a9..1db1f9b6326 100644 --- a/test/blackbox-tests/test-cases/inline_tests/parallel.t/run.t +++ b/test/blackbox-tests/test-cases/inline_tests/parallel.t/run.t @@ -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 diff --git a/test/blackbox-tests/test-cases/inline_tests/simple.t b/test/blackbox-tests/test-cases/inline_tests/simple.t index df15d03a1cb..a9ae3faa78a 100644 --- a/test/blackbox-tests/test-cases/inline_tests/simple.t +++ b/test/blackbox-tests/test-cases/inline_tests/simple.t @@ -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. @@ -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]