summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOleg Grenrus <oleg.grenrus@iki.fi>2019-05-08 09:35:15 +0300
committerBen Gamari <ben@smart-cactus.org>2019-05-14 16:41:19 -0400
commit5cf8032e2fd2a2f35b8de9016c6e38e92c524394 (patch)
treea9f17b8e93f8210530a4772f625b650642ce88e4
parente529c65eacf595006dd5358491d28c202d673732 (diff)
downloadhaskell-5cf8032e2fd2a2f35b8de9016c6e38e92c524394.tar.gz
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.
-rw-r--r--testsuite/driver/runtests.py19
-rw-r--r--testsuite/driver/testglobals.py3
-rw-r--r--testsuite/driver/testlib.py12
3 files changed, 30 insertions, 4 deletions
diff --git a/testsuite/driver/runtests.py b/testsuite/driver/runtests.py
index b439abde0c..107bd77696 100644
--- a/testsuite/driver/runtests.py
+++ b/testsuite/driver/runtests.py
@@ -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]
diff --git a/testsuite/driver/testglobals.py b/testsuite/driver/testglobals.py
index 054fd713d0..b28477c769 100644
--- a/testsuite/driver/testglobals.py
+++ b/testsuite/driver/testglobals.py
@@ -136,6 +136,9 @@ class TestConfig:
# The test environment.
self.test_env = 'local'
+ # terminal supports colors
+ self.supports_colors = False
+
global config
config = TestConfig()
diff --git a/testsuite/driver/testlib.py b/testsuite/driver/testlib.py
index 95274f30e5..dc8b1b85f1 100644
--- a/testsuite/driver/testlib.py
+++ b/testsuite/driver/testlib.py
@@ -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.