Skip to content

Commit ed9167b

Browse files
committed
Test event listener for nested and unlabeled tests
1 parent a3a9220 commit ed9167b

File tree

1 file changed

+43
-16
lines changed

1 file changed

+43
-16
lines changed

workspace/test.ml

Lines changed: 43 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,51 @@ open OUnit
33
let _esc_lf s =
44
s |> Str.global_replace (Str.regexp_string "\n") "<:LF:>";;
55

6-
(* TODO Fix missing `<COMPLETEDIN::>` *)
6+
let cw_print_success = function
7+
| _ -> print_endline ("\n<PASSED::>Test passed")
8+
9+
let cw_print_failure = function
10+
| err -> print_endline ("\n<FAILED::>" ^ (_esc_lf err))
11+
12+
let cw_print_error = function
13+
| err -> print_endline ("\n<ERROR::>" ^ (_esc_lf err))
14+
15+
let cw_print_result = function
16+
| RSuccess _ -> cw_print_success()
17+
| RFailure(_, err) -> cw_print_failure err
18+
| RError (_, err) -> cw_print_error err
19+
| _ -> ()
20+
721
let cw_print_test_event = function
8-
| EStart (name::rest) -> print_endline ("\n<IT::>" ^ string_of_node name)
9-
| EResult result ->
10-
begin match result with
11-
| RSuccess _ -> print_endline ("\n<PASSED::>Test passed")
12-
| RFailure (_, err) -> print_endline ("\n<FAILED::>" ^ (_esc_lf err))
13-
| RError (_, err) -> print_endline ("\n<ERROR::>" ^ (_esc_lf err))
14-
| _ -> ()
15-
end
22+
| EResult result -> cw_print_result result
1623
| _ -> ()
1724

18-
let run_test = function
19-
| TestLabel (name, suite) -> begin
20-
print_endline ("\n<DESCRIBE::>" ^ name);
21-
perform_test cw_print_test_event suite
25+
let rec dispatch_test_group = function
26+
| label, TestList tests -> begin
27+
print_endline("\n<DESCRIBE::>"^label);
28+
run_tests tests;
29+
print_endline("\n<COMPLETEDIN::>");
2230
end
23-
| suite -> perform_test cw_print_test_event suite
31+
32+
and dispatch_test_case = function
33+
| label, test_case -> begin
34+
print_endline("\n<IT::>"^label);
35+
perform_test cw_print_test_event test_case |> ignore;
36+
print_endline("\n<COMPLETEDIN::>");
37+
end
38+
39+
and dispatch_labeled_test = function
40+
| label, TestLabel (nested_label, test) -> dispatch_labeled_test (nested_label, test)
41+
| label, TestCase test_fun -> dispatch_test_case(label, TestCase test_fun)
42+
| label, TestList test_group -> dispatch_test_group(label, TestList test_group)
43+
44+
and run_test = function
45+
| TestList tests -> "" >::: tests |> run_test
46+
| TestCase func -> "" >:: func |> run_test
47+
| TestLabel(label, test) -> dispatch_labeled_test(label, test)
2448

25-
(* Solution and Tests are concatenated to `fixture.ml` *)
26-
let _ = List.map run_test Fixture.Tests.suite |> ignore
49+
and run_tests = function
50+
| tests -> List.iter run_test tests
51+
52+
(* `solution` and `fixture` are concatenated to `fixture.ml` *)
53+
let () = run_tests Fixture.Tests.suite

0 commit comments

Comments
 (0)