Mercurial > hg
diff tests/run-tests.py @ 12376:97ffc68f71d3
tests: add glob matching for unified tests
This adds a " (glob)" marker that works like a simpler version of
(re): "*" is converted to ".*", and "?" is converted to ".".
Both special characters can be escaped using "\", and the backslash
itself can be escaped as well.
Other glob-style syntax, like "**", "[chars]", or "[!chars]", isn't
supported.
author | Brodie Rao <brodie@bitheap.org> |
---|---|
date | Wed, 22 Sep 2010 16:06:02 -0500 |
parents | 02990e22150b |
children | a5b77eb0409b |
line wrap: on
line diff
--- a/tests/run-tests.py Wed Sep 22 16:06:00 2010 -0500 +++ b/tests/run-tests.py Wed Sep 22 16:06:02 2010 -0500 @@ -509,6 +509,25 @@ # 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) + pos = -1 postout = [] ret = 0 @@ -528,8 +547,10 @@ if el == l: # perfect match (fast) postout.append(" " + l) - elif el and el.endswith(" (re)\n") and rematch(el[:-6] + '\n', l): - postout.append(" " + el) # fallback regex match + elif (el and + (el.endswith(" (re)\n") and rematch(el[:-6] + '\n', l) or + el.endswith(" (glob)\n") and globmatch(el[:-8] + '\n', l))): + postout.append(" " + el) # fallback regex/glob match else: postout.append(" " + l) # let diff deal with it