mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1041944 - Printing mochitest failures at the end of the execution (with mach). r=ahal
This commit is contained in:
parent
93cda01912
commit
99c4a4f0c4
@ -24,7 +24,6 @@ from mach.decorators import (
|
||||
Command,
|
||||
)
|
||||
|
||||
from mach.logging import StructuredHumanFormatter
|
||||
|
||||
ADB_NOT_FOUND = '''
|
||||
The %s command requires the adb binary to be on your path.
|
||||
@ -76,11 +75,6 @@ FLAVORS = {
|
||||
'webapprt-chrome': 'webapprt-chrome',
|
||||
}
|
||||
|
||||
class UnexpectedFilter(logging.Filter):
|
||||
def filter(self, record):
|
||||
msg = getattr(record, 'params', {}).get('msg', '')
|
||||
return 'TEST-UNEXPECTED-' in msg
|
||||
|
||||
|
||||
class MochitestRunner(MozbuildObject):
|
||||
"""Easily run mochitests.
|
||||
@ -234,8 +228,6 @@ class MochitestRunner(MozbuildObject):
|
||||
print('No failure file present. Did you run mochitests before?')
|
||||
return 1
|
||||
|
||||
from StringIO import StringIO
|
||||
|
||||
# runtests.py is ambiguous, so we load the file/module manually.
|
||||
if 'mochitest' not in sys.modules:
|
||||
import imp
|
||||
@ -244,7 +236,6 @@ class MochitestRunner(MozbuildObject):
|
||||
imp.load_module('mochitest', fh, path,
|
||||
('.py', 'r', imp.PY_SOURCE))
|
||||
|
||||
import mozinfo
|
||||
import mochitest
|
||||
from manifestparser import TestManifest
|
||||
from mozbuild.testing import TestResolver
|
||||
@ -377,30 +368,14 @@ class MochitestRunner(MozbuildObject):
|
||||
# We need this to enable colorization of output.
|
||||
self.log_manager.enable_unstructured()
|
||||
|
||||
# Output processing is a little funky here. The old make targets
|
||||
# grepped the log output from TEST-UNEXPECTED-* and printed these lines
|
||||
# after test execution. Ideally the test runner would expose a Python
|
||||
# API for obtaining test results and we could just format failures
|
||||
# appropriately. Unfortunately, it doesn't yet do that. So, we capture
|
||||
# all output to a buffer then "grep" the buffer after test execution.
|
||||
# Bug 858197 tracks a Python API that would facilitate this.
|
||||
test_output = StringIO()
|
||||
handler = logging.StreamHandler(test_output)
|
||||
handler.addFilter(UnexpectedFilter())
|
||||
handler.setFormatter(StructuredHumanFormatter(0, write_times=False))
|
||||
logging.getLogger().addHandler(handler)
|
||||
|
||||
result = runner.runTests(options)
|
||||
|
||||
# Need to remove our buffering handler before we echo failures or else
|
||||
# it will catch them again!
|
||||
logging.getLogger().removeHandler(handler)
|
||||
self.log_manager.disable_unstructured()
|
||||
|
||||
if test_output.getvalue():
|
||||
if runner.message_logger.errors:
|
||||
result = 1
|
||||
for line in test_output.getvalue().splitlines():
|
||||
self.log(logging.INFO, 'unexpected', {'msg': line}, '{msg}')
|
||||
runner.message_logger.logger.warning("The following tests failed:")
|
||||
for error in runner.message_logger.errors:
|
||||
runner.message_logger.logger.log_raw(error)
|
||||
|
||||
return result
|
||||
|
||||
|
@ -93,6 +93,9 @@ class MessageLogger(object):
|
||||
# Message buffering
|
||||
self.buffered_messages = []
|
||||
|
||||
# Failures reporting, after the end of the tests execution
|
||||
self.errors = []
|
||||
|
||||
def valid_message(self, obj):
|
||||
"""True if the given object is a valid structured message (only does a superficial validation)"""
|
||||
return isinstance(obj, dict) and 'action' in obj and obj['action'] in MessageLogger.VALID_ACTIONS
|
||||
@ -133,6 +136,11 @@ class MessageLogger(object):
|
||||
unstructured = True
|
||||
message.pop('unstructured')
|
||||
|
||||
# Saving errors/failures to be shown at the end of the test run
|
||||
is_error = 'expected' in message or (message['action'] == 'log' and message['message'].startswith('TEST-UNEXPECTED'))
|
||||
if is_error:
|
||||
self.errors.append(message)
|
||||
|
||||
# If we don't do any buffering, or the tests haven't started, or the message was unstructured, it is directly logged
|
||||
if not self.buffering or unstructured or not self.tests_started:
|
||||
self.logger.log_raw(message)
|
||||
@ -143,7 +151,6 @@ class MessageLogger(object):
|
||||
self.buffered_messages = []
|
||||
|
||||
# Buffering logic; Also supports "raw" errors (in log messages) because some tests manually dump 'TEST-UNEXPECTED-FAIL'
|
||||
is_error = 'expected' in message or (message['action'] == 'log' and message['message'].startswith('TEST-UNEXPECTED'))
|
||||
if not is_error and message['action'] not in self.BUFFERED_ACTIONS:
|
||||
self.logger.log_raw(message)
|
||||
return
|
||||
|
Loading…
Reference in New Issue
Block a user