Skip to content

Commit

Permalink
kunit: tool: Do not colorize output when redirected
Browse files Browse the repository at this point in the history
Filling log files with color codes makes diffs and other comparisons
difficult. Only emit vt100 codes when the stdout is a TTY.

Cc: Brendan Higgins <[email protected]>
Cc: [email protected]
Cc: [email protected]
Signed-off-by: Kees Cook <[email protected]>
Reviewed-by: David Gow <[email protected]>
Reviewed-by: Brendan Higgins <[email protected]>
Signed-off-by: Shuah Khan <[email protected]>
  • Loading branch information
kees authored and shuahkh committed Apr 4, 2022
1 parent 885210d commit d34f82d
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions tools/testing/kunit/kunit_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

from __future__ import annotations
import re
import sys

import datetime
from enum import Enum, auto
Expand Down Expand Up @@ -503,14 +504,20 @@ def parse_crash_in_log(test: Test) -> bool:

def red(text: str) -> str:
"""Returns inputted string with red color code."""
if not sys.stdout.isatty():
return text
return '\033[1;31m' + text + RESET

def yellow(text: str) -> str:
"""Returns inputted string with yellow color code."""
if not sys.stdout.isatty():
return text
return '\033[1;33m' + text + RESET

def green(text: str) -> str:
"""Returns inputted string with green color code."""
if not sys.stdout.isatty():
return text
return '\033[1;32m' + text + RESET

ANSI_LEN = len(red(''))
Expand Down

0 comments on commit d34f82d

Please sign in to comment.