[PATCH 3 of 5] run-tests.py: add TESTDIR to PATH if it differs from RUNTESTDIR

FUJIWARA Katsunori foozy at lares.dti.ne.jp
Thu Jul 2 17:01:06 CDT 2015


# HG changeset patch
# User FUJIWARA Katsunori <foozy at lares.dti.ne.jp>
# Date 1435874163 -32400
#      Fri Jul 03 06:56:03 2015 +0900
# Node ID 2b5d5f90cf4e961bfb83424d948be6596d565595
# Parent  a720921385130b6278436bf84842310b0ad15b8d
run-tests.py: add TESTDIR to PATH if it differs from RUNTESTDIR

Before this patch, `RUNTESTDIR` is added to `PATH`, but `TESTDIR`
isn't.

This doesn't cause any problems, if `run-tests.py` runs in `tests`
directory of Mercurial source tree. In this case, `RUNTESTDIR` should
be equal to `TESTDIR`.

On the other hand, if `run-tests.py` runs in `tests` of third party
tools, commands in that directory should be executed with explicit
`$TESTDIR/` prefix in `*.t` test scripts. This isn't suitable for the
policy "drop explicit $TESTDIR from executables" of Mercurial itself
(see 4d2b9b304ad0).

BTW, 4d2b9b304ad0 describes that "$TESTDIR is added to the path" even
though `TESTDIR` isn't added to `PATH` exactly speaking, because
`TESTDIR` and `RUNTESTDIR` weren't yet distinguished from each other
at that time.

This is a one of preparations for issue4677.

diff --git a/tests/run-tests.py b/tests/run-tests.py
--- a/tests/run-tests.py
+++ b/tests/run-tests.py
@@ -1812,6 +1812,8 @@
             realfile = os.path.realpath(fileb)
             realdir = os.path.abspath(os.path.dirname(realfile))
             path.insert(2, realdir)
+        if self._testdir != runtestdir:
+            path = [self._testdir] + path
         if self._tmpbindir != self._bindir:
             path = [self._tmpbindir] + path
         osenvironb[b"PATH"] = sepb.join(path)
diff --git a/tests/test-run-tests.t b/tests/test-run-tests.t
--- a/tests/test-run-tests.t
+++ b/tests/test-run-tests.t
@@ -602,3 +602,22 @@
   $ run-tests.py test-runtestdir.t
   .
   # Ran 1 tests, 0 skipped, 0 warned, 0 failed.
+
+#if execbit
+
+test that TESTDIR is referred in PATH
+
+  $ cat > custom-command.sh <<EOF
+  > #!/bin/sh
+  > echo "hello world"
+  > EOF
+  $ chmod +x custom-command.sh
+  $ cat > test-testdir-path.t <<EOF
+  >   $ custom-command.sh
+  >   hello world
+  > EOF
+  $ run-tests.py test-testdir-path.t
+  .
+  # Ran 1 tests, 0 skipped, 0 warned, 0 failed.
+
+#endif


More information about the Mercurial-devel mailing list