Skip to content

Commit 75aeca6

Browse files
committed
refactor: introduce Test_kind.t for runtest
Signed-off-by: Ali Caglayan <[email protected]>
1 parent 735c70d commit 75aeca6

File tree

2 files changed

+25
-23
lines changed

2 files changed

+25
-23
lines changed

bin/runtest_common.ml

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
open Import
22

3+
module Test_kind = struct
4+
type t =
5+
| Runtest of Path.t
6+
| Cram of Path.t * Source.Cram_test.t
7+
8+
let alias ~contexts = function
9+
| Cram (dir, cram) ->
10+
let name = Dune_engine.Alias.Name.of_string (Source.Cram_test.name cram) in
11+
Alias.in_dir ~name ~recursive:false ~contexts dir
12+
| Runtest dir ->
13+
Alias.in_dir ~name:Dune_rules.Alias.runtest ~recursive:true ~contexts dir
14+
;;
15+
end
16+
317
let cram_tests_of_dir parent_dir =
418
let open Memo.O in
519
Source_tree.find_dir parent_dir
@@ -57,40 +71,36 @@ let explain_unsuccessful_search path ~parent_dir =
5771
run tests in. *)
5872
let disambiguate_test_name path =
5973
match Path.Source.parent path with
60-
| None -> Memo.return @@ `Runtest (Path.source Path.Source.root)
74+
| None -> Memo.return @@ Test_kind.Runtest (Path.source Path.Source.root)
6175
| Some parent_dir ->
6276
let open Memo.O in
6377
let* cram_tests = cram_tests_of_dir parent_dir in
6478
(match find_cram_test cram_tests path with
6579
| Some test ->
6680
(* If we find the cram test, then we request that is run. *)
67-
Memo.return (`Cram (parent_dir, test))
81+
Memo.return (Test_kind.Cram (Path.source parent_dir, test))
6882
| None ->
6983
(* If we don't find it, then we assume the user intended a directory for
7084
@runtest to be used. *)
7185
Source_tree.find_dir path
7286
>>= (function
7387
(* We need to make sure that this directory or file exists. *)
74-
| Some _ -> Memo.return (`Runtest (Path.source path))
88+
| Some _ -> Memo.return (Test_kind.Runtest (Path.source path))
7589
| None -> explain_unsuccessful_search path ~parent_dir))
7690
;;
7791

7892
let make_request ~contexts ~to_cwd ~test_paths =
7993
List.map test_paths ~f:(fun dir ->
8094
let dir = Path.of_string dir |> Path.Expert.try_localize_external in
81-
let open Action_builder.O in
82-
let* contexts, alias_kind =
95+
let contexts, src_dir =
8396
match (Util.check_path contexts dir : Util.checked) with
84-
| In_build_dir (context, dir) ->
85-
let+ res = Action_builder.of_memo (disambiguate_test_name dir) in
86-
[ context ], res
97+
| In_build_dir (context, dir) -> [ context ], dir
8798
| In_source_dir dir ->
8899
(* We need to adjust the path here to make up for the current working directory. *)
89100
let dir =
90101
Path.Source.L.relative Path.Source.root (to_cwd @ Path.Source.explode dir)
91102
in
92-
let+ res = Action_builder.of_memo (disambiguate_test_name dir) in
93-
contexts, res
103+
contexts, dir
94104
| In_private_context _ | In_install_dir _ ->
95105
User_error.raise
96106
[ Pp.textf "This path is internal to dune: %s" (Path.to_string_maybe_quoted dir)
@@ -102,17 +112,9 @@ let make_request ~contexts ~to_cwd ~test_paths =
102112
(Path.to_string_maybe_quoted dir)
103113
]
104114
in
105-
Alias.request
106-
@@
107-
match alias_kind with
108-
| `Cram (dir, cram) ->
109-
let alias_name = Source.Cram_test.name cram in
110-
Alias.in_dir
111-
~name:(Dune_engine.Alias.Name.of_string alias_name)
112-
~recursive:false
113-
~contexts
114-
(Path.source dir)
115-
| `Runtest dir ->
116-
Alias.in_dir ~name:Dune_rules.Alias.runtest ~recursive:true ~contexts dir)
115+
let open Action_builder.O in
116+
Action_builder.of_memo (disambiguate_test_name src_dir)
117+
>>| Test_kind.alias ~contexts
118+
>>= Alias.request)
117119
|> Action_builder.all_unit
118120
;;

boot/libs.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
open Types
2-
let external_libraries = [ "pp"; "unix"; "csexp"; "threads" ]
2+
let external_libraries = [ "unix"; "threads" ]
33

44
let local_libraries =
55
[ { path = "otherlibs/top-closure"

0 commit comments

Comments
 (0)