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

Pierre-Yves David pierre-yves.david at ens-lyon.org
Sat Sep 7 08:16:48 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 8ab000ab9c72847951a986b931da2e035283c6c7
# Parent  df7d3a5c505f6f0dd7e0ed63dd91b526e2ef1893
# EXP-Topic test-match
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r 8ab000ab9c72
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."""
 
@@ -1666,7 +1671,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)
@@ -1706,7 +1711,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' ')]
@@ -1779,9 +1784,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