X-Git-Url: https://git.xandkar.net/?a=blobdiff_plain;f=compiler%2Fsrc%2Flib%2Ftiger%2Ftiger_test.ml;h=12ddb227ccfd2c2b270d0d27033ff5f9fef804bf;hb=9949f15ba89b08c877b64e7f1d16e53cacc2999b;hp=83e9890584aaca794051ef06291bd91e549f30f3;hpb=df6377392ff2959a614242615a1dda51f5b97176;p=tiger.ml.git diff --git a/compiler/src/lib/tiger/tiger_test.ml b/compiler/src/lib/tiger/tiger_test.ml index 83e9890..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) @@ -108,6 +122,13 @@ let pass_parsing code : (Tiger_absyn.t, string) result = | ast -> Ok ast +let pass_semant (absyn_opt : Tiger_absyn.t option) : (unit, string) result = + match absyn_opt with + | None -> + Error "AST not provided" + | Some absyn -> + Ok (Tiger_semant.transProg absyn) + let s = sprintf let p = printf let p_ln = print_newline @@ -120,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) @@ -168,13 +189,20 @@ let run tests = ~expect_output:out_lexing ~is_error_expected in - let (stat_pars_exe, stat_pars_out_cmp, _) = + let (stat_pars_exe, stat_pars_out_cmp, absyn_opt) = run_pass ~f:pass_parsing ~input:code ~expect_output:out_parsing ~is_error_expected in + let (stat_semant_exe, stat_semant_out_cmp, _) = + run_pass + ~f:pass_semant + ~input:absyn_opt + ~expect_output:(Some ()) + ~is_error_expected + in p "%s" bar_sep; p_ln (); p "Test: %S" name; p_ln (); p_indent 1; p "Lexing:"; p_ln (); @@ -183,6 +211,9 @@ let run tests = p_indent 1; p "Parsing:"; p_ln (); p_indent 2; p "exe: %s" stat_pars_exe ; p_ln (); p_indent 2; p "out: %s" stat_pars_out_cmp; p_ln (); + p_indent 1; p "Semantic Analysis:"; p_ln (); + p_indent 2; p "exe: %s" stat_semant_exe ; p_ln (); + p_indent 2; p "out: %s" stat_semant_out_cmp; p_ln (); ); p "%s" bar_end; p_ln (); let failures = !error_count in