Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 18 additions & 9 deletions bin/runtest_common.ml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ open Import
module Test_kind = struct
type t =
| Runtest of Path.t
| Cram of Path.t * Source.Cram_test.t
| Cram of Path.t * Source.Cram_test.Name.t
| Test_executable of
{ dir : Path.t
; exe_name : string
Expand All @@ -14,8 +14,8 @@ module Test_kind = struct
}

let alias ~contexts = function
| Cram (dir, cram) ->
let name = Source.Cram_test.name cram |> Source.Cram_test.Name.to_alias in
| Cram (dir, name) ->
let name = Source.Cram_test.Name.to_alias name in
Alias.in_dir ~name ~recursive:false ~contexts dir
| Test_executable { dir; exe_name } ->
let name = Dune_engine.Alias.Name.of_string ("runtest-" ^ exe_name) in
Expand Down Expand Up @@ -110,8 +110,8 @@ let all_tests_of_dir ~sctx parent_dir =
classify_ml_test ~sctx ~dir:parent_dir ~ml_file >>| Result.is_ok)
>>| Filename.L.to_string
and+ dir_candidates =
let* parent_source_dir = Source_tree.find_dir parent_dir in
match parent_source_dir with
Source_tree.find_dir parent_dir
>>= function
| None -> Memo.return []
| Some parent_source_dir ->
let dirs = Source_tree.Dir.sub_dirs parent_source_dir in
Expand Down Expand Up @@ -141,11 +141,20 @@ let disambiguate_test_name ~sctx path =
| None -> Memo.return @@ Test_kind.Runtest (Path.source Path.Source.root)
| Some parent_dir ->
let open Memo.O in
let* cram_tests = cram_tests_of_dir parent_dir in
(match find_cram_test cram_tests path with
| Some test ->
Source_tree.find_dir parent_dir
>>= (function
| None -> Memo.return None
| Some source_dir ->
let+ cram_tests = Dune_rules.Cram_rules.cram_tests source_dir in
find_cram_test cram_tests path |> Option.map ~f:(fun test -> source_dir, test))
>>= (function
| Some (source_dir, test) ->
(* If we find the cram test, then we request that is run. *)
Memo.return (Test_kind.Cram (Path.source parent_dir, test))
let dune_version =
Source_tree.Dir.project source_dir |> Dune_project.dune_version
in
let name = Source.Cram_test.name test ~dune_version in
Memo.return (Test_kind.Cram (Path.source parent_dir, name))
| None ->
let filename = Path.Source.basename path in
classify_ml_test ~sctx ~dir:parent_dir ~ml_file:filename
Expand Down
2 changes: 2 additions & 0 deletions doc/changes/changed/16146.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Keep `.t` suffixes in cram test names, including aliases and `applies_to`,
starting with Dune language 3.25 (#16146, @rgrinberg)
15 changes: 9 additions & 6 deletions doc/reference/dune/cram.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,14 @@ Cram
will apply the options to all tests in all subdirectories (recursively).
This is useful to apply common options to an entire test suite.

The following will apply the stanza to all tests in this directory,
except for ``foo.t`` and ``bar.t``:
Starting with Dune 3.25, test names include the ``.t`` suffix. In earlier
versions, the suffix is omitted. The following will apply the stanza to
all tests in this directory except for ``foo.t`` and ``bar.t``:

.. code:: dune

(cram
(applies_to * \ foo bar)
(applies_to * \ foo.t bar.t)
(deps ../foo.exe))

.. seealso:: :doc:`/reference/predicate-language`
Expand All @@ -55,16 +56,18 @@ Cram
Control whether the tests are included in the ``runtest`` alias and other
aliases specified by the ``alias`` field. When ``enabled_if`` evaluates to
``false``, the test is excluded from these aliases but can still be run
explicitly via its own alias (e.g., ``dune build @foo`` for ``foo.t``).
explicitly via its own alias (e.g., ``dune build @foo.t`` for ``foo.t``
starting with Dune 3.25).

.. seealso:: :doc:`/reference/boolean-language`, :doc:`/concepts/variables`

.. describe:: (alias <name>)

Alias that can be used to run the test. In addition to the user alias,
every test ``foo.t`` is attached to the :doc:`/reference/aliases/runtest`
alias and gets its own ``@foo`` alias to make it convenient to run
individually.
alias and gets its own alias to make it convenient to run individually.
Starting with Dune 3.25, this alias is ``@foo.t``; in earlier versions it
is ``@foo``.

.. describe:: (locks <lock-names>)

Expand Down
4 changes: 2 additions & 2 deletions otherlibs/configurator/test/blackbox-tests/dune
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
(package dune-configurator)))

(cram
(applies_to pkg-config-quoting)
(applies_to pkg-config-quoting.t)
(deps %{bin:pkg-config}))

(cram
(enabled_if
(<> %{ocaml-config:system} win))
(applies_to configurator))
(applies_to configurator.t))
2 changes: 1 addition & 1 deletion otherlibs/dune-site/test/dune
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
; environment variable is set. Most CI systems set it.

