From patchwork Sat Sep 7 12:16:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [6, of, 9] run-tests: extract a `process_cmd_line` from the main function From: Pierre-Yves David X-Patchwork-Id: 41537 Message-Id: To: mercurial-devel@mercurial-scm.org Date: Sat, 07 Sep 2019 14:16:45 +0200 # HG changeset patch # User Pierre-Yves David # Date 1560529827 -3600 # Fri Jun 14 17:30:27 2019 +0100 # Node ID e9d8154ab03d353fcc5284a10d943be0129e4f4e # Parent a8b6d502b98abcb4853d062d06cbb9d8168c8a32 # EXP-Topic test-match # Available At https://bitbucket.org/octobus/mercurial-devel/ # hg pull https://bitbucket.org/octobus/mercurial-devel/ -r e9d8154ab03d run-tests: extract a `process_cmd_line` from the main function The main function doing line comparison is quite complex. Slicing it in smaller piece should clarify it. (This is a gratuitous cleanup that I made while investigating a bug). diff --git a/tests/run-tests.py b/tests/run-tests.py --- a/tests/run-tests.py +++ b/tests/run-tests.py @@ -1619,6 +1619,7 @@ class TTest(Test): if salt in out_rawline: out_line, cmd_line = out_rawline.split(salt, 1) + while out_line: if not out_line.endswith(b'\n'): out_line += b' (no-eol)\n' @@ -1699,15 +1700,8 @@ class TTest(Test): continue postout.append(b' ' + el) - if cmd_line: - # Add on last return code. - ret = int(cmd_line.split()[1]) - if ret != 0: - postout.append(b' [%d]\n' % ret) - if pos in after: - # Merge in non-active test bits. - postout += after.pop(pos) - pos = int(cmd_line.split()[0]) + pos, postout = self._process_cmd_line(cmd_line, pos, postout, after) + if pos in after: postout += after.pop(pos) @@ -1717,6 +1711,19 @@ class TTest(Test): return exitcode, postout + def _process_cmd_line(self, cmd_line, pos, postout, after): + """process a "command" part of a line from unified test output""" + if cmd_line: + # Add on last return code. + ret = int(cmd_line.split()[1]) + if ret != 0: + postout.append(b' [%d]\n' % ret) + if pos in after: + # Merge in non-active test bits. + postout += after.pop(pos) + pos = int(cmd_line.split()[0]) + return pos, postout + @staticmethod def rematch(el, l): try: