Mercurial > hg > mercurial-source
comparison tests/run-tests.py @ 12377: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 |
comparison
equal
deleted
inserted
replaced
12376:02990e22150b | 12377:97ffc68f71d3 |
---|---|
507 return re.match(el + r'\Z', l) | 507 return re.match(el + r'\Z', l) |
508 except re.error: | 508 except re.error: |
509 # el is an invalid regex | 509 # el is an invalid regex |
510 return False | 510 return False |
511 | 511 |
512 def globmatch(el, l): | |
513 # The only supported special characters are * and ?. Escaping is | |
514 # supported. | |
515 i, n = 0, len(el) | |
516 res = '' | |
517 while i < n: | |
518 c = el[i] | |
519 i += 1 | |
520 if c == '\\' and el[i] in '*?\\': | |
521 res += el[i-1:i+1] | |
522 i += 1 | |
523 elif c == '*': | |
524 res += '.*' | |
525 elif c == '?': | |
526 res += '.' | |
527 else: | |
528 res += re.escape(c) | |
529 return rematch(res, l) | |
530 | |
512 pos = -1 | 531 pos = -1 |
513 postout = [] | 532 postout = [] |
514 ret = 0 | 533 ret = 0 |
515 for n, l in enumerate(output): | 534 for n, l in enumerate(output): |
516 if l.startswith(salt): | 535 if l.startswith(salt): |
526 if pos in expected and expected[pos]: | 545 if pos in expected and expected[pos]: |
527 el = expected[pos].pop(0) | 546 el = expected[pos].pop(0) |
528 | 547 |
529 if el == l: # perfect match (fast) | 548 if el == l: # perfect match (fast) |
530 postout.append(" " + l) | 549 postout.append(" " + l) |
531 elif el and el.endswith(" (re)\n") and rematch(el[:-6] + '\n', l): | 550 elif (el and |
532 postout.append(" " + el) # fallback regex match | 551 (el.endswith(" (re)\n") and rematch(el[:-6] + '\n', l) or |
552 el.endswith(" (glob)\n") and globmatch(el[:-8] + '\n', l))): | |
553 postout.append(" " + el) # fallback regex/glob match | |
533 else: | 554 else: |
534 postout.append(" " + l) # let diff deal with it | 555 postout.append(" " + l) # let diff deal with it |
535 | 556 |
536 if pos in after: | 557 if pos in after: |
537 postout += after.pop(pos) | 558 postout += after.pop(pos) |