Patchwork [021,of,179,tests-refactor] run-tests: make rematch a static method of TTest

login
register
mail settings
Submitter Gregory Szorc
Date May 2, 2014, 6:37 p.m.
Message ID <c36d1d52594ae225ed24.1399055858@vm-ubuntu-main.gateway.sonic.net>
Download mbox | patch
Permalink /patch/4516/
State Accepted
Commit ab9bf8a5e57312c5feb117506178588add5fe868
Headers show

Comments

Gregory Szorc - May 2, 2014, 6:37 p.m.
# HG changeset patch
# User Gregory Szorc <gregory.szorc@gmail.com>
# Date 1397949182 25200
#      Sat Apr 19 16:13:02 2014 -0700
# Branch stable
# Node ID c36d1d52594ae225ed244da1668103fd4e139466
# Parent  2ccbf07cec1272ca459f84810323c28e53044745
run-tests: make rematch a static method of TTest

Patch

diff --git a/tests/run-tests.py b/tests/run-tests.py
--- a/tests/run-tests.py
+++ b/tests/run-tests.py
@@ -688,26 +688,16 @@  needescape = re.compile(r'[\x00-\x08\x0b
 escapesub = re.compile(r'[\x00-\x08\x0b-\x1f\\\x7f-\xff]').sub
 escapemap = dict((chr(i), r'\x%02x' % i) for i in range(256))
 escapemap.update({'\\': '\\\\', '\r': r'\r'})
 def escapef(m):
     return escapemap[m.group(0)]
 def stringescape(s):
     return escapesub(escapef, s)
 
-def rematch(el, l):
-    try:
-        # use \Z to ensure that the regex matches to the end of the string
-        if os.name == 'nt':
-            return re.match(el + r'\r?\n\Z', l)
-        return re.match(el + r'\n\Z', l)
-    except re.error:
-        # el is an invalid regex
-        return False
-
 def globmatch(el, l):
     # The only supported special characters are * and ? plus / which also
     # matches \ on windows. Escaping of these characters is supported.
     if el + '\n' == l:
         if os.altsep:
             # matching on "/" is not needed for this line
             return '-glob'
         return True
@@ -722,17 +712,17 @@  def globmatch(el, l):
         elif c == '*':
             res += '.*'
         elif c == '?':
             res += '.'
         elif c == '/' and os.altsep:
             res += '[/\\\\]'
         else:
             res += re.escape(c)
-    return rematch(res, l)
+    return TTest.rematch(res, l)
 
 class TTest(Test):
     """A "t test" is a test backed by a .t file."""
 
     def _run(self, testtmp, replacements, env):
         f = open(self._path)
         lines = f.readlines()
         f.close()
@@ -937,26 +927,37 @@  class TTest(Test):
             postout += after.pop(pos)
 
         if warnonly == 2:
             exitcode = False # Set exitcode to warned.
 
         return exitcode, postout
 
     @staticmethod
+    def rematch(el, l):
+        try:
+            # use \Z to ensure that the regex matches to the end of the string
+            if os.name == 'nt':
+                return re.match(el + r'\r?\n\Z', l)
+            return re.match(el + r'\n\Z', l)
+        except re.error:
+            # el is an invalid regex
+            return False
+
+    @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)
+                return TTest.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):