13
13
import os
14
14
import sys
15
15
import argparse
16
+ import signal
16
17
import subprocess # nosec B404
17
18
18
19
@@ -59,6 +60,20 @@ def _print_environ(env):
59
60
_print_end_header ()
60
61
61
62
63
+ def _print_failure (code , stdout ):
64
+ # Display some context in the CI log so the user doesn't have to click down the lines
65
+ if _ci ():
66
+ _print_format ("stdout/stderr of failure:" )
67
+ print (stdout )
68
+
69
+ signalname = "???"
70
+ try :
71
+ signalname = signal .strsignal (abs (code ))
72
+ except ValueError :
73
+ pass
74
+ _print_format ("Got error code {} ({})" , code , signalname )
75
+
76
+
62
77
def _check_filter (cmd , filter ):
63
78
"""
64
79
Checks that the filter matches at least one test for the given cmd
@@ -83,17 +98,20 @@ def _run_cmd(cmd, comment, filter):
83
98
if not _check_filter (cmd , filter ):
84
99
_print_end_header ()
85
100
_print_error ("Could not find any tests with this filter" )
86
- return 2
101
+ return ( 2 , "" )
87
102
88
103
sys .stdout .flush ()
89
- result = subprocess .call ( # nosec B603
104
+ proc = subprocess .Popen ( # nosec B603
90
105
cmd ,
91
- stdout = sys . stdout ,
92
- stderr = sys . stdout ,
106
+ stdout = subprocess . PIPE ,
107
+ stderr = subprocess . STDOUT ,
93
108
env = (os .environ | {"GTEST_FILTER" : filter }),
94
109
)
110
+ stdout = proc .communicate ()[0 ].decode ("utf-8" )
111
+ returncode = proc .wait ()
112
+ print (stdout )
95
113
_print_end_header ()
96
- return result
114
+ return ( returncode , stdout )
97
115
98
116
99
117
if __name__ == "__main__" :
@@ -155,23 +173,25 @@ def _run_cmd(cmd, comment, filter):
155
173
# First, run all the known good tests
156
174
gtest_filter = "-" + (":" .join (map (lambda x : x ["pattern" ], fail_patterns )))
157
175
if _check_filter (base_invocation , gtest_filter ):
158
- result = _run_cmd (base_invocation , "known good tests" , gtest_filter )
176
+ ( result , stdout ) = _run_cmd (base_invocation , "known good tests" , gtest_filter )
159
177
if result != 0 :
160
178
_print_error ("Tests we expected to pass have failed" )
179
+ _print_failure (result , stdout )
161
180
final_result = result
162
181
else :
163
182
_print_format ("Note: No tests in this suite are expected to pass" )
164
183
165
184
# Then run each known failing tests
166
185
for fail in fail_patterns :
167
- result = _run_cmd (
186
+ ( result , stdout ) = _run_cmd (
168
187
base_invocation , "failing test {}" .format (fail ["pattern" ]), fail ["pattern" ]
169
188
)
170
189
171
190
if result == 0 and not fail ["optional" ]:
172
191
_print_error (
173
192
"Test {} is passing when we expect it to fail!" , fail ["pattern" ]
174
193
)
194
+ _print_failure (result , stdout )
175
195
final_result = 1
176
196
177
197
sys .exit (final_result )
0 commit comments