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

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

Comments

Gregory Szorc - May 2, 2014, 6:37 p.m.
# HG changeset patch
# User Gregory Szorc <gregory.szorc@gmail.com>
# Date 1397949270 25200
#      Sat Apr 19 16:14:30 2014 -0700
# Branch stable
# Node ID 95d37bc21eea1e2fe294cd5a181e28b194f7392c
# Parent  c36d1d52594ae225ed244da1668103fd4e139466
run-tests: make globmatch 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,42 +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 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
-    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 += '.'
-        elif c == '/' and os.altsep:
-            res += '[/\\\\]'
-        else:
-            res += re.escape(c)
-    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()
 
@@ -938,28 +912,55 @@  class TTest(Test):
             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 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
+        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 += '.'
+            elif c == '/' and os.altsep:
+                res += '[/\\\\]'
+            else:
+                res += re.escape(c)
+        return TTest.rematch(res, l)
+
+    @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 TTest.rematch(el[:-6], l)
             if el.endswith(" (glob)\n"):
-                return globmatch(el[:-8], l)
+                return TTest.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).
     Return a tuple (exitcode, output).  output is None in debug mode."""