comparison tests/run-tests.py @ 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 f059d6ffcdf0
comparison
equal deleted inserted replaced
42906:8510566b2bef 42907:75bd5990d8fe
1303 bchr = lambda x: bytes([x]) 1303 bchr = lambda x: bytes([x])
1304 1304
1305 WARN_UNDEFINED = 1 1305 WARN_UNDEFINED = 1
1306 WARN_YES = 2 1306 WARN_YES = 2
1307 WARN_NO = 3 1307 WARN_NO = 3
1308
1309 MARK_OPTIONAL = b" (?)\n"
1310
1311 def isoptional(line):
1312 return line.endswith(MARK_OPTIONAL)
1308 1313
1309 class TTest(Test): 1314 class TTest(Test):
1310 """A "t test" is a test backed by a .t file.""" 1315 """A "t test" is a test backed by a .t file."""
1311 1316
1312 SKIPPED_PREFIX = b'skipped: ' 1317 SKIPPED_PREFIX = b'skipped: '
1658 r = False 1663 r = False
1659 if r: 1664 if r:
1660 els.pop(i) 1665 els.pop(i)
1661 break 1666 break
1662 if el: 1667 if el:
1663 if el.endswith(b" (?)\n"): 1668 if isoptional(el):
1664 optional.append(i) 1669 optional.append(i)
1665 else: 1670 else:
1666 m = optline.match(el) 1671 m = optline.match(el)
1667 if m: 1672 if m:
1668 conditions = [ 1673 conditions = [
1698 else: 1703 else:
1699 # clean up any optional leftovers 1704 # clean up any optional leftovers
1700 while expected.get(pos, None): 1705 while expected.get(pos, None):
1701 el = expected[pos].pop(0) 1706 el = expected[pos].pop(0)
1702 if el: 1707 if el:
1703 if not el.endswith(b" (?)\n"): 1708 if not isoptional(el):
1704 m = optline.match(el) 1709 m = optline.match(el)
1705 if m: 1710 if m:
1706 conditions = [c for c in m.group(2).split(b' ')] 1711 conditions = [c for c in m.group(2).split(b' ')]
1707 1712
1708 if self._iftest(conditions): 1713 if self._iftest(conditions):
1771 1776
1772 def linematch(self, el, l): 1777 def linematch(self, el, l):
1773 if el == l: # perfect match (fast) 1778 if el == l: # perfect match (fast)
1774 return True, True 1779 return True, True
1775 retry = False 1780 retry = False
1776 if el.endswith(b" (?)\n"): 1781 if isoptional(el):
1777 retry = "retry" 1782 retry = "retry"
1778 el = el[:-5] + b"\n" 1783 el = el[:-len(MARK_OPTIONAL)] + b"\n"
1779 else: 1784 else:
1780 m = optline.match(el) 1785 m = optline.match(el)
1781 if m: 1786 if m:
1782 conditions = [c for c in m.group(2).split(b' ')] 1787 conditions = [c for c in m.group(2).split(b' ')]
1783 1788