aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaolo Bonzini <pbonzini@redhat.com>2020-11-19 09:23:47 +0100
committerPaolo Bonzini <pbonzini@redhat.com>2020-12-27 13:55:33 +0100
commit7b3cca5047993d7051b1d991ba6707b07c39a60b (patch)
treeb9cf8e03c72730420b1f471d2c8b398b4af9e956
parenteadbf3dbf5e69f263e0a8e40aa07ee6419481b30 (diff)
downloadmeson-7b3cca5047993d7051b1d991ba6707b07c39a60b.zip
meson-7b3cca5047993d7051b1d991ba6707b07c39a60b.tar.gz
meson-7b3cca5047993d7051b1d991ba6707b07c39a60b.tar.bz2
mtest: store TestRuns in collected_failures
Instead of storing the string, store the whole TestRun. In the next patches we'll use this to colorize the summary of failures, and to allow a few more simplifications. There is some code duplication between the console and logfile code, but it won't matter as soon as console and logfile output will be in two completely separate classes. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
-rw-r--r--mesonbuild/mtest.py37
1 files changed, 24 insertions, 13 deletions
diff --git a/mesonbuild/mtest.py b/mesonbuild/mtest.py
index f1a45b7..ad8ad62 100644
--- a/mesonbuild/mtest.py
+++ b/mesonbuild/mtest.py
@@ -870,7 +870,7 @@ class TestHarness:
def __init__(self, options: argparse.Namespace):
self.options = options
self.collected_logs = [] # type: T.List[str]
- self.collected_failures = [] # type: T.List[str]
+ self.collected_failures = [] # type: T.List[TestRun]
self.fail_count = 0
self.expectedfail_count = 0
self.unexpectedpass_count = 0
@@ -880,7 +880,6 @@ class TestHarness:
self.test_count = 0
self.name_max_len = 0
self.is_run = False
- self.results = [] # type: T.List[TestRun]
self.logfilename = None # type: T.Optional[str]
self.logfile = None # type: T.Optional[T.TextIO]
self.jsonlogfile = None # type: T.Optional[T.TextIO]
@@ -967,7 +966,7 @@ class TestHarness:
else:
sys.exit('Unknown test result encountered: {}'.format(result.res))
- def print_stats(self, result: TestRun) -> None:
+ def format(self, result: TestRun, colorize: bool) -> str:
result_str = '{num:{numlen}}/{testcount} {name:{name_max_len}} {res:{reslen}} {dur:.2f}s'.format(
numlen=len(str(self.test_count)),
num=result.num,
@@ -979,15 +978,19 @@ class TestHarness:
dur=result.duration)
if result.res is TestResult.FAIL:
result_str += ' ' + returncode_to_status(result.returncode)
+ decorator = mlog.plain
if result.res.is_bad():
- self.collected_failures.append(result_str)
+ decorator = mlog.red
+ elif result.res is TestResult.SKIP:
+ decorator = mlog.yellow
+ return decorator(result_str).get_text(colorize)
+
+ def print_stats(self, result: TestRun) -> None:
+ if result.res.is_bad():
+ self.collected_failures.append(result)
if not self.options.quiet or not result.res.is_ok():
- decorator = mlog.plain
- if result.res.is_bad():
- decorator = mlog.red
- elif result.res is TestResult.SKIP:
- decorator = mlog.yellow
- print(decorator(result_str).get_text(mlog.colorize_console()))
+ print(self.format(result, mlog.colorize_console()))
+ result_str = self.format(result, False)
result_str += "\n\n" + result.get_log()
if result.res.is_bad():
if self.options.print_errorlogs:
@@ -1001,9 +1004,16 @@ class TestHarness:
def print_summary(self) -> None:
# Prepend a list of failures
- msg = '' if len(self.collected_failures) < 1 else "\nSummary of Failures:\n\n"
- msg += '\n'.join(self.collected_failures)
- msg += textwrap.dedent('''
+ if self.collected_failures:
+ print("\nSummary of Failures:\n")
+ 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))
+ if self.logfile:
+ self.logfile.write(self.format(result, False) + '\n')
+
+ msg = textwrap.dedent('''
Ok: {:<4}
Expected Fail: {:<4}
@@ -1016,6 +1026,7 @@ class TestHarness:
print(msg)
if self.logfile:
self.logfile.write(msg)
+
if self.junit:
self.junit.write()