@@ -78,10 +78,11 @@ class ComplianceTestRunner(object):
78
78
self .tests = tests
79
79
self .jp_executable = exe
80
80
81
- def run_tests (self ):
81
+ def run_tests (self , stop_first_fail ):
82
82
for test_case in self ._test_cases ():
83
83
if self ._should_run (test_case ):
84
- self ._run_test (test_case )
84
+ if not self ._run_test (test_case ) and stop_first_fail :
85
+ return
85
86
86
87
def _should_run (self , test_case ):
87
88
if not self .tests :
@@ -125,9 +126,13 @@ class ComplianceTestRunner(object):
125
126
def _run_test (self , test_case ):
126
127
command = shlex .split (self .jp_executable )
127
128
command .append (test_case ['expression' ])
128
- process = subprocess .Popen (command , stdout = subprocess .PIPE ,
129
- stderr = subprocess .PIPE ,
130
- stdin = subprocess .PIPE )
129
+ try :
130
+ process = subprocess .Popen (command , stdout = subprocess .PIPE ,
131
+ stderr = subprocess .PIPE ,
132
+ stdin = subprocess .PIPE )
133
+ except Exception , e :
134
+ raise RuntimeError ('Could not execute test executable "%s": '
135
+ '%s' % (' ' .join (command ), e ))
131
136
process .stdin .write (json .dumps (test_case ['given' ]))
132
137
process .stdin .flush ()
133
138
stdout , stderr = process .communicate ()
@@ -139,17 +144,21 @@ class ComplianceTestRunner(object):
139
144
expected = test_case ['result' ]
140
145
if not actual == expected :
141
146
self ._show_failure (actual , test_case )
147
+ return False
142
148
else :
143
149
sys .stdout .write ('.' )
144
150
sys .stdout .flush ()
151
+ return True
145
152
else :
146
153
error_type = test_case ['error' ]
147
154
# For errors, we expect the error type on stderr.
148
155
if error_type not in stderr :
149
156
self ._show_failure_for_error (stderr , test_case )
157
+ return False
150
158
else :
151
159
sys .stdout .write ('.' )
152
160
sys .stdout .flush ()
161
+ return True
153
162
154
163
def _show_failure (self , actual , test_case ):
155
164
test_case ['actual' ] = json .dumps (actual )
@@ -214,14 +223,22 @@ def main():
214
223
'These values can then be used with the '
215
224
'"-t/--tests" argument. If this argument is '
216
225
'specified, no tests will actually be run.' ))
226
+ parser .add_argument ('-s' , '--stop-first-fail' , action = 'store_true' ,
227
+ help = 'Stop running tests after a single test fails.' )
217
228
args = parser .parse_args ()
218
229
runner = ComplianceTestRunner (args .exe , args .tests )
219
230
if args .list :
220
231
display_available_tests (runner .get_compliance_test_files ())
221
232
else :
222
- runner .run_tests ()
233
+ try :
234
+ runner .run_tests (args .stop_first_fail )
235
+ except Exception , e :
236
+ sys .stderr .write (str (e ))
237
+ sys .stderr .write ("\n " )
238
+ return 1
223
239
sys .stdout .write ('\n ' )
240
+ return 0
224
241
225
242
226
243
if __name__ == '__main__' :
227
- main ()
244
+ sys . exit ( main () )
0 commit comments