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

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

Comments

Pierre-Yves David - Sept. 8, 2019, 8:15 a.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@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).
Augie Fackler - Sept. 9, 2019, 3:19 p.m.
On Sun, Sep 08, 2019 at 10:15:02AM +0200, Pierre-Yves David wrote:
> # HG changeset patch
> # User Pierre-Yves David <pierre-yves.david@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

queued, thanks

Patch

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: