changeset 40947:fcdff048a8e5

py3: teach run-tests.py to handle exe with spaces when --local isn't specified This was the reason that no amount of quoting worked in test-hghave.t. `os.popen()` needed to be swapped out because while the added quoting around line 3124 worked on py3, it failed on py2. See 38d51371792b. The problem with `os.system()` was wrongly splitting the command on the space in 'Program Files', regardless of quoting. It looks like there are a few other instances of `os.system()` in core code, so presumably those should be replaced?
author Matt Harbison <matt_harbison@yahoo.com>
date Thu, 13 Dec 2018 00:18:47 -0500
parents 43ca24b772d6
children e54bfde922f2
files tests/run-tests.py
diffstat 1 files changed, 8 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/tests/run-tests.py	Tue Dec 11 17:13:17 2018 +0100
+++ b/tests/run-tests.py	Thu Dec 13 00:18:47 2018 -0500
@@ -3019,7 +3019,7 @@
             # least on Windows for now, deal with .pydistutils.cfg bugs
             # when they happen.
             nohome = b''
-        cmd = (b'%(exe)s setup.py %(pure)s clean --all'
+        cmd = (b'"%(exe)s" setup.py %(pure)s clean --all'
                b' build %(compiler)s --build-base="%(base)s"'
                b' install --force --prefix="%(prefix)s"'
                b' --install-lib="%(libdir)s"'
@@ -3042,7 +3042,7 @@
         makedirs(self._bindir)
 
         vlog("# Running", cmd)
-        if os.system(_strpath(cmd)) == 0:
+        if subprocess.call(_strpath(cmd), shell=True) == 0:
             if not self.options.verbose:
                 try:
                     os.remove(installerrs)
@@ -3121,15 +3121,15 @@
         if self._hgpath is not None:
             return self._hgpath
 
-        cmd = b'%s -c "import mercurial; print (mercurial.__path__[0])"'
+        cmd = b'"%s" -c "import mercurial; print (mercurial.__path__[0])"'
         cmd = cmd % PYTHON
         if PYTHON3:
             cmd = _strpath(cmd)
-        pipe = os.popen(cmd)
-        try:
-            self._hgpath = _bytespath(pipe.read().strip())
-        finally:
-            pipe.close()
+
+        p = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True)
+        out, err = p.communicate()
+
+        self._hgpath = out.strip()
 
         return self._hgpath