##// END OF EJS Templates
run-tests: also color the summary messages (skipped, failed...)
Matthieu Laneuville -
r33813:81b12f69 default
parent child Browse files
Show More
@@ -94,13 +94,48 b" 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
103
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 }
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
@@ -1598,7 +1633,14 b' class TestResult(unittest._TextTestResul'
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()
@@ -2000,9 +2042,23 b' class TextTestRunner(unittest.TextTestRu'
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
@@ -131,10 +131,9 b' test diff colorisation'
131 \x1b[38;5;34m+ bar*baz (glob)\x1b[39m (esc)
131 \x1b[38;5;34m+ bar*baz (glob)\x1b[39m (esc)
132 bar*bad (glob)
132 bar*bad (glob)
133 \x1b[38;5;124m- bar*baz (glob)\x1b[39m (esc)
133 \x1b[38;5;124m- bar*baz (glob)\x1b[39m (esc)
134
134 \x1b[38;5;88mERROR: \x1b[39m\x1b[38;5;9mtest-failure.t\x1b[39m\x1b[38;5;88m output changed\x1b[39m (esc)
135 ERROR: test-failure.t output changed
136 !
135 !
137 Failed test-failure.t: output changed
136 \x1b[38;5;88mFailed \x1b[39m\x1b[38;5;9mtest-failure.t\x1b[39m\x1b[38;5;88m: output changed\x1b[39m (esc)
138 # Ran 1 tests, 0 skipped, 1 failed.
137 # Ran 1 tests, 0 skipped, 1 failed.
139 python hash seed: * (glob)
138 python hash seed: * (glob)
140 [1]
139 [1]
General Comments 0
You need to be logged in to leave comments. Login now