run-tests: pull out line matching function
authorMatt Mackall <mpm@selenic.com>
Thu, 03 Nov 2011 15:08:45 -0500
changeset 15415 8c90b3df5bed
parent 15414 2a62d7c8aee7
child 15416 3b7c4f96885c
run-tests: pull out line matching function
tests/run-tests.py
--- a/tests/run-tests.py	Thu Nov 03 14:51:04 2011 -0500
+++ b/tests/run-tests.py	Thu Nov 03 15:08:45 2011 -0500
@@ -548,6 +548,16 @@
             res += re.escape(c)
     return rematch(res, l)
 
+def linematch(el, l):
+    if el == l: # perfect match (fast)
+        return True
+    if (el and
+        (el.endswith(" (re)\n") and rematch(el[:-6] + '\n', l) or
+         el.endswith(" (glob)\n") and globmatch(el[:-8] + '\n', l) or
+         el.endswith(" (esc)\n") and el.decode('string-escape') == l)):
+        return True
+    return False
+
 def tsttest(test, wd, options, replacements):
     t = open(test)
     out = []
@@ -655,14 +665,8 @@
             if pos in expected and expected[pos]:
                 el = expected[pos].pop(0)
 
-            if el == lout: # perfect match (fast)
-                postout.append("  " + lout)
-            elif (el and
-                  (el.endswith(" (re)\n") and rematch(el[:-6] + '\n', lout) or
-                   el.endswith(" (glob)\n") and globmatch(el[:-8] + '\n', lout)
-                   or el.endswith(" (esc)\n") and
-                      el.decode('string-escape') == l)):
-                postout.append("  " + el) # fallback regex/glob/esc match
+            if linematch(el, lout):
+                postout.append("  " + el)
             else:
                 if needescape(lout):
                     lout = stringescape(lout.rstrip('\n')) + " (esc)\n"