[llvm-commits] [llvm] r81987 - in /llvm/trunk/utils/lit: LitFormats.py TestFormats.py

Daniel Dunbar daniel at zuster.org
Tue Sep 15 18:34:53 PDT 2009


Author: ddunbar
Date: Tue Sep 15 20:34:52 2009
New Revision: 81987

URL: http://llvm.org/viewvc/llvm-project?rev=81987&view=rev
Log:
lit: Add a custom test format for use in clang.

Modified:
    llvm/trunk/utils/lit/LitFormats.py
    llvm/trunk/utils/lit/TestFormats.py

Modified: llvm/trunk/utils/lit/LitFormats.py
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/lit/LitFormats.py?rev=81987&r1=81986&r2=81987&view=diff

==============================================================================
--- llvm/trunk/utils/lit/LitFormats.py (original)
+++ llvm/trunk/utils/lit/LitFormats.py Tue Sep 15 20:34:52 2009
@@ -1,2 +1,2 @@
-from TestFormats import GoogleTest, ShTest, TclTest
+from TestFormats import GoogleTest, ShTest, TclTest, SyntaxCheckTest
 

Modified: llvm/trunk/utils/lit/TestFormats.py
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/lit/TestFormats.py?rev=81987&r1=81986&r2=81987&view=diff

==============================================================================
--- llvm/trunk/utils/lit/TestFormats.py (original)
+++ llvm/trunk/utils/lit/TestFormats.py Tue Sep 15 20:34:52 2009
@@ -89,3 +89,56 @@
 class TclTest(FileBasedTest):
     def execute(self, test, litConfig):
         return TestRunner.executeTclTest(test, litConfig)
+
+###
+
+import re
+import tempfile
+
+class SyntaxCheckTest:
+    # FIXME: Refactor into generic test for running some command on a directory
+    # of inputs.
+
+    def __init__(self, compiler, dir, recursive, pattern, extra_cxx_args=[]):
+        self.compiler = str(compiler)
+        self.dir = str(dir)
+        self.recursive = bool(recursive)
+        self.pattern = re.compile(pattern)
+        self.extra_cxx_args = list(extra_cxx_args)
+
+    def getTestsInDirectory(self, testSuite, path_in_suite,
+                            litConfig, localConfig):
+        for dirname,subdirs,filenames in os.walk(self.dir):
+            if not self.recursive:
+                subdirs[:] = []
+
+            for filename in filenames:
+                if (not self.pattern.match(filename) or
+                    filename in localConfig.excludes):
+                    continue
+
+                path = os.path.join(dirname,filename)
+                suffix = path[len(self.dir):]
+                if suffix.startswith(os.sep):
+                    suffix = suffix[1:]
+                test = Test.Test(testSuite,
+                                 path_in_suite + tuple(suffix.split(os.sep)),
+                                 localConfig)
+                # FIXME: Hack?
+                test.source_path = path
+                yield test
+
+    def execute(self, test, litConfig):
+        tmp = tempfile.NamedTemporaryFile(suffix='.cpp')
+        print >>tmp, '#include "%s"' % test.source_path
+        tmp.flush()
+
+        cmd = [self.compiler, '-x', 'c++', '-fsyntax-only', tmp.name]
+        cmd.extend(self.extra_cxx_args)
+        out, err, exitCode = TestRunner.executeCommand(cmd)
+
+        diags = out + err
+        if not exitCode and not diags.strip():
+            return Test.PASS,''
+
+        return Test.FAIL, diags





More information about the llvm-commits mailing list