(cram
(applies_to run_2_9 run)
(applies_to run_2_9.t run.t)
(enabled_if
(and
(= %{env:CI=false} false)
Expand Down
8 changes: 4 additions & 4 deletions src/dune_rules/cram/cram_rules.ml
Original file line number Diff line number Diff line change
Expand Up @@ -250,11 +250,10 @@ let collect_stanzas =
| Some dir -> collect_whole_subtree [ acc ] dir
;;

let spec_for_test ~stanzas test =
let spec_for_test ~stanzas ~dune_version test =
let name =
match test with
| Ok test -> Cram_test.name test
| Error (Missing_run_t test) -> Cram_test.name test
| Ok test | Error (Missing_run_t test) -> Cram_test.name test ~dune_version
in
let test_name_alias = Cram_test.Name.to_alias name in
let init = None, Spec.make_empty ~test_name_alias in
Expand Down Expand Up @@ -397,6 +396,7 @@ let spec_for_test ~stanzas test =
;;

let rules ~sctx ~dir tests project =
let dune_version = Dune_project.dune_version project in
let* stanzas = collect_stanzas ~dir
and* with_package_mask =
let+ mask = Dune_load.mask () >>| Only_packages.enumerate in
Expand Down Expand Up @@ -433,7 +433,7 @@ let rules ~sctx ~dir tests project =
else fun packages _f -> with_validate_packages packages ~f:Memo.return)
in
Memo.parallel_iter tests ~f:(fun test ->
let* spec = spec_for_test ~stanzas test in
let* spec = spec_for_test ~stanzas ~dune_version test in
with_package_mask spec.packages (fun () -> test_rule ~sctx ~dir spec test))
;;

Expand Down
11 changes: 5 additions & 6 deletions src/source/cram_test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,11 @@ let path = function
| Dir d -> d.dir
;;

let name t =
path t
|> Path.Source.basename
|> Filename.to_string
|> String.drop_suffix ~suffix
|> Option.value_exn
let name t ~dune_version =
let name = path t |> Path.Source.basename |> Filename.to_string in
if dune_version >= (3, 25)
then name
else String.drop_suffix ~suffix name |> Option.value_exn
;;

let script t =
Expand Down
8 changes: 4 additions & 4 deletions src/source/cram_test.mli
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ val is_cram_suffix : Filename.t -> bool
(** The "run.t" filename for directory cram tests. *)
val fname_in_dir_test : Filename.t

(** The [name] of a cram test. If this is a file test, then it will be the file
name without the cram suffix. If this is a directory test, then it will be
the directory name without the cram suffix. *)
val name : t -> Name.t
(** The [name] of a cram test. Starting from dune language 3.25 this is the
full basename, including the cram suffix. Before 3.25 the suffix is
dropped. *)
val name : t -> dune_version:Dune_lang.Syntax.Version.t -> Name.t

(** The [path] associated to a cram test. If this is a file test, then it will
be the file. If this is a directory test, then it will be the directory. *)
Expand Down
13 changes: 10 additions & 3 deletions test/blackbox-tests/test-cases/action-runner/dune
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
(cram
(alias runtest-action-runner)
(applies_to basic cancel-disconnect disconnect failure pool runtest trace))
(applies_to
basic.t
cancel-disconnect.t
disconnect.t
failure.t
pool.t
runtest.t
trace.t))

(cram
(alias runtest-action-runner)
(applies_to fd-leak)
(applies_to fd-leak.t)
(enabled_if
(= %{system} linux)))

Expand All @@ -14,4 +21,4 @@
(cram
(enabled_if false)
(alias runtest-action-runner)
(applies_to stop-on-first-error watch-stop-on-first-error))
(applies_to stop-on-first-error.t watch-stop-on-first-error.t))
6 changes: 3 additions & 3 deletions test/blackbox-tests/test-cases/actions/dune
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
(cram
(applies_to stray-process)
(applies_to stray-process.t)
(enabled_if
(<> %{system} macosx)))

