Skip to content

Commit ff33ed9

Browse files
committed
refactor: split finding cram tests and collecting cram tests
Signed-off-by: Ali Caglayan <[email protected]>
1 parent 51dd253 commit ff33ed9

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

bin/runtest_common.ml

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
11
open Import
22

3-
let find_cram_test path ~parent_dir =
3+
let cram_tests_of_dir parent_dir =
44
let open Memo.O in
55
Source_tree.find_dir parent_dir
66
>>= function
7-
| None -> Memo.return None
8-
| Some dir ->
9-
Dune_rules.Cram_rules.cram_tests dir
10-
>>| List.find_map ~f:(function
11-
| Ok cram_test when Path.Source.equal path (Source.Cram_test.path cram_test) ->
12-
Some cram_test
13-
(* We raise any error we encounter when looking for our test specifically. *)
14-
| Error (Dune_rules.Cram_rules.Missing_run_t cram_test)
15-
when Path.Source.equal path (Source.Cram_test.path cram_test) ->
16-
Dune_rules.Cram_rules.missing_run_t cram_test
17-
(* Any errors or successes unrelated to our test are discarded. *)
18-
| Error (Dune_rules.Cram_rules.Missing_run_t _) | Ok _ -> None)
7+
| None -> Memo.return []
8+
| Some dir -> Dune_rules.Cram_rules.cram_tests dir
9+
;;
10+
11+
let find_cram_test cram_tests path =
12+
List.find_map cram_tests ~f:(function
13+
| Ok cram_test when Path.Source.equal path (Source.Cram_test.path cram_test) ->
14+
Some cram_test
15+
(* We raise any error we encounter when looking for our test specifically. *)
16+
| Error (Dune_rules.Cram_rules.Missing_run_t cram_test)
17+
when Path.Source.equal path (Source.Cram_test.path cram_test) ->
18+
Dune_rules.Cram_rules.missing_run_t cram_test
19+
(* Any errors or successes unrelated to our test are discarded. *)
20+
| Error (Dune_rules.Cram_rules.Missing_run_t _) | Ok _ -> None)
1921
;;
2022

2123
let explain_unsuccessful_search path ~parent_dir =
@@ -57,8 +59,8 @@ let disambiguate_test_name path =
5759
| None -> Memo.return @@ `Runtest (Path.source Path.Source.root)
5860
| Some parent_dir ->
5961
let open Memo.O in
60-
find_cram_test path ~parent_dir
61-
>>= (function
62+
let* cram_tests = cram_tests_of_dir parent_dir in
63+
(match find_cram_test cram_tests path with
6264
| Some test ->
6365
(* If we find the cram test, then we request that is run. *)
6466
Memo.return (`Cram (parent_dir, test))

0 commit comments

Comments
 (0)