diff --git a/lib/ansi.mligo b/lib/ansi.mligo new file mode 100644 index 0000000..1b23905 --- /dev/null +++ b/lib/ansi.mligo @@ -0,0 +1,29 @@ +(* MIT License + + Copyright (c) 2022 Marigold + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal in + the Software without restriction, including without limitation the rights to + use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + the Software, and to permit persons to whom the Software is furnished to do so, + subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. *) + +let top = Option.unopt (Test.chr 27n) + +let green message = + top ^ "[32m" ^ message ^ top ^ "[0m" + +let red message = + top ^ "[31m" ^ message ^ top ^ "[0m" \ No newline at end of file diff --git a/lib/model.mligo b/lib/model.mligo index bfa8818..f8ec75b 100644 --- a/lib/model.mligo +++ b/lib/model.mligo @@ -23,6 +23,7 @@ #import "util.mligo" "Util" #import "logger.mligo" "Logger" #import "result.mligo" "Result" +#import "ansi.mligo" "Ansi" (** Describes the model of the test engine. *) @@ -63,10 +64,12 @@ let perform_case (log_level: Logger.level) (case : case) : (bool * string) = (** Pretty print the result of a test. *) let pp_case_result (is_succeed : bool) (message : string) (case : case) = - let flag = if is_succeed then "[v]" else "[x]" in + let flag, color = if is_succeed then "v", Ansi.green else "x", Ansi.red in let full_message = - flag ^ " " ^ case.case_name ^ " | " ^ case.case_desc - ^ ":\n " ^ message + "[" ^ (color flag) ^ "]" + ^ case.case_name ^ " | " + ^ case.case_desc ^ ":\n " + ^ color message in Test.println full_message @@ -93,10 +96,12 @@ let run_suite (log_level: Logger.level) (suite: suite) : bool = let is_succeed = failed_test = 0n in let () = if not is_succeed then - Test.println - ("There is some tests (" + let message = + "There is some tests (" ^ Util.nat_to_string_without_suffix failed_test - ^ ") that fails") + ^ ") that fails" + in Test.println (Ansi.red message) + in is_succeed