X-Git-Url: https://git.xandkar.net/?a=blobdiff_plain;f=compiler%2Fsrc%2Flib%2Ftiger%2Ftiger_test.ml;h=12ddb227ccfd2c2b270d0d27033ff5f9fef804bf;hb=9949f15ba89b08c877b64e7f1d16e53cacc2999b;hp=976fc3d9f0a6d6c96475df7c445aff357738a343;hpb=ea3f5e0c5e110e3ff8b8e07fa07add2a231cb549;p=tiger.ml.git diff --git a/compiler/src/lib/tiger/tiger_test.ml b/compiler/src/lib/tiger/tiger_test.ml index 976fc3d..12ddb22 100644 --- a/compiler/src/lib/tiger/tiger_test.ml +++ b/compiler/src/lib/tiger/tiger_test.ml @@ -64,6 +64,20 @@ let color color string = let color_off = "\027[0m" in sprintf "%s%s%s" color_on string color_off +let status indicator info = + match info with + | "" -> indicator + | _ -> sprintf "%s: %s" indicator info + +let status_pass ?(info="") () = + status (color Green "Pass") info + +let status_fail ?(info="") () = + status (color Red "Fail") info + +let status_skip ?(info="") () = + status (color Yellow "Skip") info + let case ?(out_lexing) ?(out_parsing) @@ -127,41 +141,41 @@ let run tests = let output_value = None in match f input with | exception e -> - let status_text, error_text = + let execution_status = (match e with | Tiger_error.T e when is_error_expected e -> - ((color Green "OK"), Tiger_error.to_string e) + status_pass () ~info:(Tiger_error.to_string e) | Tiger_error.T e -> incr error_count; - ((color Red "ERROR"), Tiger_error.to_string e) + status_fail () ~info:(Tiger_error.to_string e) | e -> incr error_count; - ((color Red "ERROR"), Printexc.to_string e) + status_fail () ~info:(Printexc.to_string e) ) in - ( s "%s: %s" status_text error_text + ( execution_status , output_status , output_value ) - | Error msg -> + | Error info -> incr error_count; - ( s "%s: %s" (color Red "ERROR") msg + ( status_fail ~info () , output_status , output_value ) | Ok produced -> - let execution_status = s "%s" (color Green "OK") in + let execution_status = status_pass () in let output_status = match Option.map expect_output (fun expected -> expected = produced) with | None -> - s "%s" (color Yellow "expected output not provided") + status_skip () ~info:"expected output not provided" | Some true -> - s "%s" (color Green "OK") + status_pass () | Some false -> incr error_count; - s "%s" (color Red "ERROR") + status_fail () in let output_value = Some produced in (execution_status, output_status, output_value)