forked from OSchip/llvm-project
lit: Factor a new OneCommandPerFileTest out of SyntaxCheckTest.
- Used for running a single fixed command on a directory of files, with the option of deriving a temporary input file from the test source. llvm-svn: 88844
This commit is contained in:
parent
c9b231c8d1
commit
9a61bd5022
|
@ -1,2 +1,3 @@
|
||||||
from TestFormats import GoogleTest, ShTest, TclTest, SyntaxCheckTest
|
from TestFormats import GoogleTest, ShTest, TclTest
|
||||||
|
from TestFormats import SyntaxCheckTest, OneCommandPerFileTest
|
||||||
|
|
||||||
|
|
|
@ -97,17 +97,20 @@ class TclTest(FileBasedTest):
|
||||||
import re
|
import re
|
||||||
import tempfile
|
import tempfile
|
||||||
|
|
||||||
class SyntaxCheckTest:
|
class OneCommandPerFileTest:
|
||||||
# FIXME: Refactor into generic test for running some command on a directory
|
# FIXME: Refactor into generic test for running some command on a directory
|
||||||
# of inputs.
|
# of inputs.
|
||||||
|
|
||||||
def __init__(self, compiler, dir, recursive, pattern,
|
def __init__(self, command, dir, recursive=False,
|
||||||
extra_cxx_args=[]):
|
pattern=".*", useTempInput=False):
|
||||||
self.compiler = str(compiler)
|
if isinstance(command, str):
|
||||||
|
self.command = [command]
|
||||||
|
else:
|
||||||
|
self.command = list(command)
|
||||||
self.dir = str(dir)
|
self.dir = str(dir)
|
||||||
self.recursive = bool(recursive)
|
self.recursive = bool(recursive)
|
||||||
self.pattern = re.compile(pattern)
|
self.pattern = re.compile(pattern)
|
||||||
self.extra_cxx_args = list(extra_cxx_args)
|
self.useTempInput = useTempInput
|
||||||
|
|
||||||
def getTestsInDirectory(self, testSuite, path_in_suite,
|
def getTestsInDirectory(self, testSuite, path_in_suite,
|
||||||
litConfig, localConfig):
|
litConfig, localConfig):
|
||||||
|
@ -134,20 +137,46 @@ class SyntaxCheckTest:
|
||||||
test.source_path = path
|
test.source_path = path
|
||||||
yield test
|
yield test
|
||||||
|
|
||||||
|
def createTempInput(self, tmp, test):
|
||||||
|
abstract
|
||||||
|
|
||||||
def execute(self, test, litConfig):
|
def execute(self, test, litConfig):
|
||||||
if test.config.unsupported:
|
if test.config.unsupported:
|
||||||
return (Test.UNSUPPORTED, 'Test is unsupported')
|
return (Test.UNSUPPORTED, 'Test is unsupported')
|
||||||
|
|
||||||
tmp = tempfile.NamedTemporaryFile(suffix='.cpp')
|
cmd = list(self.command)
|
||||||
print >>tmp, '#include "%s"' % test.source_path
|
|
||||||
tmp.flush()
|
# If using temp input, create a temporary file and hand it to the
|
||||||
|
# subclass.
|
||||||
|
if self.useTempInput:
|
||||||
|
tmp = tempfile.NamedTemporaryFile(suffix='.cpp')
|
||||||
|
self.createTempInput(tmp, test)
|
||||||
|
tmp.flush()
|
||||||
|
cmd.append(tmp.name)
|
||||||
|
else:
|
||||||
|
cmd.append(test.source_path)
|
||||||
|
|
||||||
cmd = [self.compiler, '-x', 'c++', '-fsyntax-only', tmp.name]
|
|
||||||
cmd.extend(self.extra_cxx_args)
|
|
||||||
out, err, exitCode = TestRunner.executeCommand(cmd)
|
out, err, exitCode = TestRunner.executeCommand(cmd)
|
||||||
|
|
||||||
diags = out + err
|
diags = out + err
|
||||||
if not exitCode and not diags.strip():
|
if not exitCode and not diags.strip():
|
||||||
return Test.PASS,''
|
return Test.PASS,''
|
||||||
|
|
||||||
return Test.FAIL, diags
|
# Try to include some useful information.
|
||||||
|
report = """Command: %s\n""" % ' '.join(["'%s'" % a
|
||||||
|
for a in cmd])
|
||||||
|
if self.useTempInput:
|
||||||
|
report += """Temporary File: %s\n""" % tmp.name
|
||||||
|
report += "--\n%s--\n""" % open(tmp.name).read()
|
||||||
|
report += """Output:\n--\n%s--""" % diags
|
||||||
|
|
||||||
|
return Test.FAIL, report
|
||||||
|
|
||||||
|
class SyntaxCheckTest(OneCommandPerFileTest):
|
||||||
|
def __init__(self, compiler, dir, extra_cxx_args=[], *args, **kwargs):
|
||||||
|
cmd = [compiler, '-x', 'c++', '-fsyntax-only'] + extra_cxx_args
|
||||||
|
OneCommandPerFileTest.__init__(self, cmd, dir,
|
||||||
|
useTempInput=1, *args, **kwargs)
|
||||||
|
|
||||||
|
def createTempInput(self, tmp, test):
|
||||||
|
print >>tmp, '#include "%s"' % test.source_path
|
||||||
|
|
Loading…
Reference in New Issue