Mercurial > hg
comparison tests/run-tests.py @ 33814:81b12f69ef5b
run-tests: also color the summary messages (skipped, failed...)
author | Matthieu Laneuville <matthieu.laneuville@octobus.net> |
---|---|
date | Fri, 11 Aug 2017 14:21:49 +0200 |
parents | 2e43c5cd57a7 |
children | 4e8a46c25fac |
comparison
equal
deleted
inserted
replaced
33813:1e71a27dee97 | 33814:81b12f69ef5b |
---|---|
92 # ANSI color is unsupported prior to Windows 10 | 92 # ANSI color is unsupported prior to Windows 10 |
93 if os.name != 'nt': | 93 if os.name != 'nt': |
94 try: # is pygments installed | 94 try: # is pygments installed |
95 import pygments | 95 import pygments |
96 import pygments.lexers as lexers | 96 import pygments.lexers as lexers |
97 import pygments.lexer as lexer | |
97 import pygments.formatters as formatters | 98 import pygments.formatters as formatters |
99 import pygments.token as token | |
100 import pygments.style as style | |
98 pygmentspresent = True | 101 pygmentspresent = True |
99 difflexer = lexers.DiffLexer() | 102 difflexer = lexers.DiffLexer() |
100 terminal256formatter = formatters.Terminal256Formatter() | 103 terminal256formatter = formatters.Terminal256Formatter() |
101 except ImportError: | 104 except ImportError: |
102 pass | 105 pass |
106 | |
107 if pygmentspresent: | |
108 class TestRunnerStyle(style.Style): | |
109 default_style = "" | |
110 skipped = token.string_to_tokentype("Token.Generic.Skipped") | |
111 failed = token.string_to_tokentype("Token.Generic.Failed") | |
112 error = token.string_to_tokentype("Token.Generic.Error") | |
113 skippedname = token.string_to_tokentype("Token.Generic.SName") | |
114 failedname = token.string_to_tokentype("Token.Generic.FName") | |
115 styles = { | |
116 skipped: '#e5e5e5', | |
117 skippedname: '#00ffff', | |
118 failed: '#7f0000', | |
119 failedname: '#ff0000', | |
120 } | |
121 | |
122 class TestRunnerLexer(lexer.RegexLexer): | |
123 tokens = { | |
124 'root': [ | |
125 (r'^Skipped', token.Generic.Skipped, 'skipped'), | |
126 (r'^Failed ', token.Generic.Failed, 'failed'), | |
127 (r'^ERROR: ', token.Generic.Failed, 'failed'), | |
128 ], | |
129 'skipped': [ | |
130 (r'[\w-]+\.t', token.Generic.SName), | |
131 (r':.*', token.Generic.Skipped), | |
132 ], | |
133 'failed': [ | |
134 (r'[\w-]+\.t', token.Generic.FName), | |
135 (r'(:| ).*', token.Generic.Failed), | |
136 ] | |
137 } | |
103 | 138 |
104 if sys.version_info > (3, 5, 0): | 139 if sys.version_info > (3, 5, 0): |
105 PYTHON3 = True | 140 PYTHON3 = True |
106 xrange = range # we use xrange in one place, and we'd rather not use range | 141 xrange = range # we use xrange in one place, and we'd rather not use range |
107 def _bytespath(p): | 142 def _bytespath(p): |
1596 with iolock: | 1631 with iolock: |
1597 if reason == "timed out": | 1632 if reason == "timed out": |
1598 self.stream.write('t') | 1633 self.stream.write('t') |
1599 else: | 1634 else: |
1600 if not self._options.nodiff: | 1635 if not self._options.nodiff: |
1601 self.stream.write('\nERROR: %s output changed\n' % test) | 1636 formatted = '\nERROR: %s output changed\n' % test |
1637 if self.color: | |
1638 formatted = pygments.highlight( | |
1639 formatted, | |
1640 TestRunnerLexer(), | |
1641 formatters.Terminal256Formatter( | |
1642 style=TestRunnerStyle)) | |
1643 self.stream.write(formatted) | |
1602 self.stream.write('!') | 1644 self.stream.write('!') |
1603 | 1645 |
1604 self.stream.flush() | 1646 self.stream.flush() |
1605 | 1647 |
1606 def addSuccess(self, test): | 1648 def addSuccess(self, test): |
1998 with iolock: | 2040 with iolock: |
1999 self.stream.writeln('') | 2041 self.stream.writeln('') |
2000 | 2042 |
2001 if not self._runner.options.noskips: | 2043 if not self._runner.options.noskips: |
2002 for test, msg in result.skipped: | 2044 for test, msg in result.skipped: |
2003 self.stream.writeln('Skipped %s: %s' % (test.name, msg)) | 2045 formatted = 'Skipped %s: %s' % (test.name, msg) |
2046 if result.color: | |
2047 formatted = pygments.highlight( | |
2048 formatted, | |
2049 TestRunnerLexer(), | |
2050 formatters.Terminal256Formatter( | |
2051 style=TestRunnerStyle)).strip("\n") | |
2052 self.stream.writeln(formatted) | |
2004 for test, msg in result.failures: | 2053 for test, msg in result.failures: |
2005 self.stream.writeln('Failed %s: %s' % (test.name, msg)) | 2054 formatted = 'Failed %s: %s' % (test.name, msg) |
2055 if result.color: | |
2056 formatted = pygments.highlight( | |
2057 formatted, | |
2058 TestRunnerLexer(), | |
2059 formatters.Terminal256Formatter( | |
2060 style=TestRunnerStyle)).strip("\n") | |
2061 self.stream.writeln(formatted) | |
2006 for test, msg in result.errors: | 2062 for test, msg in result.errors: |
2007 self.stream.writeln('Errored %s: %s' % (test.name, msg)) | 2063 self.stream.writeln('Errored %s: %s' % (test.name, msg)) |
2008 | 2064 |
2009 if self._runner.options.xunit: | 2065 if self._runner.options.xunit: |
2010 with open(self._runner.options.xunit, "wb") as xuf: | 2066 with open(self._runner.options.xunit, "wb") as xuf: |