[llvm] r374947 - [lit] Add back LitTestCase
Julian Lettner via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 15 13:57:21 PDT 2019
Author: yln
Date: Tue Oct 15 13:57:20 2019
New Revision: 374947
URL: http://llvm.org/viewvc/llvm-project?rev=374947&view=rev
Log:
[lit] Add back LitTestCase
This essentially reverts a commit [1] that removed the adaptor for
Python unittests. The code has been slightly refactored to make it more
additive: all code is contained in LitTestCase.py.
Usage sites will require a small adaption:
```
[old]
import lit.discovery
...
test_suite = lit.discovery.load_test_suite(...)
[new]
import lit.LitTestCase
...
test_suite = lit.LitTestCase.load_test_suite(...)
```
This was put back on request by Daniel Dunbar, since I wrongly assumed
that the functionality is unused. At least llbuild still uses this [2].
[1] 70ca752ccf6a8f362aea25ccd3ee2bbceca93b20
[2] https://github.com/apple/swift-llbuild/blob/master/utils/Xcode/LitXCTestAdaptor/LitTests.py#L16
Reviewed By: ddunbar
Differential Revision: https://reviews.llvm.org/D69002
Added:
llvm/trunk/utils/lit/lit/LitTestCase.py
llvm/trunk/utils/lit/tests/Inputs/unittest-adaptor/
llvm/trunk/utils/lit/tests/Inputs/unittest-adaptor/lit.cfg
llvm/trunk/utils/lit/tests/Inputs/unittest-adaptor/test-one.txt
llvm/trunk/utils/lit/tests/Inputs/unittest-adaptor/test-two.txt
llvm/trunk/utils/lit/tests/unittest-adaptor.py
Added: llvm/trunk/utils/lit/lit/LitTestCase.py
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/lit/lit/LitTestCase.py?rev=374947&view=auto
==============================================================================
--- llvm/trunk/utils/lit/lit/LitTestCase.py (added)
+++ llvm/trunk/utils/lit/lit/LitTestCase.py Tue Oct 15 13:57:20 2019
@@ -0,0 +1,62 @@
+import unittest
+
+import lit.worker
+import lit.LitConfig
+
+"""
+TestCase adaptor for providing a Python 'unittest' compatible interface to 'lit'
+tests.
+"""
+
+
+class UnresolvedError(RuntimeError):
+ pass
+
+
+class LitTestCase(unittest.TestCase):
+ def __init__(self, test, lit_config):
+ unittest.TestCase.__init__(self)
+ self._test = test
+ self._lit_config = lit_config
+
+ def id(self):
+ return self._test.getFullName()
+
+ def shortDescription(self):
+ return self._test.getFullName()
+
+ def runTest(self):
+ # Run the test.
+ lit.worker._execute_test(self._test, self._lit_config)
+
+ # Adapt the result to unittest.
+ result = self._test.result
+ if result.code is lit.Test.UNRESOLVED:
+ raise UnresolvedError(result.output)
+ elif result.code.isFailure:
+ self.fail(result.output)
+
+
+def load_test_suite(inputs):
+ import platform
+ windows = platform.system() == 'Windows'
+
+ # Create the global config object.
+ lit_config = lit.LitConfig.LitConfig(
+ progname='lit',
+ path=[],
+ quiet=False,
+ useValgrind=False,
+ valgrindLeakCheck=False,
+ valgrindArgs=[],
+ noExecute=False,
+ debug=False,
+ isWindows=windows,
+ params={})
+
+ # Perform test discovery.
+ tests = lit.discovery.find_tests_for_inputs(lit_config, inputs)
+ test_adaptors = [LitTestCase(t, lit_config) for t in tests]
+
+ # Return a unittest test suite which just runs the tests in order.
+ return unittest.TestSuite(test_adaptors)
Added: llvm/trunk/utils/lit/tests/Inputs/unittest-adaptor/lit.cfg
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/lit/tests/Inputs/unittest-adaptor/lit.cfg?rev=374947&view=auto
==============================================================================
--- llvm/trunk/utils/lit/tests/Inputs/unittest-adaptor/lit.cfg (added)
+++ llvm/trunk/utils/lit/tests/Inputs/unittest-adaptor/lit.cfg Tue Oct 15 13:57:20 2019
@@ -0,0 +1,6 @@
+import lit.formats
+config.name = 'unittest-adaptor'
+config.suffixes = ['.txt']
+config.test_format = lit.formats.ShTest()
+config.test_source_root = None
+config.test_exec_root = None
Added: llvm/trunk/utils/lit/tests/Inputs/unittest-adaptor/test-one.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/lit/tests/Inputs/unittest-adaptor/test-one.txt?rev=374947&view=auto
==============================================================================
--- llvm/trunk/utils/lit/tests/Inputs/unittest-adaptor/test-one.txt (added)
+++ llvm/trunk/utils/lit/tests/Inputs/unittest-adaptor/test-one.txt Tue Oct 15 13:57:20 2019
@@ -0,0 +1 @@
+# RUN: true
Added: llvm/trunk/utils/lit/tests/Inputs/unittest-adaptor/test-two.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/lit/tests/Inputs/unittest-adaptor/test-two.txt?rev=374947&view=auto
==============================================================================
--- llvm/trunk/utils/lit/tests/Inputs/unittest-adaptor/test-two.txt (added)
+++ llvm/trunk/utils/lit/tests/Inputs/unittest-adaptor/test-two.txt Tue Oct 15 13:57:20 2019
@@ -0,0 +1 @@
+# RUN: false
Added: llvm/trunk/utils/lit/tests/unittest-adaptor.py
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/lit/tests/unittest-adaptor.py?rev=374947&view=auto
==============================================================================
--- llvm/trunk/utils/lit/tests/unittest-adaptor.py (added)
+++ llvm/trunk/utils/lit/tests/unittest-adaptor.py Tue Oct 15 13:57:20 2019
@@ -0,0 +1,17 @@
+# Check the lit adaption to run under unittest.
+#
+# RUN: %{python} %s %{inputs}/unittest-adaptor 2> %t.err
+# RUN: FileCheck < %t.err %s
+#
+# CHECK-DAG: unittest-adaptor :: test-two.txt ... FAIL
+# CHECK-DAG: unittest-adaptor :: test-one.txt ... ok
+
+import sys
+import unittest
+
+import lit.LitTestCase
+
+input_path = sys.argv[1]
+unittest_suite = lit.LitTestCase.load_test_suite([input_path])
+runner = unittest.TextTestRunner(verbosity=2)
+runner.run(unittest_suite)
More information about the llvm-commits
mailing list