[lit] Move unittest adaptor code into discovery module.
authorDaniel Dunbar <daniel@zuster.org>
Thu, 31 Jan 2013 01:23:39 +0000 (01:23 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Thu, 31 Jan 2013 01:23:39 +0000 (01:23 +0000)
 - Also, add a test for it.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@174019 91177308-0d34-0410-b5e6-96231b3b80d8

utils/lit/lit/discovery.py
utils/lit/lit/main.py
utils/lit/tests/Inputs/unittest-adaptor/lit.cfg [new file with mode: 0644]
utils/lit/tests/Inputs/unittest-adaptor/test-one.txt [new file with mode: 0644]
utils/lit/tests/Inputs/unittest-adaptor/test-two.txt [new file with mode: 0644]
utils/lit/tests/unittest-adaptor.py [new file with mode: 0644]

index 830c5dea02786968117fc16a592d9cc0b047b4d3..c869a671ef723475c69c4960622847cd213e8b5e 100644 (file)
@@ -6,7 +6,7 @@ import os
 import sys
 
 from lit.TestingConfig import TestingConfig
-from lit import Test
+from lit import LitConfig, Test
 
 def dirContainsTestSuite(path, lit_config):
     cfgpath = os.path.join(path, lit_config.site_config_name)
@@ -208,3 +208,27 @@ def find_tests_for_inputs(lit_config, inputs):
         sys.exit(2)
 
     return tests
+
+def load_test_suite(inputs):
+    import platform
+    import unittest
+    from lit.LitTestCase import LitTestCase
+
+    # Create the global config object.
+    litConfig = LitConfig.LitConfig(progname = 'lit',
+                                    path = [],
+                                    quiet = False,
+                                    useValgrind = False,
+                                    valgrindLeakCheck = False,
+                                    valgrindArgs = [],
+                                    noExecute = False,
+                                    ignoreStdErr = False,
+                                    debug = False,
+                                    isWindows = (platform.system()=='Windows'),
+                                    params = {})
+
+    tests = find_tests_for_inputs(litConfig, inputs)
+
+    # Return a unittest test suite which just runs the tests in order.
+    return unittest.TestSuite([LitTestCase(test, litConfig) for test in tests])
+
index 5a3b11cde708ddac2bd5f74d600561f869f14ac4..da961eeedc636d8a8d0bff2e25df6625f37a27d9 100755 (executable)
@@ -148,28 +148,6 @@ def runTests(numThreads, litConfig, provider, display):
     except KeyboardInterrupt:
         sys.exit(2)
 
-def load_test_suite(inputs):
-    import unittest
-
-    # Create the global config object.
-    litConfig = LitConfig.LitConfig(progname = 'lit',
-                                    path = [],
-                                    quiet = False,
-                                    useValgrind = False,
-                                    valgrindLeakCheck = False,
-                                    valgrindArgs = [],
-                                    noExecute = False,
-                                    ignoreStdErr = False,
-                                    debug = False,
-                                    isWindows = (platform.system()=='Windows'),
-                                    params = {})
-
-    tests = lit.discovery.find_tests_for_inputs(litConfig, inputs)
-
-    # Return a unittest test suite which just runs the tests in order.
-    from LitTestCase import LitTestCase
-    return unittest.TestSuite([LitTestCase(test, litConfig) for test in tests])
-
 def main(builtinParameters = {}):
     # Bump the GIL check interval, its more important to get any one thread to a
     # blocking operation (hopefully exec) than to try and unblock other threads.
diff --git a/utils/lit/tests/Inputs/unittest-adaptor/lit.cfg b/utils/lit/tests/Inputs/unittest-adaptor/lit.cfg
new file mode 100644 (file)
index 0000000..52de709
--- /dev/null
@@ -0,0 +1,5 @@
+config.name = 'unittest-adaptor'
+config.suffixes = ['.txt']
+config.test_format = lit.formats.ShTest()
+config.test_source_root = None
+config.test_exec_root = None
diff --git a/utils/lit/tests/Inputs/unittest-adaptor/test-one.txt b/utils/lit/tests/Inputs/unittest-adaptor/test-one.txt
new file mode 100644 (file)
index 0000000..b80b60b
--- /dev/null
@@ -0,0 +1 @@
+# RUN: true
diff --git a/utils/lit/tests/Inputs/unittest-adaptor/test-two.txt b/utils/lit/tests/Inputs/unittest-adaptor/test-two.txt
new file mode 100644 (file)
index 0000000..49932c3
--- /dev/null
@@ -0,0 +1 @@
+# RUN: false
diff --git a/utils/lit/tests/unittest-adaptor.py b/utils/lit/tests/unittest-adaptor.py
new file mode 100644 (file)
index 0000000..243dd41
--- /dev/null
@@ -0,0 +1,18 @@
+# Check the lit adaption to run under unittest.
+#
+# RUN: python %s %{inputs}/unittest-adaptor 2> %t.err
+# RUN: FileCheck < %t.err %s
+#
+# CHECK: unittest-adaptor :: test-one.txt ... ok
+# CHECK: unittest-adaptor :: test-two.txt ... FAIL
+
+import unittest
+import sys
+
+import lit
+import lit.discovery
+
+input_path = sys.argv[1]
+unittest_suite = lit.discovery.load_test_suite([input_path])
+runner = unittest.TextTestRunner(verbosity=2)
+runner.run(unittest_suite)