[PATCH 4 of 4 V2] run-tests: add a dedicated 'isoptional' function

Pierre-Yves David pierre-yves.david at ens-lyon.org
Sun Sep 8 04:15:02 EDT 2019


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at octobus.net>
# Date 1560531004 -3600
#      Fri Jun 14 17:50:04 2019 +0100
# Node ID f70d40f8e6b66c0d885eb3d78ac2216985e3f183
# Parent  e01d12fd89afdda7e4d118c2e46f70f3207e1b1f
# EXP-Topic test-match
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r f70d40f8e6b6
run-tests: add a dedicated 'isoptional' function

This is clearer than repeated manual call to to 'endswith'.

(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
@@ -1306,6 +1306,11 @@ WARN_UNDEFINED = 1
 WARN_YES = 2
 WARN_NO = 3
 
+MARK_OPTIONAL = b" (?)\n"
+
+def isoptional(line):
+    return line.endswith(MARK_OPTIONAL)
+
 class TTest(Test):
     """A "t test" is a test backed by a .t file."""
 
@@ -1660,7 +1665,7 @@ class TTest(Test):
                     els.pop(i)
                     break
                 if el:
-                    if el.endswith(b" (?)\n"):
+                    if isoptional(el):
                         optional.append(i)
                     else:
                         m = optline.match(el)
@@ -1700,7 +1705,7 @@ class TTest(Test):
             while expected.get(pos, None):
                 el = expected[pos].pop(0)
                 if el:
-                    if not el.endswith(b" (?)\n"):
+                    if not isoptional(el):
                         m = optline.match(el)
                         if m:
                             conditions = [c for c in m.group(2).split(b' ')]
@@ -1773,9 +1778,9 @@ class TTest(Test):
         if el == l: # perfect match (fast)
             return True, True
         retry = False
-        if el.endswith(b" (?)\n"):
+        if isoptional(el):
             retry = "retry"
-            el = el[:-5] + b"\n"
+            el = el[:-len(MARK_OPTIONAL)] + b"\n"
         else:
             m = optline.match(el)
             if m:


More information about the Mercurial-devel mailing list