Skip to content

Commit 79357f3

Browse files
committed
Merge branch 'runner-improvements'
* runner-improvements: Add stop on first fail option Provide a good err msg for invalid test executables
2 parents 2c579ba + b57bea0 commit 79357f3

File tree

1 file changed

+24
-7
lines changed

1 file changed

+24
-7
lines changed

bin/jp-compliance

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,11 @@ class ComplianceTestRunner(object):
7878
self.tests = tests
7979
self.jp_executable = exe
8080

81-
def run_tests(self):
81+
def run_tests(self, stop_first_fail):
8282
for test_case in self._test_cases():
8383
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
8586

8687
def _should_run(self, test_case):
8788
if not self.tests:
@@ -125,9 +126,13 @@ class ComplianceTestRunner(object):
125126
def _run_test(self, test_case):
126127
command = shlex.split(self.jp_executable)
127128
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))
131136
process.stdin.write(json.dumps(test_case['given']))
132137
process.stdin.flush()
133138
stdout, stderr = process.communicate()
@@ -139,17 +144,21 @@ class ComplianceTestRunner(object):
139144
expected = test_case['result']
140145
if not actual == expected:
141146
self._show_failure(actual, test_case)
147+
return False
142148
else:
143149
sys.stdout.write('.')
144150
sys.stdout.flush()
151+
return True
145152
else:
146153
error_type = test_case['error']
147154
# For errors, we expect the error type on stderr.
148155
if error_type not in stderr:
149156
self._show_failure_for_error(stderr, test_case)
157+
return False
150158
else:
151159
sys.stdout.write('.')
152160
sys.stdout.flush()
161+
return True
153162

154163
def _show_failure(self, actual, test_case):
155164
test_case['actual'] = json.dumps(actual)
@@ -214,14 +223,22 @@ def main():
214223
'These values can then be used with the '
215224
'"-t/--tests" argument. If this argument is '
216225
'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.')
217228
args = parser.parse_args()
218229
runner = ComplianceTestRunner(args.exe, args.tests)
219230
if args.list:
220231
display_available_tests(runner.get_compliance_test_files())
221232
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
223239
sys.stdout.write('\n')
240+
return 0
224241

225242

226243
if __name__ == '__main__':
227-
main()
244+
sys.exit(main())

0 commit comments

Comments
 (0)