Patchwork [1,of,4,V2] run-tests: extract a `process_cmd_line` from the main function

login
register
mail settings
Submitter Pierre-Yves David
Date Sept. 8, 2019, 8:14 a.m.
Message ID <0c5eff3f149ed6a04151.1567930499@nodosa.octopoid.net>
Download mbox | patch
Permalink /patch/41567/
State Accepted
Headers show

Comments

Pierre-Yves David - Sept. 8, 2019, 8:14 a.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@octobus.net>
# Date 1567930121 -7200
#      Sun Sep 08 10:08:41 2019 +0200
# Node ID 0c5eff3f149ed6a041511538ac6c04826ac0d29c
# Parent  5ca351ba24788d7a74b9b2b4d35589ce87d48942
# EXP-Topic test-match
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r 0c5eff3f149e
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).

Patch

diff --git a/tests/run-tests.py b/tests/run-tests.py
--- a/tests/run-tests.py
+++ b/tests/run-tests.py
@@ -1695,15 +1695,7 @@  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)
@@ -1713,6 +1705,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: