Skip to content

Commit 44923fb

Browse files
authored
Merge pull request #2 from hobovsky/main
2 parents a3a9220 + 8a50600 commit 44923fb

File tree

1 file changed

+37
-19
lines changed

1 file changed

+37
-19
lines changed

workspace/test.ml

Lines changed: 37 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,44 @@
11
open OUnit
22

3-
let _esc_lf s =
4-
s |> Str.global_replace (Str.regexp_string "\n") "<:LF:>";;
3+
let _esc_lf = Str.global_replace (Str.regexp_string "\n") "<:LF:>"
54

6-
(* TODO Fix missing `<COMPLETEDIN::>` *)
5+
let cw_print_success () = print_endline "\n<PASSED::>Test passed"
6+
7+
let cw_print_failure err = print_endline ("\n<FAILED::>" ^ _esc_lf err)
8+
9+
let cw_print_error err = print_endline ("\n<ERROR::>" ^ _esc_lf err)
10+
11+
let cw_print_result = function
12+
| RSuccess _ -> cw_print_success ()
13+
| RFailure (_, err) -> cw_print_failure err
14+
| RError (_, err) -> cw_print_error err
15+
| RSkip _ | RTodo _ -> ()
16+
717
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
16-
| _ -> ()
18+
| EResult result -> cw_print_result result
19+
| EStart _ | EEnd _ -> ()
1720

18-
let run_test = function
19-
| TestLabel (name, suite) -> begin
20-
print_endline ("\n<DESCRIBE::>" ^ name);
21-
perform_test cw_print_test_event suite
21+
let dispatch_test_case label test_case =
22+
print_endline ("\n<IT::>" ^ label);
23+
perform_test cw_print_test_event test_case |> ignore;
24+
print_endline "\n<COMPLETEDIN::>"
25+
26+
let rec dispatch_labeled_test label test =
27+
match test with
28+
| TestLabel (nested_label, nested_test) -> dispatch_labeled_test nested_label nested_test
29+
| TestCase _ -> dispatch_test_case label test
30+
| TestList tests -> begin
31+
print_endline ("\n<DESCRIBE::>" ^ label);
32+
run_tests tests;
33+
print_endline "\n<COMPLETEDIN::>";
2234
end
23-
| suite -> perform_test cw_print_test_event suite
35+
36+
and run_test = function
37+
| TestList tests -> "" >::: tests |> run_test
38+
| TestCase func -> "" >:: func |> run_test
39+
| TestLabel (label, test) -> dispatch_labeled_test label test
2440

25-
(* Solution and Tests are concatenated to `fixture.ml` *)
26-
let _ = List.map run_test Fixture.Tests.suite |> ignore
41+
and run_tests tests = List.iter run_test tests
42+
43+
(* `solution` and `fixture` are concatenated to `fixture.ml` *)
44+
let () = run_tests Fixture.Tests.suite

0 commit comments

Comments
 (0)