Patchwork [4,of,6] run-tests: separate newline normalization from replacements

login
register
mail settings
Submitter Gregory Szorc
Date March 29, 2015, 3:15 a.m.
Message ID <ef971bec3244987328d2.1427598909@vm-ubuntu-main.gateway.sonic.net>
Download mbox | patch
Permalink /patch/8339/
State Accepted
Headers show

Comments

Gregory Szorc - March 29, 2015, 3:15 a.m.
# HG changeset patch
# User Gregory Szorc <gregory.szorc@gmail.com>
# Date 1427578102 25200
#      Sat Mar 28 14:28:22 2015 -0700
# Node ID ef971bec3244987328d272ee93e81a691509d63a
# Parent  37fb7d70143047327da622428f8f79d9e690e590
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.
Augie Fackler - March 30, 2015, 2:58 p.m.
On Sat, Mar 28, 2015 at 08:15:09PM -0700, Gregory Szorc wrote:
> # HG changeset patch
> # User Gregory Szorc <gregory.szorc@gmail.com>
> # Date 1427578102 25200
> #      Sat Mar 28 14:28:22 2015 -0700
> # Node ID ef971bec3244987328d272ee93e81a691509d63a
> # Parent  37fb7d70143047327da622428f8f79d9e690e590
> run-tests: separate newline normalization from replacements

I've queued 1-4. I have a meeting now, so I'll look at 5 and 6 later.

>
> 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.
>
> diff --git a/tests/run-tests.py b/tests/run-tests.py
> --- a/tests/run-tests.py
> +++ b/tests/run-tests.py
> @@ -721,9 +721,9 @@ class Test(unittest.TestCase):
>          # unittest differentiates between errored and failed.
>          # 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).
>
>          Return a tuple (exitcode, output). output is None in debug mode.
> @@ -764,8 +764,12 @@ class Test(unittest.TestCase):
>              killdaemons(env['DAEMON_PIDS'])
>
>          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):
>      """A Python-based test."""
> @@ -777,11 +781,11 @@ class PythonTest(Test):
>      def _run(self, replacements, env):
>          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()
>
>          return result
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel

Patch

diff --git a/tests/run-tests.py b/tests/run-tests.py
--- a/tests/run-tests.py
+++ b/tests/run-tests.py
@@ -721,9 +721,9 @@  class Test(unittest.TestCase):
         # unittest differentiates between errored and failed.
         # 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).
 
         Return a tuple (exitcode, output). output is None in debug mode.
@@ -764,8 +764,12 @@  class Test(unittest.TestCase):
             killdaemons(env['DAEMON_PIDS'])
 
         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):
     """A Python-based test."""
@@ -777,11 +781,11 @@  class PythonTest(Test):
     def _run(self, replacements, env):
         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()
 
         return result