[lit] Allow formats to return lit.Test.Result instances directly.

llvm-svn: 188948
This commit is contained in:
Daniel Dunbar 2013-08-21 22:26:40 +00:00
parent 61821065a2
commit 02ae385cac
2 changed files with 21 additions and 10 deletions

View File

@ -23,7 +23,7 @@ UNSUPPORTED = ResultCode('UNSUPPORTED', False)
class Result(object):
"""Wrapper for the results of executing an individual test."""
def __init__(self, code, output, elapsed):
def __init__(self, code, output='', elapsed=None):
# The result code.
self.code = code
# The test output.
@ -62,9 +62,13 @@ class Test:
# The test result, once complete.
self.result = None
def setResult(self, result, output, elapsed):
assert self.result is None, "Test result already set!"
self.result = Result(result, output, elapsed)
def setResult(self, result):
if self.result is not None:
raise ArgumentError("test result already set")
if not isinstance(result, Result):
raise ArgumentError("unexpected result type")
self.result = result
def getFullName(self):
return self.suite.config.name + ' :: ' + '/'.join(self.path_in_suite)

View File

@ -118,8 +118,15 @@ class Tester(threading.Thread):
result = None
startTime = time.time()
try:
result, output = test.config.test_format.execute(test,
self.litConfig)
result = test.config.test_format.execute(test, self.litConfig)
# Support deprecated result from execute() which returned the result
# code and additional output as a tuple.
if isinstance(result, tuple):
code, output = result
result = lit.Test.Result(code, output)
elif not isinstance(result, lit.Test.Result):
raise ValueError("unexpected result from test execution")
except KeyboardInterrupt:
# This is a sad hack. Unfortunately subprocess goes
# bonkers with ctrl-c and we start forking merrily.
@ -128,13 +135,13 @@ class Tester(threading.Thread):
except:
if self.litConfig.debug:
raise
result = lit.Test.UNRESOLVED
output = 'Exception during script execution:\n'
output += traceback.format_exc()
output += '\n'
elapsed = time.time() - startTime
result = lit.Test.Result(lit.Test.UNRESOLVED, output)
result.elapsed = time.time() - startTime
test.setResult(result, output, elapsed)
test.setResult(result)
self.display.update(test)
def runTests(numThreads, litConfig, provider, display):
@ -382,7 +389,7 @@ def main(builtinParameters = {}):
# Update results for any tests which weren't run.
for test in tests:
if test.result is None:
test.setResult(lit.Test.UNRESOLVED, '', 0.0)
test.setResult(lit.Test.Result(lit.Test.UNRESOLVED, '', 0.0))
# List test results organized by kind.
hasFailures = False