7 class GoogleTest(object):
8 def __init__(self, test_sub_dir, test_suffix):
9 self.test_sub_dir = str(test_sub_dir)
10 self.test_suffix = str(test_suffix)
12 def getGTestTests(self, path):
13 """getGTestTests(path) - [name]
15 Return the tests available in gtest executable."""
17 lines = Util.capture([path, '--gtest_list_tests']).split('\n')
25 while ln[index*2:index*2+2] == ' ':
27 while len(nested_tests) > index:
32 nested_tests.append(ln)
34 yield ''.join(nested_tests) + ln
36 def getTestsInDirectory(self, testSuite, path_in_suite,
37 litConfig, localConfig):
38 source_path = testSuite.getSourcePath(path_in_suite)
39 for filename in os.listdir(source_path):
40 # Check for the one subdirectory (build directory) tests will be in.
41 if filename != self.test_sub_dir:
44 filepath = os.path.join(source_path, filename)
45 for subfilename in os.listdir(filepath):
46 if subfilename.endswith(self.test_suffix):
47 execpath = os.path.join(filepath, subfilename)
49 # Discover the tests in this executable.
50 for name in self.getGTestTests(execpath):
51 testPath = path_in_suite + (filename, subfilename, name)
52 yield Test.Test(testSuite, testPath, localConfig)
54 def execute(self, test, litConfig):
55 testPath,testName = os.path.split(test.getSourcePath())
56 if not os.path.exists(testPath):
57 # Handle GTest typed tests, whose name includes a '/'.
58 testPath, namePrefix = os.path.split(testPath)
59 testName = os.path.join(namePrefix, testName)
61 cmd = [testPath, '--gtest_filter=' + testName]
62 out, err, exitCode = TestRunner.executeCommand(cmd)
67 return Test.FAIL, out + err
71 class FileBasedTest(object):
72 def getTestsInDirectory(self, testSuite, path_in_suite,
73 litConfig, localConfig):
74 source_path = testSuite.getSourcePath(path_in_suite)
75 for filename in os.listdir(source_path):
76 filepath = os.path.join(source_path, filename)
77 if not os.path.isdir(filepath):
78 base,ext = os.path.splitext(filename)
79 if ext in localConfig.suffixes:
80 yield Test.Test(testSuite, path_in_suite + (filename,),
83 class ShTest(FileBasedTest):
84 def __init__(self, execute_external = False, require_and_and = False):
85 self.execute_external = execute_external
86 self.require_and_and = require_and_and
88 def execute(self, test, litConfig):
89 return TestRunner.executeShTest(test, litConfig,
90 self.execute_external,
93 class TclTest(FileBasedTest):
94 def execute(self, test, litConfig):
95 return TestRunner.executeTclTest(test, litConfig)
102 class SyntaxCheckTest:
103 # FIXME: Refactor into generic test for running some command on a directory
106 def __init__(self, compiler, dir, recursive, pattern, extra_cxx_args=[]):
107 self.compiler = str(compiler)
109 self.recursive = bool(recursive)
110 self.pattern = re.compile(pattern)
111 self.extra_cxx_args = list(extra_cxx_args)
113 def getTestsInDirectory(self, testSuite, path_in_suite,
114 litConfig, localConfig):
115 for dirname,subdirs,filenames in os.walk(self.dir):
116 if not self.recursive:
119 for filename in filenames:
120 if (not self.pattern.match(filename) or
121 filename in localConfig.excludes):
124 path = os.path.join(dirname,filename)
125 suffix = path[len(self.dir):]
126 if suffix.startswith(os.sep):
128 test = Test.Test(testSuite,
129 path_in_suite + tuple(suffix.split(os.sep)),
132 test.source_path = path
135 def execute(self, test, litConfig):
136 tmp = tempfile.NamedTemporaryFile(suffix='.cpp')
137 print >>tmp, '#include "%s"' % test.source_path
140 cmd = [self.compiler, '-x', 'c++', '-fsyntax-only', tmp.name]
141 cmd.extend(self.extra_cxx_args)
142 out, err, exitCode = TestRunner.executeCommand(cmd)
145 if not exitCode and not diags.strip():
148 return Test.FAIL, diags