Skip to content

Commit 8f2f91d

Browse files
Print failed tests at the end
1 parent bc55110 commit 8f2f91d

File tree

2 files changed

+40
-7
lines changed

2 files changed

+40
-7
lines changed

check.py

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import sys
2222
import unittest
2323
from collections import OrderedDict
24+
from contextlib import contextmanager
2425
from multiprocessing.pool import ThreadPool
2526
from pathlib import Path
2627

@@ -219,6 +220,7 @@ def run_one_spec_test(wast: Path, stdout=None):
219220
return # don't try all the binary format stuff TODO
220221
else:
221222
shared.fail_with_error(str(e))
223+
raise
222224

223225
check_expected(actual, expected, stdout=stdout)
224226

@@ -248,32 +250,63 @@ def run_one_spec_test(wast: Path, stdout=None):
248250

249251

250252
def run_spec_test_with_wrapped_stdout(wast: Path):
253+
'''
254+
Returns (bool, str) where the first element is whether the test was
255+
successful and the second is the combined stdout and stderr of the test.
256+
'''
251257
out = io.StringIO()
252258
try:
253259
run_one_spec_test(wast, stdout=out)
254260
except Exception as e:
255261
# Serialize exceptions into the output string buffer
256262
# so they can be reported on the main thread.
257263
print(e, file=out)
258-
raise
259-
return out.getvalue()
264+
return False, out.getvalue()
265+
return True, out.getvalue()
266+
267+
268+
@contextmanager
269+
def red_stdout():
270+
try:
271+
print("\033[31m", end="")
272+
yield
273+
finally:
274+
print("\033[0m", end="")
260275

261276

262277
def run_spec_tests():
263278
print('\n[ checking wasm-shell spec testcases... ]\n')
264279

265280
worker_count = os.cpu_count()
266281
print("Running with", worker_count, "workers")
267-
test_paths = [Path(x) for x in shared.options.spec_tests]
282+
test_paths = (Path(x) for x in shared.options.spec_tests)
283+
284+
failed_stdouts = []
268285
with ThreadPool(processes=worker_count) as pool:
269286
try:
270-
for result in pool.imap_unordered(run_spec_test_with_wrapped_stdout, test_paths):
271-
print(result, end="")
287+
for success, stdout in pool.imap_unordered(run_spec_test_with_wrapped_stdout, test_paths):
288+
if success:
289+
print(stdout, end="")
290+
continue
291+
292+
failed_stdouts.append(stdout)
293+
if shared.options.abort_on_first_failure:
294+
with red_stdout():
295+
print("Aborted tests execution after first failure. Set --no-fail-fast to disable this.")
296+
break
272297
except KeyboardInterrupt:
273298
# Hard exit to avoid threads continuing to run after Ctrl-C.
274299
# There's no concern of deadlocking during shutdown here.
275300
os._exit(1)
276301

302+
if not failed_stdouts:
303+
return
304+
305+
with red_stdout():
306+
print("Failed tests:")
307+
for failed in failed_stdouts:
308+
print(failed, end="")
309+
277310

278311
def run_validator_tests():
279312
print('\n[ running validation tests... ]\n')

scripts/test/shared.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@ def parse_args(args):
4040
'--no-torture', dest='torture', action='store_false',
4141
help='Disables running the torture testcases.')
4242
parser.add_argument(
43-
'--abort-on-first-failure', dest='abort_on_first_failure',
43+
'--abort-on-first-failure', "--fail-fast", dest='abort_on_first_failure',
4444
action='store_true', default=True,
4545
help=('Specifies whether to halt test suite execution on first test error.'
4646
' Default: true.'))
4747
parser.add_argument(
48-
'--no-abort-on-first-failure', dest='abort_on_first_failure',
48+
'--no-abort-on-first-failure', "--no-fail-fast", dest='abort_on_first_failure',
4949
action='store_false',
5050
help=('If set, the whole test suite will run to completion independent of'
5151
' earlier errors.'))

0 commit comments

Comments
 (0)