diff options
author | Paolo Bonzini <pbonzini@redhat.com> | 2020-11-19 10:20:46 +0100 |
---|---|---|
committer | Paolo Bonzini <pbonzini@redhat.com> | 2020-12-27 13:55:33 +0100 |
commit | 2201e2bca66603a33d0341a11427f09872eddfcf (patch) | |
tree | 8bc96942461e76b7399d91c9f51b2e1c0924dc10 | |
parent | 7b3cca5047993d7051b1d991ba6707b07c39a60b (diff) | |
download | meson-2201e2bca66603a33d0341a11427f09872eddfcf.zip meson-2201e2bca66603a33d0341a11427f09872eddfcf.tar.gz meson-2201e2bca66603a33d0341a11427f09872eddfcf.tar.bz2 |
mtest: improve colorization
Instead of colorizing the whole status line, only colorize the word
representing the outcome of the test (SKIP, OK, FAIL, etc.). This
is less intrusive, so the patch also does the following changes:
- colorize OK and EXPECTEDFAIL, respectively as green and yellow
- colorize the summary of failures as well.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
-rw-r--r-- | mesonbuild/mtest.py | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/mesonbuild/mtest.py b/mesonbuild/mtest.py index ad8ad62..b8db80d 100644 --- a/mesonbuild/mtest.py +++ b/mesonbuild/mtest.py @@ -188,6 +188,16 @@ class TestResult(enum.Enum): return self in {TestResult.FAIL, TestResult.TIMEOUT, TestResult.INTERRUPT, TestResult.UNEXPECTEDPASS, TestResult.ERROR} + def get_text(self, colorize: bool) -> str: + result_str = '{res:{reslen}}'.format(res=self.value, reslen=self.maxlen()) + if self.is_bad(): + decorator = mlog.red + elif self in (TestResult.SKIP, TestResult.EXPECTEDFAIL): + decorator = mlog.yellow + else: + decorator = mlog.green + return decorator(result_str).get_text(colorize) + class TAPParser: Plan = namedtuple('Plan', ['count', 'late', 'skipped', 'explanation']) @@ -967,23 +977,17 @@ class TestHarness: sys.exit('Unknown test result encountered: {}'.format(result.res)) def format(self, result: TestRun, colorize: bool) -> str: - result_str = '{num:{numlen}}/{testcount} {name:{name_max_len}} {res:{reslen}} {dur:.2f}s'.format( + result_str = '{num:{numlen}}/{testcount} {name:{name_max_len}} {res} {dur:.2f}s'.format( numlen=len(str(self.test_count)), num=result.num, testcount=self.test_count, name_max_len=self.name_max_len, name=result.name, - reslen=TestResult.maxlen(), - res=result.res.value, + res=result.res.get_text(colorize), dur=result.duration) if result.res is TestResult.FAIL: result_str += ' ' + returncode_to_status(result.returncode) - decorator = mlog.plain - if result.res.is_bad(): - decorator = mlog.red - elif result.res is TestResult.SKIP: - decorator = mlog.yellow - return decorator(result_str).get_text(colorize) + return result_str def print_stats(self, result: TestRun) -> None: if result.res.is_bad(): @@ -1009,7 +1013,7 @@ class TestHarness: if self.logfile: self.logfile.write("\nSummary of Failures:\n\n") for i, result in enumerate(self.collected_failures, 1): - print(self.format(result, False)) + print(self.format(result, mlog.colorize_console())) if self.logfile: self.logfile.write(self.format(result, False) + '\n') |