(cram
(applies_to subreaper)
(applies_to subreaper.t)
(deps
(source_tree bin))
(enabled_if
(= %{system} linux)))

(cram
(applies_to concurrent)
(applies_to concurrent.t)
(enabled_if false))
2 changes: 1 addition & 1 deletion test/blackbox-tests/test-cases/bin-pform/dune
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(cram
(applies_to windows-install-names)
(applies_to windows-install-names.t)
(enabled_if
(= %{os_type} Win32))
(alias runtest-windows))
2 changes: 1 addition & 1 deletion test/blackbox-tests/test-cases/build-info/dune
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(cram
(applies_to link-time-transitive-deps dune-build-info-subdir)
(applies_to link-time-transitive-deps.t dune-build-info-subdir.t)
(deps
(package dune-build-info)))
8 changes: 4 additions & 4 deletions test/blackbox-tests/test-cases/completion/dune
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
(cram
(applies_to bash)
(applies_to bash.t)
(enabled_if
(and
(<> %{system} macosx)
%{bin-available:bash}))
(deps %{bin:bash}))

(cram
(applies_to fish)
(applies_to fish.t)
(enabled_if %{bin-available:fish})
(deps %{bin:fish}))

(cram
(applies_to zsh)
(applies_to zsh.t)
(enabled_if %{bin-available:zsh})
(deps %{bin:zsh}))

(cram
(applies_to powershell)
(applies_to powershell.t)
(enabled_if %{bin-available:pwsh})
(alias runtest-windows)
(deps %{bin:pwsh}))
29 changes: 0 additions & 29 deletions test/blackbox-tests/test-cases/cram/cram-applies-to-no-match.t

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
A cram stanza uses different test names before and after dune language 3.25:

$ make_dune_project 3.24

Before 3.25, [applies_to] matches the cram test name without the [.t] suffix:

$ cat >dune <<EOF
> (cram
> (applies_to foobar.t)
> (alias file-applies-match))
> (cram
> (applies_to dirtest.t)
> (alias dir-applies-match))
> EOF

$ cat >foobar.t <<EOF
> $ echo foo
> EOF

$ mkdir dirtest.t
$ cat >dirtest.t/run.t <<EOF
> $ echo dir
> EOF

$ dune show aliases > aliases 2>&1
$ grep '^file-applies-match$' aliases
[1]
$ grep '^dir-applies-match$' aliases
[1]

From 3.25 onward, the full cram test name is used:

$ make_dune_project 3.25

$ dune show aliases > aliases 2>&1
$ grep '^file-applies-match$' aliases
file-applies-match
$ grep '^dir-applies-match$' aliases
dir-applies-match
14 changes: 7 additions & 7 deletions test/blackbox-tests/test-cases/cram/dune
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
(cram
(applies_to subprocess)
(applies_to subprocess.t)
(enabled_if
(= %{system} linux))
(deps %{bin:ps}))

(cram
(applies_to error subprocess)
(applies_to error.t subprocess.t)
(enabled_if false))

;; mac has a different sh error message

(cram
(applies_to error)
(applies_to error.t)
(enabled_if
(<> "macosx" %{ocaml-config:system})))

(cram
(applies_to hg-access)
(applies_to hg-access.t)
(enabled_if %{bin-available:hg}))

(cram
(applies_to junction-cleanup)
(applies_to junction-cleanup.t)
(enabled_if
(= %{os_type} Win32))
(alias runtest-windows))

(cram
(applies_to windows-path-rewriting)
(applies_to windows-path-rewriting.t)
(enabled_if
(= %{os_type} Win32))
(alias runtest-windows))

(cram
(applies_to workspace-root-change)
(applies_to workspace-root-change.t)
(deps %{bin:cksum} %{bin:cut}))
Loading
Loading