##// END OF EJS Templates
run-tests: move string escaping to TTest...
Gregory Szorc -
r21384:a36cc85a default
parent child Browse files
Show More
@@ -618,21 +618,16 b' class PythonTest(Test):'
618 618 return run(cmd, testtmp, self._options, replacements, env,
619 619 self._runner.abort)
620 620
621
622 needescape = re.compile(r'[\x00-\x08\x0b-\x1f\x7f-\xff]').search
623 escapesub = re.compile(r'[\x00-\x08\x0b-\x1f\\\x7f-\xff]').sub
624 escapemap = dict((chr(i), r'\x%02x' % i) for i in range(256))
625 escapemap.update({'\\': '\\\\', '\r': r'\r'})
626 def escapef(m):
627 return escapemap[m.group(0)]
628 def stringescape(s):
629 return escapesub(escapef, s)
630
631 621 class TTest(Test):
632 622 """A "t test" is a test backed by a .t file."""
633 623
634 624 SKIPPED_PREFIX = 'skipped: '
635 625 FAILED_PREFIX = 'hghave check failed: '
626 NEEDESCAPE = re.compile(r'[\x00-\x08\x0b-\x1f\x7f-\xff]').search
627
628 ESCAPESUB = re.compile(r'[\x00-\x08\x0b-\x1f\\\x7f-\xff]').sub
629 ESCAPEMAP = dict((chr(i), r'\x%02x' % i) for i in range(256)).update(
630 {'\\': '\\\\', '\r': r'\r'})
636 631
637 632 def _run(self, testtmp, replacements, env):
638 633 f = open(self._path)
@@ -818,8 +813,9 b' class TTest(Test):'
818 813 if r:
819 814 postout.append(' ' + el)
820 815 else:
821 if needescape(lout):
822 lout = stringescape(lout.rstrip('\n')) + ' (esc)\n'
816 if self.NEEDESCAPE(lout):
817 lout = TTest.stringescape('%s (esc)\n' %
818 lout.rstrip('\n'))
823 819 postout.append(' ' + lout) # Let diff deal with it.
824 820 if r != '': # If line failed.
825 821 warnonly = 3 # for sure not
@@ -918,6 +914,15 b' class TTest(Test):'
918 914
919 915 return missing, failed
920 916
917 @staticmethod
918 def _escapef(m):
919 return TTest.ESCAPEMAP[m.group(0)]
920
921 @staticmethod
922 def _stringescape(s):
923 return TTest.ESCAPESUB(TTest._escapef, s)
924
925
921 926 wifexited = getattr(os, "WIFEXITED", lambda x: False)
922 927 def run(cmd, wd, options, replacements, env, abort):
923 928 """Run command in a sub-process, capturing the output (stdout and stderr).
General Comments 0
You need to be logged in to leave comments. Login now