Commit 5cf8032e authored by Oleg Grenrus's avatar Oleg Grenrus Committed by Ben Gamari

Update terminal title while running test-suite

Useful progress indicator even when `make test VERBOSE=1`,
and when you do something else, but have terminal title visible.
parent e529c65e
......@@ -189,6 +189,23 @@ else:
print('WARNING: No UTF8 locale found.')
print('You may get some spurious test failures.')
# https://stackoverflow.com/a/22254892/1308058
def supports_colors():
"""
Returns True if the running system's terminal supports color, and False
otherwise.
"""
plat = sys.platform
supported_platform = plat != 'Pocket PC' and (plat != 'win32' or
'ANSICON' in os.environ)
# isatty is not always implemented, #6223.
is_a_tty = hasattr(sys.stdout, 'isatty') and sys.stdout.isatty()
if not supported_platform or not is_a_tty:
return False
return True
config.supports_colors = supports_colors()
# This has to come after arg parsing as the args can change the compiler
get_compiler_info()
......@@ -412,7 +429,7 @@ else:
print(Perf.allow_changes_string(t.metrics))
print('-' * 25)
summary(t, sys.stdout, config.no_print_summary, True)
summary(t, sys.stdout, config.no_print_summary, config.supports_colors)
# Write perf stats if any exist or if a metrics file is specified.
stats = [stat for (_, stat) in t.metrics]
......
......@@ -136,6 +136,9 @@ class TestConfig:
# The test environment.
self.test_env = 'local'
# terminal supports colors
self.supports_colors = False
global config
config = TestConfig()
......
......@@ -891,11 +891,17 @@ def do_test(name, way, func, args, files):
full_name = name + '(' + way + ')'
if_verbose(2, "=====> {0} {1} of {2} {3}".format(
full_name, t.total_tests, len(allTestNames),
progress_args = [ full_name, t.total_tests, len(allTestNames),
[len(t.unexpected_passes),
len(t.unexpected_failures),
len(t.framework_failures)]))
len(t.framework_failures)]]
if_verbose(2, "=====> {0} {1} of {2} {3}".format(*progress_args))
# Update terminal title
# useful progress indicator even when make test VERBOSE=1
if config.supports_colors:
print("\033]0;{0} {1} of {2} {3}\007".format(*progress_args), end="")
sys.stdout.flush()
# Clean up prior to the test, so that we can't spuriously conclude
# that it passed on the basis of old run outputs.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment