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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@188948 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Daniel Dunbar 2013-08-21 22:26:40 +00:00
parent ccd21b26dd
commit d3bf8a2c0a
2 changed files with 21 additions and 10 deletions

View File

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

View File

@ -118,8 +118,15 @@ class Tester(threading.Thread):
result = None result = None
startTime = time.time() startTime = time.time()
try: try:
result, output = test.config.test_format.execute(test, result = test.config.test_format.execute(test, self.litConfig)
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: except KeyboardInterrupt:
# This is a sad hack. Unfortunately subprocess goes # This is a sad hack. Unfortunately subprocess goes
# bonkers with ctrl-c and we start forking merrily. # bonkers with ctrl-c and we start forking merrily.
@ -128,13 +135,13 @@ class Tester(threading.Thread):
except: except:
if self.litConfig.debug: if self.litConfig.debug:
raise raise
result = lit.Test.UNRESOLVED
output = 'Exception during script execution:\n' output = 'Exception during script execution:\n'
output += traceback.format_exc() output += traceback.format_exc()
output += '\n' 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) self.display.update(test)
def runTests(numThreads, litConfig, provider, display): def runTests(numThreads, litConfig, provider, display):
@ -382,7 +389,7 @@ def main(builtinParameters = {}):
# Update results for any tests which weren't run. # Update results for any tests which weren't run.
for test in tests: for test in tests:
if test.result is None: 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. # List test results organized by kind.
hasFailures = False hasFailures = False