Skip to content

Commit f93f532

Browse files
committed
feature: tests stanzas produce aliases
Signed-off-by: Ali Caglayan <alizter@gmail.com>
1 parent 6d1e608 commit f93f532

3 files changed

Lines changed: 37 additions & 11 deletions

File tree

src/dune_rules/test_rules.ml

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
open Import
22
open Memo.O
33

4-
let alias mode ~dir =
5-
match mode with
6-
| `js mode -> Jsoo_rules.js_of_ocaml_runtest_alias ~dir ~mode
7-
| `exe | `bc -> Memo.return Alias0.runtest
4+
let runtest_alias mode ~dir =
5+
(match mode with
6+
| `js mode -> Jsoo_rules.js_of_ocaml_runtest_alias ~dir ~mode
7+
| `exe | `bc -> Memo.return Alias0.runtest)
8+
>>| Alias.make ~dir
89
;;
910

1011
let test_kind dir_contents (loc, name, ext) =
@@ -68,8 +69,7 @@ let rules (t : Tests.t) ~sctx ~dir ~scope ~expander ~dir_contents =
6869
| false ->
6970
let loc = Nonempty_list.hd t.exes.names |> fst in
7071
Memo.parallel_iter runtest_modes ~f:(fun mode ->
71-
let* alias_name = alias mode ~dir in
72-
let alias = Alias.make alias_name ~dir in
72+
let* alias = runtest_alias mode ~dir in
7373
Simple_rules.Alias_rules.add_empty sctx ~loc ~alias)
7474
| true ->
7575
Nonempty_list.to_list t.exes.names
@@ -97,7 +97,7 @@ let rules (t : Tests.t) ~sctx ~dir ~scope ~expander ~dir_contents =
9797
in
9898
Pform.Map.singleton test_pform [ Value.Path test_exe_path ]
9999
in
100-
let* runtest_alias = alias runtest_mode ~dir in
100+
let* runtest_alias = runtest_alias runtest_mode ~dir in
101101
let deps =
102102
(* is this useless? we are going to infer the dependency anyway *)
103103
match custom_runner with
@@ -114,9 +114,10 @@ let rules (t : Tests.t) ~sctx ~dir ~scope ~expander ~dir_contents =
114114
| `js JS | `exe | `bc -> t.deps)
115115
in
116116
let add_alias ~loc ~action =
117+
let alias = Alias.make ~dir (Alias.Name.of_string s) in
117118
(* CR rgrinberg: why are we going through the stanza api? *)
118-
let alias =
119-
{ Alias_conf.name = runtest_alias
119+
let alias_conf =
120+
{ Alias_conf.name = Alias.name alias
120121
; locks = t.locks
121122
; package = t.package
122123
; deps
@@ -125,7 +126,10 @@ let rules (t : Tests.t) ~sctx ~dir ~scope ~expander ~dir_contents =
125126
; loc
126127
}
127128
in
128-
Simple_rules.alias sctx ~extra_bindings ~dir ~expander alias
129+
Rules.Produce.Alias.add_deps
130+
runtest_alias
131+
(Action_builder.dep (Dep.alias alias))
132+
>>> Simple_rules.alias sctx ~extra_bindings ~dir ~expander alias_conf
129133
in
130134
match test_kind dir_contents (loc, s, ext) with
131135
| `Regular -> add_alias ~loc ~action:run_action
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
Tests stanzas produce aliases with the executable names
2+
3+
$ cat > dune-project << EOF
4+
> (lang dune 3.17)
5+
> EOF
6+
7+
$ cat > dune << EOF
8+
> (tests
9+
> (names a b))
10+
> EOF
11+
12+
$ cat > a.ml << EOF
13+
> let () = print_endline "a"
14+
> EOF
15+
16+
$ cat > b.ml << EOF
17+
> let () = print_endline "b"
18+
> EOF
19+
20+
$ dune build @a @b
21+
a
22+
b

test/blackbox-tests/test-cases/test-build-if/feature.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ We test the various combinations:
2626
> else
2727
> echo ' build was done: NO'
2828
> fi
29-
> if echo $output|grep -q "alias runtest" ; then
29+
> if echo $output|grep -q "alias t" ; then
3030
> echo ' test did run: YES'
3131
> else
3232
> echo ' test did run: NO'

0 commit comments

Comments
 (0)