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) diff --git a/src/dune_rules/test_rules.ml b/src/dune_rules/test_rules.ml index e27d34c934d..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 } @@ -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 @@ -90,12 +91,12 @@ 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 = { 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/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..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,4 +2,3 @@ tests stanza with jsoo $ dune build @default @runtest-js a: ok - b: ok 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/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..10bcbf13621 --- /dev/null +++ b/test/blackbox-tests/test-cases/tests-stanza/modes.t/run.t @@ -0,0 +1 @@ + $ dune runtest