Comments
Patch
@@ -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."""