# HG changeset patch # User Matt Mackall # Date 2011-11-03 19:51:04 # Node ID 2a62d7c8aee7c2ada2606320cc952ba7bdd17615 # Parent 8e60433e070a566d7328a52c6ab56d86d349184c run-tests: pull out unified matching funcs diff --git a/tests/run-tests.py b/tests/run-tests.py --- a/tests/run-tests.py +++ b/tests/run-tests.py @@ -521,6 +521,33 @@ def escapef(m): def stringescape(s): return escapesub(escapef, s) +def rematch(el, l): + try: + # ensure that the regex matches to the end of the string + return re.match(el + r'\Z', l) + except re.error: + # el is an invalid regex + return False + +def globmatch(el, l): + # The only supported special characters are * and ?. Escaping is + # supported. + i, n = 0, len(el) + res = '' + while i < n: + c = el[i] + i += 1 + if c == '\\' and el[i] in '*?\\': + res += el[i - 1:i + 1] + i += 1 + elif c == '*': + res += '.*' + elif c == '?': + res += '.' + else: + res += re.escape(c) + return rematch(res, l) + def tsttest(test, wd, options, replacements): t = open(test) out = [] @@ -608,33 +635,6 @@ def tsttest(test, wd, options, replaceme finally: os.remove(name) - def rematch(el, l): - try: - # ensure that the regex matches to the end of the string - return re.match(el + r'\Z', l) - except re.error: - # el is an invalid regex - return False - - def globmatch(el, l): - # The only supported special characters are * and ?. Escaping is - # supported. - i, n = 0, len(el) - res = '' - while i < n: - c = el[i] - i += 1 - if c == '\\' and el[i] in '*?\\': - res += el[i - 1:i + 1] - i += 1 - elif c == '*': - res += '.*' - elif c == '?': - res += '.' - else: - res += re.escape(c) - return rematch(res, l) - # Merge the script output back into a unified test pos = -1