Skip to content

Commit

Permalink
_
Browse files Browse the repository at this point in the history
Signed-off-by: Rudi Grinberg <me@rgrinberg.com>
  • Loading branch information
rgrinberg committed Oct 31, 2024
1 parent acaa7f6 commit a84f460
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 11 deletions.
13 changes: 6 additions & 7 deletions bin/runtest.ml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ let disambiguate_test_name path =
>>= (function
| Some test ->
(* If we find the cram test, then we request that is run. *)
Memo.return (`Test (Dune_rules.Cram_test.name test))
Memo.return (`Test (parent_dir, Dune_rules.Cram_test.name test))
| None ->
(* If we don't find it, then we assume the user intended a directory for
@runtest to be used. *)
Expand Down Expand Up @@ -92,10 +92,9 @@ let runtest_term =
let common, config = Common.init builder in
let request (setup : Import.Main.build_system) =
List.map dirs ~f:(fun dir ->
let dir = Path.(relative root) (Common.prefix_target common dir) in
let open Action_builder.O in
let* alias_kind =
(* We always interpret the arguments as paths *)
let dir = Path.of_string dir in
match Path.as_in_source_tree dir with
| Some path -> Action_builder.of_memo (disambiguate_test_name path)
| None ->
Expand All @@ -106,12 +105,12 @@ let runtest_term =
Alias.request
@@
match alias_kind with
| `Test alias_name ->
Alias.of_string
(Common.root common)
| `Test (dir, alias_name) ->
Alias.in_dir
~name:(Dune_engine.Alias.Name.of_string alias_name)
~recursive:false
~contexts:setup.contexts
alias_name
(Path.source dir)
| `Runtest dir ->
Alias.in_dir
~name:Dune_rules.Alias.runtest
Expand Down
31 changes: 27 additions & 4 deletions test/blackbox-tests/test-cases/runtest-cmd.t
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,31 @@ Here we test the features of the `dune runtest` command.
> "Goodbye, world!"
> EOF

Passing no arguments to `dune runtest` should be equivalent to `dune build
@runtest`.

This should work:

$ dune test tests/myothertest.t
File "tests/myothertest.t/run.t", line 1, characters 0-0:
Error: Files _build/default/tests/myothertest.t/run.t and
_build/default/tests/myothertest.t/run.t.corrected differ.
[1]

This should not work

$ dune test myotherttest.t
Error: "myotherttest.t" was not found.
[1]

Should this work? Debatable but giving a hint if it doesn't would be good.

$ dune test tests/myothertest.t/run.t
File "tests/myothertest.t/run.t", line 1, characters 0-0:
Error: Files _build/default/tests/myothertest.t/run.t and
_build/default/tests/myothertest.t/run.t.corrected differ.
[1]

Passing no arguments to $ dune runtest should be equivalent to $ dune build
@runtest.

$ dune test 2>&1 | grep "^File"
File "mytest.t", line 1, characters 0-0:
Expand All @@ -31,7 +54,7 @@ Passing the name of a test should only run that test.
$ dune test mytest.t 2>&1 | grep "^File"
File "mytest.t", line 1, characters 0-0:
$ dune test tests/myothertest.t 2>&1 | grep "^File"
[1]
File "tests/myothertest.t/run.t", line 1, characters 0-0:

Passing a directory should run all the tests in that directory (recursively).

Expand Down Expand Up @@ -60,7 +83,7 @@ messages are informative enough.

- Giving a path outside the workspace gives an informative error:
$ dune test ..
Error: path outside the workspace: .. from .
Error: @@ on the command line must be followed by a relative path
[1]
- Giving a nonexistent path gives an informative error:
$ dune test nonexistent
Expand Down

0 comments on commit a84f460

Please sign in to comment.