changeset 42907:75bd5990d8fe

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).
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Fri, 14 Jun 2019 17:50:04 +0100
parents 8510566b2bef
children ff1ff2aae132
files tests/run-tests.py
diffstat 1 files changed, 9 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/tests/run-tests.py	Fri Jun 14 17:39:16 2019 +0100
+++ b/tests/run-tests.py	Fri Jun 14 17:50:04 2019 +0100
@@ -1306,6 +1306,11 @@
 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 @@
                     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 @@
             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 @@
         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: