home
/
code
/
tiger.ml.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Improve final pass/fail indicator
[tiger.ml.git]
/
compiler
/
src
/
lib
/
tiger
/
tiger_test.ml
diff --git
a/compiler/src/lib/tiger/tiger_test.ml
b/compiler/src/lib/tiger/tiger_test.ml
index
bea8611
..
89376a3
100644
(file)
--- a/
compiler/src/lib/tiger/tiger_test.ml
+++ b/
compiler/src/lib/tiger/tiger_test.ml
@@
-45,7
+45,7
@@
type t =
; code : string
; out_lexing : (Tiger_parser.token list) option
; out_parsing : Tiger_absyn.t option
; code : string
; out_lexing : (Tiger_parser.token list) option
; out_parsing : Tiger_absyn.t option
- ; is_error_expected : (Tiger_error.t -> bool)
+ ; is_error_expected
_semant
: (Tiger_error.t -> bool)
}
type color =
}
type color =
@@
-69,19
+69,19
@@
let status indicator info =
| "" -> indicator
| _ -> sprintf "%s: %s" indicator info
| "" -> indicator
| _ -> sprintf "%s: %s" indicator info
-let status_
ok
?(info="") () =
- status (color Green "
OK
") info
+let status_
pass
?(info="") () =
+ status (color Green "
Pass
") info
-let status_
error
?(info="") () =
- status (color Red "
ERROR
") info
+let status_
fail
?(info="") () =
+ status (color Red "
Fail
") info
-let status_
warn
?(info="") () =
- status (color Yellow "
WARN
") info
+let status_
skip
?(info="") () =
+ status (color Yellow "
Skip
") info
let case
?(out_lexing)
?(out_parsing)
let case
?(out_lexing)
?(out_parsing)
- ?(is_error_expected=(fun _ -> false))
+ ?(is_error_expected
_semant
=(fun _ -> false))
~code
name
=
~code
name
=
@@
-89,7
+89,7
@@
let case
; code
; out_lexing
; out_parsing
; code
; out_lexing
; out_parsing
- ; is_error_expected
+ ; is_error_expected
_semant
}
let bar_sep = String.make 80 '-'
}
let bar_sep = String.make 80 '-'
@@
-135,7
+135,7
@@
let p_ln = print_newline
let p_indent n = p "%s" (indent n)
let run tests =
let p_indent n = p "%s" (indent n)
let run tests =
- let
error
_count = ref 0 in
+ let
failure
_count = ref 0 in
let run_pass ~f ~input ~expect_output ~is_error_expected =
let output_status = "n/a" in
let output_value = None in
let run_pass ~f ~input ~expect_output ~is_error_expected =
let output_status = "n/a" in
let output_value = None in
@@
-144,13
+144,13
@@
let run tests =
let execution_status =
(match e with
| Tiger_error.T e when is_error_expected e ->
let execution_status =
(match e with
| Tiger_error.T e when is_error_expected e ->
- status_
ok
() ~info:(Tiger_error.to_string e)
+ status_
pass
() ~info:(Tiger_error.to_string e)
| Tiger_error.T e ->
| Tiger_error.T e ->
- incr
error
_count;
- status_
error
() ~info:(Tiger_error.to_string e)
+ incr
failure
_count;
+ status_
fail
() ~info:(Tiger_error.to_string e)
| e ->
| e ->
- incr
error
_count;
- status_
error
() ~info:(Printexc.to_string e)
+ incr
failure
_count;
+ status_
fail
() ~info:(Printexc.to_string e)
)
in
( execution_status
)
in
( execution_status
@@
-158,50
+158,57
@@
let run tests =
, output_value
)
| Error info ->
, output_value
)
| Error info ->
- incr
error
_count;
- ( status_
error
~info ()
+ incr
failure
_count;
+ ( status_
fail
~info ()
, output_status
, output_value
)
| Ok produced ->
, output_status
, output_value
)
| Ok produced ->
- let execution_status = status_
ok
() in
+ let execution_status = status_
pass
() in
let output_status =
match
Option.map expect_output (fun expected -> expected = produced)
with
| None ->
let output_status =
match
Option.map expect_output (fun expected -> expected = produced)
with
| None ->
- status_
warn
() ~info:"expected output not provided"
+ status_
skip
() ~info:"expected output not provided"
| Some true ->
| Some true ->
- status_
ok
()
+ status_
pass
()
| Some false ->
| Some false ->
- incr
error
_count;
- status_
error
()
+ incr
failure
_count;
+ status_
fail
()
in
let output_value = Some produced in
(execution_status, output_status, output_value)
in
List.iter tests ~f:(
in
let output_value = Some produced in
(execution_status, output_status, output_value)
in
List.iter tests ~f:(
- fun {name; code; out_lexing; out_parsing; is_error_expected} ->
+ fun
+ { name
+ ; code
+ ; out_lexing
+ ; out_parsing
+ ; is_error_expected_semant
+ }
+ ->
let (stat_lex_exe, stat_lex_out_cmp, _) =
run_pass
~f:pass_lexing
~input:code
~expect_output:out_lexing
let (stat_lex_exe, stat_lex_out_cmp, _) =
run_pass
~f:pass_lexing
~input:code
~expect_output:out_lexing
- ~is_error_expected
+ ~is_error_expected
:(fun _ -> false)
in
let (stat_pars_exe, stat_pars_out_cmp, absyn_opt) =
run_pass
~f:pass_parsing
~input:code
~expect_output:out_parsing
in
let (stat_pars_exe, stat_pars_out_cmp, absyn_opt) =
run_pass
~f:pass_parsing
~input:code
~expect_output:out_parsing
- ~is_error_expected
+ ~is_error_expected
:(fun _ -> false)
in
let (stat_semant_exe, stat_semant_out_cmp, _) =
run_pass
~f:pass_semant
~input:absyn_opt
~expect_output:(Some ())
in
let (stat_semant_exe, stat_semant_out_cmp, _) =
run_pass
~f:pass_semant
~input:absyn_opt
~expect_output:(Some ())
- ~is_error_expected
+ ~is_error_expected
:is_error_expected_semant
in
p "%s" bar_sep; p_ln ();
p "Test: %S" name; p_ln ();
in
p "%s" bar_sep; p_ln ();
p "Test: %S" name; p_ln ();
@@
-216,8
+223,11
@@
let run tests =
p_indent 2; p "out: %s" stat_semant_out_cmp; p_ln ();
);
p "%s" bar_end; 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
- let clr = (if failures = 0 then Green else Red) in
- p "Failures: %s" (color clr (string_of_int failures)); p_ln ();
+ p "%s"
+ (match !failure_count with
+ | 0 -> status_pass ()
+ | _ -> status_fail () ~info:(s "%d failures" !failure_count)
+ );
+ p_ln ();
p "%s" bar_end; p_ln ();
p "%s" bar_end; p_ln ();
- exit
failures
+ exit
!failure_count
This page took
0.035458 seconds
and
4
git commands to generate.