Show More
@@ -88,6 +88,18 b' origenviron = os.environ.copy()' | |||||
88 | osenvironb = getattr(os, 'environb', os.environ) |
|
88 | osenvironb = getattr(os, 'environb', os.environ) | |
89 | processlock = threading.Lock() |
|
89 | processlock = threading.Lock() | |
90 |
|
90 | |||
|
91 | with_color = False | |||
|
92 | try: # is pygments installed | |||
|
93 | import pygments | |||
|
94 | import pygments.lexers as lexers | |||
|
95 | import pygments.formatters as formatters | |||
|
96 | with_color = True | |||
|
97 | except ImportError: | |||
|
98 | pass | |||
|
99 | ||||
|
100 | if not sys.stderr.isatty(): # check if the terminal is capable | |||
|
101 | with_color = False | |||
|
102 | ||||
91 | if sys.version_info > (3, 5, 0): |
|
103 | if sys.version_info > (3, 5, 0): | |
92 | PYTHON3 = True |
|
104 | PYTHON3 = True | |
93 | xrange = range # we use xrange in one place, and we'd rather not use range |
|
105 | xrange = range # we use xrange in one place, and we'd rather not use range | |
@@ -255,6 +267,9 b' def getparser():' | |||||
255 | help="output files annotated with coverage") |
|
267 | help="output files annotated with coverage") | |
256 | parser.add_option("-c", "--cover", action="store_true", |
|
268 | parser.add_option("-c", "--cover", action="store_true", | |
257 | help="print a test coverage report") |
|
269 | help="print a test coverage report") | |
|
270 | parser.add_option("--color", choices=["always", "auto", "never"], | |||
|
271 | default="auto", | |||
|
272 | help="colorisation: always|auto|never (default: auto)") | |||
258 | parser.add_option("-d", "--debug", action="store_true", |
|
273 | parser.add_option("-d", "--debug", action="store_true", | |
259 | help="debug mode: write output of test scripts to console" |
|
274 | help="debug mode: write output of test scripts to console" | |
260 | " rather than capturing and diffing it (disables timeout)") |
|
275 | " rather than capturing and diffing it (disables timeout)") | |
@@ -397,6 +412,13 b' def parseargs(args, parser):' | |||||
397 | parser.error('--chg does not work when --with-hg is specified ' |
|
412 | parser.error('--chg does not work when --with-hg is specified ' | |
398 | '(use --with-chg instead)') |
|
413 | '(use --with-chg instead)') | |
399 |
|
414 | |||
|
415 | global with_color | |||
|
416 | if options.color != 'auto': | |||
|
417 | if options.color == 'never': | |||
|
418 | with_color = False | |||
|
419 | else: # 'always', for testing purposes | |||
|
420 | with_color = True | |||
|
421 | ||||
400 | global useipv6 |
|
422 | global useipv6 | |
401 | if options.ipv6: |
|
423 | if options.ipv6: | |
402 | useipv6 = checksocketfamily('AF_INET6') |
|
424 | useipv6 = checksocketfamily('AF_INET6') | |
@@ -1625,6 +1647,11 b' class TestResult(unittest._TextTestResul' | |||||
1625 | else: |
|
1647 | else: | |
1626 | self.stream.write('\n') |
|
1648 | self.stream.write('\n') | |
1627 | for line in lines: |
|
1649 | for line in lines: | |
|
1650 | if with_color: | |||
|
1651 | line = pygments.highlight( | |||
|
1652 | line, | |||
|
1653 | lexers.DiffLexer(), | |||
|
1654 | formatters.Terminal256Formatter()) | |||
1628 | if PYTHON3: |
|
1655 | if PYTHON3: | |
1629 | self.stream.flush() |
|
1656 | self.stream.flush() | |
1630 | self.stream.buffer.write(line) |
|
1657 | self.stream.buffer.write(line) |
@@ -119,6 +119,43 b' test churn with globs' | |||||
119 | python hash seed: * (glob) |
|
119 | python hash seed: * (glob) | |
120 | [1] |
|
120 | [1] | |
121 |
|
121 | |||
|
122 | test diff colorisation | |||
|
123 | ||||
|
124 | $ rt test-failure.t --color always | |||
|
125 | ||||
|
126 | \x1b[38;5;124m--- $TESTTMP/test-failure.t\x1b[39m (esc) | |||
|
127 | \x1b[38;5;34m+++ $TESTTMP/test-failure.t.err\x1b[39m (esc) | |||
|
128 | \x1b[38;5;90;01m@@ -1,3 +1,3 @@\x1b[39;00m (esc) | |||
|
129 | $ echo "bar-baz"; echo "bar-bad" | |||
|
130 | \x1b[38;5;34m+ bar*baz (glob)\x1b[39m (esc) | |||
|
131 | bar*bad (glob) | |||
|
132 | \x1b[38;5;124m- bar*baz (glob)\x1b[39m (esc) | |||
|
133 | ||||
|
134 | ERROR: test-failure.t output changed | |||
|
135 | ! | |||
|
136 | Failed test-failure.t: output changed | |||
|
137 | # Ran 1 tests, 0 skipped, 1 failed. | |||
|
138 | python hash seed: * (glob) | |||
|
139 | [1] | |||
|
140 | ||||
|
141 | $ rt test-failure.t 2> tmp.log | |||
|
142 | [1] | |||
|
143 | $ cat tmp.log | |||
|
144 | ||||
|
145 | --- $TESTTMP/test-failure.t | |||
|
146 | +++ $TESTTMP/test-failure.t.err | |||
|
147 | @@ -1,3 +1,3 @@ | |||
|
148 | $ echo "bar-baz"; echo "bar-bad" | |||
|
149 | + bar*baz (glob) | |||
|
150 | bar*bad (glob) | |||
|
151 | - bar*baz (glob) | |||
|
152 | ||||
|
153 | ERROR: test-failure.t output changed | |||
|
154 | ! | |||
|
155 | Failed test-failure.t: output changed | |||
|
156 | # Ran 1 tests, 0 skipped, 1 failed. | |||
|
157 | python hash seed: * (glob) | |||
|
158 | ||||
122 | basic failing test |
|
159 | basic failing test | |
123 | $ cat > test-failure.t << EOF |
|
160 | $ cat > test-failure.t << EOF | |
124 | > $ echo babar |
|
161 | > $ echo babar |
General Comments 0
You need to be logged in to leave comments.
Login now