Mercurial > hg
comparison tests/run-tests.py @ 33930:f5d4bb8e944d
run-tests: factor out highlight functions
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Thu, 24 Aug 2017 22:15:40 +0900 |
parents | 5d2ce90c71f1 |
children | 7cab956794e4 |
comparison
equal
deleted
inserted
replaced
33929:5d2ce90c71f1 | 33930:f5d4bb8e944d |
---|---|
609 for m in msg: | 609 for m in msg: |
610 print(m, end=' ') | 610 print(m, end=' ') |
611 print() | 611 print() |
612 sys.stdout.flush() | 612 sys.stdout.flush() |
613 | 613 |
614 def highlightdiff(line, color): | |
615 if not color: | |
616 return line | |
617 assert pygmentspresent | |
618 return pygments.highlight(line, difflexer, terminal256formatter) | |
619 | |
620 def highlightmsg(msg, color): | |
621 if not color: | |
622 return msg | |
623 assert pygmentspresent | |
624 return pygments.highlight(msg, runnerlexer, runnerformatter) | |
625 | |
614 def terminate(proc): | 626 def terminate(proc): |
615 """Terminate subprocess""" | 627 """Terminate subprocess""" |
616 vlog('# Terminating process %d' % proc.pid) | 628 vlog('# Terminating process %d' % proc.pid) |
617 try: | 629 try: |
618 proc.terminate() | 630 proc.terminate() |
1634 if reason == "timed out": | 1646 if reason == "timed out": |
1635 self.stream.write('t') | 1647 self.stream.write('t') |
1636 else: | 1648 else: |
1637 if not self._options.nodiff: | 1649 if not self._options.nodiff: |
1638 formatted = '\nERROR: %s output changed\n' % test | 1650 formatted = '\nERROR: %s output changed\n' % test |
1639 if self.color: | 1651 self.stream.write(highlightmsg(formatted, self.color)) |
1640 formatted = pygments.highlight( | |
1641 formatted, | |
1642 runnerlexer, | |
1643 runnerformatter) | |
1644 self.stream.write(formatted) | |
1645 self.stream.write('!') | 1652 self.stream.write('!') |
1646 | 1653 |
1647 self.stream.flush() | 1654 self.stream.flush() |
1648 | 1655 |
1649 def addSuccess(self, test): | 1656 def addSuccess(self, test): |
1705 raise test.failureException( | 1712 raise test.failureException( |
1706 'server failed to start (HGPORT=%s)' % test._startport) | 1713 'server failed to start (HGPORT=%s)' % test._startport) |
1707 else: | 1714 else: |
1708 self.stream.write('\n') | 1715 self.stream.write('\n') |
1709 for line in lines: | 1716 for line in lines: |
1710 if self.color: | 1717 line = highlightdiff(line, self.color) |
1711 line = pygments.highlight(line, | |
1712 difflexer, | |
1713 terminal256formatter) | |
1714 if PYTHON3: | 1718 if PYTHON3: |
1715 self.stream.flush() | 1719 self.stream.flush() |
1716 self.stream.buffer.write(line) | 1720 self.stream.buffer.write(line) |
1717 self.stream.buffer.flush() | 1721 self.stream.buffer.flush() |
1718 else: | 1722 else: |
2042 self.stream.writeln('') | 2046 self.stream.writeln('') |
2043 | 2047 |
2044 if not self._runner.options.noskips: | 2048 if not self._runner.options.noskips: |
2045 for test, msg in result.skipped: | 2049 for test, msg in result.skipped: |
2046 formatted = 'Skipped %s: %s\n' % (test.name, msg) | 2050 formatted = 'Skipped %s: %s\n' % (test.name, msg) |
2047 if result.color: | 2051 self.stream.write(highlightmsg(formatted, result.color)) |
2048 formatted = pygments.highlight( | |
2049 formatted, | |
2050 runnerlexer, | |
2051 runnerformatter) | |
2052 self.stream.write(formatted) | |
2053 for test, msg in result.failures: | 2052 for test, msg in result.failures: |
2054 formatted = 'Failed %s: %s\n' % (test.name, msg) | 2053 formatted = 'Failed %s: %s\n' % (test.name, msg) |
2055 if result.color: | 2054 self.stream.write(highlightmsg(formatted, result.color)) |
2056 formatted = pygments.highlight( | |
2057 formatted, | |
2058 runnerlexer, | |
2059 runnerformatter) | |
2060 self.stream.write(formatted) | |
2061 for test, msg in result.errors: | 2055 for test, msg in result.errors: |
2062 self.stream.writeln('Errored %s: %s' % (test.name, msg)) | 2056 self.stream.writeln('Errored %s: %s' % (test.name, msg)) |
2063 | 2057 |
2064 if self._runner.options.xunit: | 2058 if self._runner.options.xunit: |
2065 with open(self._runner.options.xunit, "wb") as xuf: | 2059 with open(self._runner.options.xunit, "wb") as xuf: |