run-tests: separate newline normalization from replacements
authorGregory Szorc <gregory.szorc@gmail.com>
Sat, 28 Mar 2015 14:28:22 -0700
changeset 24510 8d6fd0b8f622
parent 24509 27092bb70293
child 24511 0ecc1e42ff3f
run-tests: separate newline normalization from replacements Upcoming patches will change how the replacements system works to make it more flexible. To prepare for this, eliminate the one-off use of replacements to perform newline normalization on Windows.
tests/run-tests.py
--- a/tests/run-tests.py	Sat Mar 28 14:12:57 2015 -0700
+++ b/tests/run-tests.py	Sat Mar 28 14:28:22 2015 -0700
@@ -722,7 +722,7 @@
         # Failed is denoted by AssertionError (by default at least).
         raise AssertionError(msg)
 
-    def _runcommand(self, cmd, replacements, env):
+    def _runcommand(self, cmd, replacements, env, normalizenewlines=False):
         """Run command in a sub-process, capturing the output (stdout and
         stderr).
 
@@ -765,6 +765,10 @@
 
         for s, r in replacements:
             output = re.sub(s, r, output)
+
+        if normalizenewlines:
+            output = output.replace('\r\n', '\n')
+
         return ret, output.splitlines(True)
 
 class PythonTest(Test):
@@ -778,9 +782,9 @@
         py3kswitch = self._py3kwarnings and ' -3' or ''
         cmd = '%s%s "%s"' % (PYTHON, py3kswitch, self.path)
         vlog("# Running", cmd)
-        if os.name == 'nt':
-            replacements.append((r'\r\n', '\n'))
-        result = self._runcommand(cmd, replacements, env)
+        normalizenewlines = os.name == 'nt'
+        result = self._runcommand(cmd, replacements, env,
+                                  normalizenewlines=normalizenewlines)
         if self._aborted:
             raise KeyboardInterrupt()