tests/run-tests.py
changeset 803 2941e3ddd1b1
parent 802 630d72ae4f76
child 822 842e2c76e64b
--- a/tests/run-tests.py	Wed Sep 22 23:46:57 2010 +0200
+++ b/tests/run-tests.py	Thu Sep 23 10:33:58 2010 +0200
@@ -503,14 +503,31 @@
 
     def rematch(el, l):
         try:
-            # hack to deal with graphlog, which looks like bogus regexes
-            if el.startswith('|'):
-                el = '\\' + el
-            return re.match(el, l)
+            # 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)
+
     pos = -1
     postout = []
     ret = 0
@@ -530,10 +547,12 @@
 
             if el == l: # perfect match (fast)
                 postout.append("  " + l)
-            elif el and rematch(el, l): # fallback regex match
-                postout.append("  " + el)
-            else: # mismatch - let diff deal with it
-                postout.append("  " + l)
+            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
 
     if pos in after:
         postout += after.pop(pos)