pc and testing -> seperate files
This commit is contained in:
51
testing.ml
Normal file
51
testing.ml
Normal file
@@ -0,0 +1,51 @@
|
||||
type result = Pass | Fail | Skip;;
|
||||
|
||||
let testing = ref false;;
|
||||
let test_only = ref [];;
|
||||
let test_results = ref [];;
|
||||
|
||||
let rec should_skip test =
|
||||
match List.assoc_opt test !test_results with
|
||||
Some Fail
|
||||
| Some Skip -> true
|
||||
| _ -> false;;
|
||||
|
||||
let test name ?(depends = []) run =
|
||||
let test_only = !test_only in
|
||||
if (test_only = [] && !testing) || List.exists (String.equal name) test_only then begin
|
||||
Printf.printf "Test '%s': " name;
|
||||
let res = if List.exists should_skip depends then begin
|
||||
Printf.printf "Skip\n%!";
|
||||
Skip
|
||||
end else begin
|
||||
try
|
||||
run ();
|
||||
Printf.printf "Pass\n%!";
|
||||
Pass
|
||||
with e ->
|
||||
Printf.printf "FAIL\n%!";
|
||||
if test_only <> [] then begin
|
||||
let msg = Printexc.to_string e
|
||||
and stack = Printexc.get_backtrace () in
|
||||
Printf.printf "exception thrown: %s%s\n\n%!" msg stack
|
||||
end;
|
||||
Fail
|
||||
end; in
|
||||
test_results := (name, res) :: !test_results
|
||||
end;;
|
||||
|
||||
let () =
|
||||
let rec proc args =
|
||||
begin match args with
|
||||
[] -> ()
|
||||
| "--run-tests" :: tl ->
|
||||
testing := true;
|
||||
proc tl
|
||||
| "--run-test" :: test :: tl ->
|
||||
testing := false;
|
||||
test_only := test :: !test_only;
|
||||
proc tl
|
||||
| hd :: tl ->
|
||||
proc tl
|
||||
end
|
||||
in proc @@ Array.to_list Sys.argv;;
|
Reference in New Issue
Block a user