@@ -724,32 +724,16 @@ def globmatch(el, l):
elif c == '?':
res += '.'
elif c == '/' and os.altsep:
res += '[/\\\\]'
else:
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."""
def _run(self, testtmp, replacements, env):
f = open(self._path)
lines = f.readlines()
f.close()
@@ -912,17 +896,17 @@ class TTest(Test):
if not lout.endswith('\n'):
lout += ' (no-eol)\n'
# Find the expected output at the current position.
el = None
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'
r = '' # Warn only this line.
elif r == '-glob':
lout = ''.join(el.rsplit(' (glob)', 1))
r = '' # Warn only this line.
else:
@@ -952,16 +936,33 @@ class TTest(Test):
if pos in after:
postout += after.pop(pos)
if warnonly == 2:
exitcode = False # Set exitcode to warned.
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).
Return a tuple (exitcode, output). output is None in debug mode."""
# TODO: Use subprocess.Popen if we're running on Python 2.4
if options.debug:
proc = subprocess.Popen(cmd, shell=True, cwd=wd, env=env)
ret = proc.wait()
@@ -24,17 +24,17 @@ def lm(expected, output):
missing newline
>>> try: lm('single backslash\n', 'single \backslash\n')
... except AssertionError, ex: print ex
single backslash or unknown char
"""
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:
return bool(match) # do not return match object
def wintests():
r"""test matching like running on windows