run-tests: pass color option via test case object , not global var
authorMartin von Zweigbergk <martinvonz@google.com>
Mon, 17 Jul 2017 16:15:15 -0700
changeset 33565 0982d900dccb
parent 33564 91e3dcefc9b7
child 33566 97070cbf0813
run-tests: pass color option via test case object , not global var At first I updated the color field of the 'options' object (from the CLI parser), but then I decided to put it directly on the test case object itself to avoid mutating the shared object (even though all tests would have the same value). Differential Revision: https://phab.mercurial-scm.org/D114
tests/run-tests.py
--- a/tests/run-tests.py	Mon Jul 10 18:02:03 2017 -0700
+++ b/tests/run-tests.py	Mon Jul 17 16:15:15 2017 -0700
@@ -1564,16 +1564,12 @@
         self.successes = []
         self.faildata = {}
 
-        global with_color
-        if not self.stream.isatty(): # check if the terminal is capable
-            with_color = False
-
-        if options.color != 'auto':
-            if options.color == 'never':
-                with_color = False
-            else: # 'always', for testing purposes
-                if pygmentspresent:
-                    with_color = True
+        if options.color == 'auto':
+            self.color = with_color and self.stream.isatty()
+        elif options.color == 'never':
+            self.color = False
+        else: # 'always', for testing purposes
+            self.color = pygmentspresent
 
     def addFailure(self, test, reason):
         self.failures.append((test, reason))
@@ -1652,7 +1648,7 @@
                 else:
                     self.stream.write('\n')
                     for line in lines:
-                        if with_color and pygmentspresent:
+                        if self.color and pygmentspresent:
                             line = pygments.highlight(
                                     line,
                                     lexers.DiffLexer(),