[lit] Allow formats to return lit.Test.Result instances directly.
authorDaniel Dunbar <daniel@zuster.org>
Wed, 21 Aug 2013 22:26:40 +0000 (22:26 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Wed, 21 Aug 2013 22:26:40 +0000 (22:26 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@188948 91177308-0d34-0410-b5e6-96231b3b80d8

utils/lit/lit/Test.py
utils/lit/lit/main.py

index d37854ece1d619552d05ae67e39136b185ab6710..c1bacb3d86d1f8b8efe00df458c411935e01f0d7 100644 (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)
index 9608803ef7182ce642a1052b40849266dc3bfed9..b84140f90f4a6c2f2b8f09e7b7cbf2d699e157ea 100755 (executable)
@@ -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