Skip to content

Commit

Permalink
Merge pull request #7 from marigold-dev/colorfuloutput
Browse files Browse the repository at this point in the history
Add colorful output
  • Loading branch information
xvw authored Feb 17, 2023
2 parents b4faf1f + 646422d commit cd72e18
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 6 deletions.
29 changes: 29 additions & 0 deletions lib/ansi.mligo
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
(* MIT License
Copyright (c) 2022 Marigold <[email protected]>
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"
17 changes: 11 additions & 6 deletions lib/model.mligo
Original file line number Diff line number Diff line change
Expand Up @@ -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. *)

Expand Down Expand Up @@ -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

Expand All @@ -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

Expand Down

0 comments on commit cd72e18

Please sign in to comment.