# HG changeset patch # User Pierre-Yves David # Date 1560531004 -3600 # Node ID 75bd5990d8fefebe308bbe155fae6e23977928ed # Parent 8510566b2bef78c7fb7767eee4ad408c57b5ea2e 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 -r 8510566b2bef -r 75bd5990d8fe tests/run-tests.py --- 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: