mtest: refactor TestRun creation

Parse the error code outside SingleTestRunner's run() method.  This
will let us add TAP support without complicating that long method
further.
pull/4958/head
Paolo Bonzini 6 years ago
parent 4b5cf3f7c5
commit 1264f03637
  1. 31
      mesonbuild/mtest.py

@ -149,8 +149,17 @@ class TestResult(enum.Enum):
class TestRun: class TestRun:
def __init__(self, res, returncode, should_fail, duration, stdo, stde, cmd, @staticmethod
env): def make_exitcode(test, returncode, duration, stdo, stde, cmd):
if returncode == GNU_SKIP_RETURNCODE:
res = TestResult.SKIP
elif test.should_fail:
res = TestResult.EXPECTEDFAIL if bool(returncode) else TestResult.UNEXPECTEDPASS
else:
res = TestResult.FAIL if bool(returncode) else TestResult.OK
return TestRun(test, res, returncode, test.should_fail, duration, stdo, stde, cmd, test.env)
def __init__(self, test, res, returncode, duration, stdo, stde, cmd):
assert isinstance(res, TestResult) assert isinstance(res, TestResult)
self.res = res self.res = res
self.returncode = returncode self.returncode = returncode
@ -158,8 +167,8 @@ class TestRun:
self.stdo = stdo self.stdo = stdo
self.stde = stde self.stde = stde
self.cmd = cmd self.cmd = cmd
self.env = env self.env = test.env
self.should_fail = should_fail self.should_fail = test.should_fail
def get_log(self): def get_log(self):
res = '--- command ---\n' res = '--- command ---\n'
@ -257,9 +266,8 @@ class SingleTestRunner:
cmd = self._get_cmd() cmd = self._get_cmd()
if cmd is None: if cmd is None:
skip_stdout = 'Not run because can not execute cross compiled binaries.' skip_stdout = 'Not run because can not execute cross compiled binaries.'
return TestRun(res=TestResult.SKIP, returncode=GNU_SKIP_RETURNCODE, return TestRun(test=self.test, res=TestResult.SKIP, returncode=GNU_SKIP_RETURNCODE,
should_fail=self.test.should_fail, duration=0.0, duration=0.0, stdo=skip_stdout, stde=None, cmd=None)
stdo=skip_stdout, stde=None, cmd=None, env=self.test.env)
else: else:
wrap = TestHarness.get_wrapper(self.options) wrap = TestHarness.get_wrapper(self.options)
if self.options.gdb: if self.options.gdb:
@ -388,14 +396,9 @@ class SingleTestRunner:
stdo = "" stdo = ""
stde = additional_error stde = additional_error
if timed_out: if timed_out:
res = TestResult.TIMEOUT return TestRun(self.test, TestResult.TIMEOUT, p.returncode, duration, stdo, stde, cmd)
elif p.returncode == GNU_SKIP_RETURNCODE:
res = TestResult.SKIP
elif self.test.should_fail:
res = TestResult.EXPECTEDFAIL if bool(p.returncode) else TestResult.UNEXPECTEDPASS
else: else:
res = TestResult.FAIL if bool(p.returncode) else TestResult.OK return TestRun.make_exitcode(self.test, p.returncode, duration, stdo, stde, cmd)
return TestRun(res, p.returncode, self.test.should_fail, duration, stdo, stde, cmd, self.test.env)
class TestHarness: class TestHarness:

Loading…
Cancel
Save