changeset 47309:af4d1a177548

run-tests: disable color in 'auto' mode on Windows if stdout is redirected Differential Revision: https://phab.mercurial-scm.org/D10761
author Matt Harbison <matt_harbison@yahoo.com>
date Thu, 06 May 2021 19:39:19 -0400
parents bb4606f35d37
children 9a3aa54774ff
files tests/run-tests.py
diffstat 1 files changed, 7 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/tests/run-tests.py	Thu May 06 18:52:08 2021 -0400
+++ b/tests/run-tests.py	Thu May 06 19:39:19 2021 -0400
@@ -2211,7 +2211,13 @@
         self.faildata = {}
 
         if options.color == 'auto':
-            self.color = pygmentspresent and self.stream.isatty()
+            isatty = self.stream.isatty()
+            # For some reason, redirecting stdout on Windows disables the ANSI
+            # color processing of stderr, which is what is used to print the
+            # output.  Therefore, both must be tty on Windows to enable color.
+            if os.name == 'nt':
+                isatty = isatty and sys.stdout.isatty()
+            self.color = pygmentspresent and isatty
         elif options.color == 'never':
             self.color = False
         else:  # 'always', for testing purposes