11
11
kIsWindows = sys .platform in ['win32' , 'cygwin' ]
12
12
13
13
class GoogleTest (TestFormat ):
14
- def __init__ (self , test_sub_dirs , test_suffix ):
14
+ def __init__ (self , test_sub_dirs , test_suffix , run_under = [] ):
15
15
self .test_sub_dirs = str (test_sub_dirs ).split (';' )
16
16
17
17
# On Windows, assume tests will also end in '.exe'.
@@ -21,6 +21,7 @@ def __init__(self, test_sub_dirs, test_suffix):
21
21
22
22
# Also check for .py files for testing purposes.
23
23
self .test_suffixes = {exe_suffix , test_suffix + '.py' }
24
+ self .run_under = run_under
24
25
25
26
def getGTestTests (self , path , litConfig , localConfig ):
26
27
"""getGTestTests(path) - [name]
@@ -32,7 +33,7 @@ def getGTestTests(self, path, litConfig, localConfig):
32
33
litConfig: LitConfig instance
33
34
localConfig: TestingConfig instance"""
34
35
35
- list_test_cmd = self .maybeAddPythonToCmd ([path , '--gtest_list_tests' ])
36
+ list_test_cmd = self .prepareCmd ([path , '--gtest_list_tests' ])
36
37
37
38
try :
38
39
output = subprocess .check_output (list_test_cmd ,
@@ -113,7 +114,7 @@ def execute(self, test, litConfig):
113
114
testName = namePrefix + '/' + testName
114
115
115
116
cmd = [testPath , '--gtest_filter=' + testName ]
116
- cmd = self .maybeAddPythonToCmd (cmd )
117
+ cmd = self .prepareCmd (cmd )
117
118
if litConfig .useValgrind :
118
119
cmd = litConfig .valgrindArgs + cmd
119
120
@@ -141,13 +142,17 @@ def execute(self, test, litConfig):
141
142
142
143
return lit .Test .PASS ,''
143
144
144
- def maybeAddPythonToCmd (self , cmd ):
145
- """Insert the python exe into the command if cmd[0] ends in .py
145
+ def prepareCmd (self , cmd ):
146
+ """Insert interpreter if needed.
146
147
148
+ It inserts the python exe into the command if cmd[0] ends in .py or caller
149
+ specified run_under.
147
150
We cannot rely on the system to interpret shebang lines for us on
148
151
Windows, so add the python executable to the command if this is a .py
149
152
script.
150
153
"""
151
154
if cmd [0 ].endswith ('.py' ):
152
- return [sys .executable ] + cmd
155
+ cmd = [sys .executable ] + cmd
156
+ if self .run_under :
157
+ cmd = self .run_under + cmd
153
158
return cmd
0 commit comments