changeset 21315:56610da39b48

run-tests: make linematch a static method of TTest linematch only applies to t tests. It makes sense to move everything t test related to the TTest class.
author Gregory Szorc <gregory.szorc@gmail.com>
date Sat, 19 Apr 2014 16:11:49 -0700
parents 76d7967d8f3d
children ab9bf8a5e573
files tests/run-tests.py tests/test-run-tests.py
diffstat 2 files changed, 19 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/tests/run-tests.py	Sat Apr 19 15:37:50 2014 -0700
+++ b/tests/run-tests.py	Sat Apr 19 16:11:49 2014 -0700
@@ -731,22 +731,6 @@
             res += re.escape(c)
     return rematch(res, l)
 
-def linematch(el, l):
-    if el == l: # perfect match (fast)
-        return True
-    if el:
-        if el.endswith(" (esc)\n"):
-            el = el[:-7].decode('string-escape') + '\n'
-        if el == l or os.name == 'nt' and el[:-1] + '\r\n' == l:
-            return True
-        if el.endswith(" (re)\n"):
-            return rematch(el[:-6], l)
-        if el.endswith(" (glob)\n"):
-            return globmatch(el[:-8], l)
-        if os.altsep and l.replace('\\', '/') == el:
-            return '+glob'
-    return False
-
 class TTest(Test):
     """A "t test" is a test backed by a .t file."""
 
@@ -919,7 +903,7 @@
                 if expected.get(pos, None):
                     el = expected[pos].pop(0)
 
-                r = linematch(el, lout)
+                r = TTest.linematch(el, lout)
                 if isinstance(r, str):
                     if r == '+glob':
                         lout = el[:-1] + ' (glob)\n'
@@ -959,6 +943,23 @@
 
         return exitcode, postout
 
+    @staticmethod
+    def linematch(el, l):
+        if el == l: # perfect match (fast)
+            return True
+        if el:
+            if el.endswith(" (esc)\n"):
+                el = el[:-7].decode('string-escape') + '\n'
+            if el == l or os.name == 'nt' and el[:-1] + '\r\n' == l:
+                return True
+            if el.endswith(" (re)\n"):
+                return rematch(el[:-6], l)
+            if el.endswith(" (glob)\n"):
+                return globmatch(el[:-8], l)
+            if os.altsep and l.replace('\\', '/') == el:
+                return '+glob'
+        return False
+
 wifexited = getattr(os, "WIFEXITED", lambda x: False)
 def run(cmd, wd, options, replacements, env):
     """Run command in a sub-process, capturing the output (stdout and stderr).
--- a/tests/test-run-tests.py	Sat Apr 19 15:37:50 2014 -0700
+++ b/tests/test-run-tests.py	Sat Apr 19 16:11:49 2014 -0700
@@ -29,7 +29,7 @@
     assert expected.endswith('\n') and output.endswith('\n'), 'missing newline'
     assert not re.search(r'[^ \w\\/\r\n()*?]', expected + output), \
            'single backslash or unknown char'
-    match = run_tests.linematch(expected, output)
+    match = run_tests.TTest.linematch(expected, output)
     if isinstance(match, str):
         return 'special: ' + match
     else: