diff options
author | Daniel Dunbar <daniel@zuster.org> | 2009-09-16 01:34:52 +0000 |
---|---|---|
committer | Daniel Dunbar <daniel@zuster.org> | 2009-09-16 01:34:52 +0000 |
commit | 7c748661ce1e8898479106bc808cce9b55110f5c (patch) | |
tree | b969e4338fc7cb375fabdb48a9678f07458eea29 | |
parent | b107fc15fc46e81a99886ad88cc8b6cbfe98ce87 (diff) | |
download | external_llvm-7c748661ce1e8898479106bc808cce9b55110f5c.zip external_llvm-7c748661ce1e8898479106bc808cce9b55110f5c.tar.gz external_llvm-7c748661ce1e8898479106bc808cce9b55110f5c.tar.bz2 |
lit: Add a custom test format for use in clang.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@81987 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | utils/lit/LitFormats.py | 2 | ||||
-rw-r--r-- | utils/lit/TestFormats.py | 53 |
2 files changed, 54 insertions, 1 deletions
diff --git a/utils/lit/LitFormats.py b/utils/lit/LitFormats.py index e22f84b..9b8250d 100644 --- a/utils/lit/LitFormats.py +++ b/utils/lit/LitFormats.py @@ -1,2 +1,2 @@ -from TestFormats import GoogleTest, ShTest, TclTest +from TestFormats import GoogleTest, ShTest, TclTest, SyntaxCheckTest diff --git a/utils/lit/TestFormats.py b/utils/lit/TestFormats.py index 6245146..61bdb18 100644 --- a/utils/lit/TestFormats.py +++ b/utils/lit/TestFormats.py @@ -89,3 +89,56 @@ class ShTest(FileBasedTest): 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 |