Patchwork run-tests: also follow symlink when update PATH with 'run-tests.py' dir

login
register
mail settings
Submitter Pierre-Yves David
Date April 11, 2015, 6:54 p.m.
Message ID <5df1cf6d7646bbab8aef.1428778440@marginatus.alto.octopoid.net>
Download mbox | patch
Permalink /patch/8620/
State Accepted
Commit 39ee0444e27c978f101b02c4ad68527e55de9d18
Headers show

Comments

Pierre-Yves David - April 11, 2015, 6:54 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@fb.com>
# Date 1428777852 14400
#      Sat Apr 11 14:44:12 2015 -0400
# Node ID 5df1cf6d7646bbab8aef9a5afdaac0c8645ab927
# Parent  52ff737c63d2b2cb41185549aa9c35bc47317032
run-tests: also follow symlink when update PATH with 'run-tests.py' dir

I'm using 'run-tests.py' from my '$PATH' and use a symlink to get 'run-tests.py'
to in that '$PATH'. There is a handful of test helpers (like f) that needs to be
in the '$PATH' for the test to run, and they are expected to live next to the
'run-tests.py' binary. Using a symlink confuses this logic, so we add to the
'$PATH' both the 'run-tests.py' executable directory, and the actual file
location direction.
Augie Fackler - April 11, 2015, 9:40 p.m.
On Sat, Apr 11, 2015 at 02:54:00PM -0400, Pierre-Yves David wrote:
> # HG changeset patch
> # User Pierre-Yves David <pierre-yves.david@fb.com>
> # Date 1428777852 14400
> #      Sat Apr 11 14:44:12 2015 -0400
> # Node ID 5df1cf6d7646bbab8aef9a5afdaac0c8645ab927
> # Parent  52ff737c63d2b2cb41185549aa9c35bc47317032
> run-tests: also follow symlink when update PATH with 'run-tests.py' dir

I'm +0 on this, I guess. It seems reasonable, but having run-tests in
a bin directory also seems pretty unusual to me.

>
> I'm using 'run-tests.py' from my '$PATH' and use a symlink to get 'run-tests.py'
> to in that '$PATH'. There is a handful of test helpers (like f) that needs to be
> in the '$PATH' for the test to run, and they are expected to live next to the
> 'run-tests.py' binary. Using a symlink confuses this logic, so we add to the
> '$PATH' both the 'run-tests.py' executable directory, and the actual file
> location direction.
>
> diff --git a/tests/run-tests.py b/tests/run-tests.py
> --- a/tests/run-tests.py
> +++ b/tests/run-tests.py
> @@ -1691,10 +1691,15 @@ class TestRunner(object):
>          os.environ["BINDIR"] = self._bindir
>          os.environ["PYTHON"] = PYTHON
>
>          runtestdir = os.path.abspath(os.path.dirname(__file__))
>          path = [self._bindir, runtestdir] + os.environ["PATH"].split(os.pathsep)
> +        if os.path.islink(__file__):
> +            # test helper will likely be at the end of the symlink
> +            realfile = os.path.realpath(__file__)
> +            realdir = os.path.abspath(os.path.dirname(realfile))
> +            path.insert(2, realdir)
>          if self._tmpbindir != self._bindir:
>              path = [self._tmpbindir] + path
>          os.environ["PATH"] = os.pathsep.join(path)
>
>          # Include TESTDIR in PYTHONPATH so that out-of-tree extensions
> _______________________________________________
> 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
@@ -1691,10 +1691,15 @@  class TestRunner(object):
         os.environ["BINDIR"] = self._bindir
         os.environ["PYTHON"] = PYTHON
 
         runtestdir = os.path.abspath(os.path.dirname(__file__))
         path = [self._bindir, runtestdir] + os.environ["PATH"].split(os.pathsep)
+        if os.path.islink(__file__):
+            # test helper will likely be at the end of the symlink
+            realfile = os.path.realpath(__file__)
+            realdir = os.path.abspath(os.path.dirname(realfile))
+            path.insert(2, realdir)
         if self._tmpbindir != self._bindir:
             path = [self._tmpbindir] + path
         os.environ["PATH"] = os.pathsep.join(path)
 
         # Include TESTDIR in PYTHONPATH so that out-of-tree extensions