From e1ad20ba29d486b98524ced2177726d7a1ade395 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Vouillon?= Date: Wed, 26 Jun 2024 14:07:19 +0200 Subject: [PATCH 1/5] Expect test: add failing test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Vouillon --- .../test-cases/jsoo/tests.t/b.expected | 1 + .../test-cases/jsoo/tests.t/run.t | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 test/blackbox-tests/test-cases/jsoo/tests.t/b.expected diff --git a/test/blackbox-tests/test-cases/jsoo/tests.t/b.expected b/test/blackbox-tests/test-cases/jsoo/tests.t/b.expected new file mode 100644 index 00000000000..3aca7c21f74 --- /dev/null +++ b/test/blackbox-tests/test-cases/jsoo/tests.t/b.expected @@ -0,0 +1 @@ +b: ok diff --git a/test/blackbox-tests/test-cases/jsoo/tests.t/run.t b/test/blackbox-tests/test-cases/jsoo/tests.t/run.t index 31412302c01..74fa4288a01 100644 --- a/test/blackbox-tests/test-cases/jsoo/tests.t/run.t +++ b/test/blackbox-tests/test-cases/jsoo/tests.t/run.t @@ -2,4 +2,21 @@ tests stanza with jsoo $ dune build @default @runtest-js a: ok - b: ok + File "dune", line 2, characters 11-12: + 2 | (names a b) + ^ + node:internal/modules/cjs/loader:1146 + throw err; + ^ + + Error: Cannot find module '$TESTCASE_ROOT/_build/default/b.bc.js' + at Module._resolveFilename (node:internal/modules/cjs/loader:1143:15) + at Module._load (node:internal/modules/cjs/loader:984:27) + at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:142:12) + at node:internal/main/run_main_module:28:49 { + code: 'MODULE_NOT_FOUND', + requireStack: [] + } + + Node.js v22.0.0-v8-canary20231204cf8ac0f493 + [1] From aed3e563cf7a93572e081ed9003ad098a45edcb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Vouillon?= Date: Wed, 26 Jun 2024 13:58:27 +0200 Subject: [PATCH 2/5] Fix expect test dependencies MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When there is a custom runner, the rule that executes the test should have a dependency on the executable. Signed-off-by: Jérôme Vouillon --- src/dune_rules/test_rules.ml | 17 +++++++++-------- .../test-cases/jsoo/tests.t/run.t | 18 ------------------ 2 files changed, 9 insertions(+), 26 deletions(-) diff --git a/src/dune_rules/test_rules.ml b/src/dune_rules/test_rules.ml index e27d34c934d..d63ea454be4 100644 --- a/src/dune_rules/test_rules.ml +++ b/src/dune_rules/test_rules.ml @@ -70,19 +70,20 @@ let rules (t : Tests.t) ~sctx ~dir ~scope ~expander ~dir_contents = | `js -> Jsoo_rules.js_of_ocaml_runtest_alias ~dir | `exe | `bc -> Memo.return Alias0.runtest in + let deps = + match custom_runner with + | Some _ -> + Bindings.Unnamed (Dep_conf.File (String_with_vars.make_text loc test_exe)) + :: t.deps + | None -> t.deps + in let add_alias ~loc ~action ~locks = (* CR-rgrinberg: why are we going through the stanza api? *) let alias = { Alias_conf.name = runtest_alias ; locks ; package = t.package - ; deps = - (match custom_runner with - | Some _ -> - Bindings.Unnamed - (Dep_conf.File (String_with_vars.make_text loc test_exe)) - :: t.deps - | None -> t.deps) + ; deps ; action = Some (loc, action) ; enabled_if = t.enabled_if ; loc @@ -95,7 +96,7 @@ let rules (t : Tests.t) ~sctx ~dir ~scope ~expander ~dir_contents = | `Expect diff -> let rule = { Rule_conf.targets = Infer - ; deps = t.deps + ; deps ; action = ( loc , Action_unexpanded.Redirect_out (Stdout, diff.file2, Normal, run_action) diff --git a/test/blackbox-tests/test-cases/jsoo/tests.t/run.t b/test/blackbox-tests/test-cases/jsoo/tests.t/run.t index 74fa4288a01..1debd3da900 100644 --- a/test/blackbox-tests/test-cases/jsoo/tests.t/run.t +++ b/test/blackbox-tests/test-cases/jsoo/tests.t/run.t @@ -2,21 +2,3 @@ tests stanza with jsoo $ dune build @default @runtest-js a: ok - File "dune", line 2, characters 11-12: - 2 | (names a b) - ^ - node:internal/modules/cjs/loader:1146 - throw err; - ^ - - Error: Cannot find module '$TESTCASE_ROOT/_build/default/b.bc.js' - at Module._resolveFilename (node:internal/modules/cjs/loader:1143:15) - at Module._load (node:internal/modules/cjs/loader:984:27) - at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:142:12) - at node:internal/main/run_main_module:28:49 { - code: 'MODULE_NOT_FOUND', - requireStack: [] - } - - Node.js v22.0.0-v8-canary20231204cf8ac0f493 - [1] From ca8f88147fafcd6ab58ca244a9eb5a83c6a4ae55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Vouillon?= Date: Wed, 26 Jun 2024 15:36:32 +0200 Subject: [PATCH 3/5] Add expect test with multiple modes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Vouillon --- test/blackbox-tests/test-cases/tests-stanza/modes.t/dune | 1 + .../test-cases/tests-stanza/modes.t/dune-project | 1 + .../test-cases/tests-stanza/modes.t/modes.expected | 1 + test/blackbox-tests/test-cases/tests-stanza/modes.t/modes.ml | 1 + test/blackbox-tests/test-cases/tests-stanza/modes.t/run.t | 5 +++++ 5 files changed, 9 insertions(+) create mode 100644 test/blackbox-tests/test-cases/tests-stanza/modes.t/dune create mode 100644 test/blackbox-tests/test-cases/tests-stanza/modes.t/dune-project create mode 100644 test/blackbox-tests/test-cases/tests-stanza/modes.t/modes.expected create mode 100644 test/blackbox-tests/test-cases/tests-stanza/modes.t/modes.ml create mode 100644 test/blackbox-tests/test-cases/tests-stanza/modes.t/run.t diff --git a/test/blackbox-tests/test-cases/tests-stanza/modes.t/dune b/test/blackbox-tests/test-cases/tests-stanza/modes.t/dune new file mode 100644 index 00000000000..9137703f0ac --- /dev/null +++ b/test/blackbox-tests/test-cases/tests-stanza/modes.t/dune @@ -0,0 +1 @@ +(test (name modes) (modes byte native)) diff --git a/test/blackbox-tests/test-cases/tests-stanza/modes.t/dune-project b/test/blackbox-tests/test-cases/tests-stanza/modes.t/dune-project new file mode 100644 index 00000000000..37f995d6492 --- /dev/null +++ b/test/blackbox-tests/test-cases/tests-stanza/modes.t/dune-project @@ -0,0 +1 @@ +(lang dune 3.0) diff --git a/test/blackbox-tests/test-cases/tests-stanza/modes.t/modes.expected b/test/blackbox-tests/test-cases/tests-stanza/modes.t/modes.expected new file mode 100644 index 00000000000..afba1fb71ea --- /dev/null +++ b/test/blackbox-tests/test-cases/tests-stanza/modes.t/modes.expected @@ -0,0 +1 @@ +testing multiple modes diff --git a/test/blackbox-tests/test-cases/tests-stanza/modes.t/modes.ml b/test/blackbox-tests/test-cases/tests-stanza/modes.t/modes.ml new file mode 100644 index 00000000000..9c7d02e4c69 --- /dev/null +++ b/test/blackbox-tests/test-cases/tests-stanza/modes.t/modes.ml @@ -0,0 +1 @@ +print_endline "testing multiple modes" diff --git a/test/blackbox-tests/test-cases/tests-stanza/modes.t/run.t b/test/blackbox-tests/test-cases/tests-stanza/modes.t/run.t new file mode 100644 index 00000000000..f9e1830df2e --- /dev/null +++ b/test/blackbox-tests/test-cases/tests-stanza/modes.t/run.t @@ -0,0 +1,5 @@ + $ dune runtest + Error: Multiple rules generated for _build/default/modes.output: + - dune:1 + - dune:1 + [1] From db1c40b70c32ff848b0871c3ffb6c97210e57764 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Vouillon?= Date: Wed, 26 Jun 2024 15:42:49 +0200 Subject: [PATCH 4/5] Expect tests: support multiple modes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Each mode must correspond to a different output file. Signed-off-by: Jérôme Vouillon --- src/dune_rules/test_rules.ml | 6 +++--- test/blackbox-tests/test-cases/tests-stanza-expected-deps.t | 2 +- .../test-cases/tests-stanza/generated.t/run.t | 2 +- test/blackbox-tests/test-cases/tests-stanza/modes.t/run.t | 4 ---- 4 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/dune_rules/test_rules.ml b/src/dune_rules/test_rules.ml index d63ea454be4..53ea8b62a51 100644 --- a/src/dune_rules/test_rules.ml +++ b/src/dune_rules/test_rules.ml @@ -1,14 +1,14 @@ open Import let rules (t : Tests.t) ~sctx ~dir ~scope ~expander ~dir_contents = - let test_kind (loc, name) = + let test_kind (loc, name, ext) = let files = Dir_contents.text_files dir_contents in let expected_basename = name ^ ".expected" in if Filename.Set.mem files expected_basename then `Expect { Diff.file1 = String_with_vars.make_text loc expected_basename - ; file2 = String_with_vars.make_text loc (name ^ ".output") + ; file2 = String_with_vars.make_text loc (name ^ ext ^ ".output") ; optional = false ; mode = Text } @@ -91,7 +91,7 @@ let rules (t : Tests.t) ~sctx ~dir ~scope ~expander ~dir_contents = in Simple_rules.alias sctx ~extra_bindings ~dir ~expander alias in - match test_kind (loc, s) with + match test_kind (loc, s, ext) with | `Regular -> add_alias ~loc ~action:run_action ~locks:[] | `Expect diff -> let rule = diff --git a/test/blackbox-tests/test-cases/tests-stanza-expected-deps.t b/test/blackbox-tests/test-cases/tests-stanza-expected-deps.t index 1fe61a4f8eb..5d8897a7f8b 100644 --- a/test/blackbox-tests/test-cases/tests-stanza-expected-deps.t +++ b/test/blackbox-tests/test-cases/tests-stanza-expected-deps.t @@ -23,4 +23,4 @@ This is visible when trying to build the `@all` alias. See #5950. $ cp data.txt t.expected - $ dune build t.output + $ dune build t.exe.output diff --git a/test/blackbox-tests/test-cases/tests-stanza/generated.t/run.t b/test/blackbox-tests/test-cases/tests-stanza/generated.t/run.t index f041a30b27a..58dbb66f070 100644 --- a/test/blackbox-tests/test-cases/tests-stanza/generated.t/run.t +++ b/test/blackbox-tests/test-cases/tests-stanza/generated.t/run.t @@ -1,5 +1,5 @@ $ dune runtest File "generated.expected", line 1, characters 0-0: Error: Files _build/default/generated.expected and - _build/default/generated.output differ. + _build/default/generated.exe.output differ. [1] diff --git a/test/blackbox-tests/test-cases/tests-stanza/modes.t/run.t b/test/blackbox-tests/test-cases/tests-stanza/modes.t/run.t index f9e1830df2e..10bcbf13621 100644 --- a/test/blackbox-tests/test-cases/tests-stanza/modes.t/run.t +++ b/test/blackbox-tests/test-cases/tests-stanza/modes.t/run.t @@ -1,5 +1 @@ $ dune runtest - Error: Multiple rules generated for _build/default/modes.output: - - dune:1 - - dune:1 - [1] From 0850c49518f13c7731d30e03ff5ac0e2fff45b01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Vouillon?= Date: Wed, 26 Jun 2024 15:51:18 +0200 Subject: [PATCH 5/5] Changes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Vouillon --- doc/changes/10671.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 doc/changes/10671.md diff --git a/doc/changes/10671.md b/doc/changes/10671.md new file mode 100644 index 00000000000..3887e4031bd --- /dev/null +++ b/doc/changes/10671.md @@ -0,0 +1 @@ +- Expect test fixes: support multiple modes and fix dependencies when there is a custom runner (#10671, @vouillon)