[PATCH 2 of 5] run-tests.py: add RUNTESTDIR to refer `tests` of Mercurial

FUJIWARA Katsunori foozy at lares.dti.ne.jp
Thu Jul 2 17:01:05 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 a720921385130b6278436bf84842310b0ad15b8d
# Parent  4e720dd1ec4ec6edf7f9770360ec9471bd4b862f
run-tests.py: add RUNTESTDIR to refer `tests` of Mercurial

Before this patch, there is no way to refer files under `tests` or so
of Mercurial source tree, when `run-tests.py` runs in `tests` of third
party tools. In this case, `TESTDIR` refers the latter `tests`.

This prevents third party tools from using useful tools in Mercurial
source tree (e.g. `contrib/check-code.py`).

This patch adds `RUNTESTDIR` environment variable to refer `tests` of
Mercurial source tree, in which `run-tests.py` now running is
placed. For example, tests of third party tools can refer
`contrib/check-code.py` in Mercurial source tree as
`$RUNTESTDIR/../contrib/check-code.py`.

BTW, for similarity with `TESTDIR` referring `test*s*` directory,
newly added environment variable isn't named as `RUNTEST*S*DIR`. In
addition to it, the corresponded local variable is also named as
`runtestdir`.

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
@@ -1801,6 +1801,7 @@
 
         fileb = _bytespath(__file__)
         runtestdir = os.path.abspath(os.path.dirname(fileb))
+        osenvironb[b'RUNTESTDIR'] = runtestdir
         if PYTHON3:
             sepb = _bytespath(os.pathsep)
         else:
@@ -1835,6 +1836,7 @@
         self._coveragefile = os.path.join(self._testdir, b'.coverage')
 
         vlog("# Using TESTDIR", self._testdir)
+        vlog("# Using RUNTESTDIR", osenvironb[b'RUNTESTDIR'])
         vlog("# Using HGTMP", self._hgtmp)
         vlog("# Using PATH", os.environ["PATH"])
         vlog("# Using", IMPL_PATH, osenvironb[IMPL_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
@@ -583,3 +583,22 @@
   $ run-tests.py test-hghave.t
   .
   # Ran 1 tests, 0 skipped, 0 warned, 0 failed.
+
+test that RUNTESTDIR refers the directory, in which `run-tests.py` now
+running is placed.
+
+  $ cat > test-runtestdir.t <<EOF
+  > - $TESTDIR, in which test-run-tests.t is placed
+  > - \$TESTDIR, in which test-runtestdir.t is placed (expanded at runtime)
+  > - \$RUNTESTDIR, in which run-tests.py is placed (expanded at runtime)
+  > 
+  >   $ test "\$TESTDIR" = "$TESTTMP"/anothertests
+  >   $ test "\$RUNTESTDIR" = "$TESTDIR"
+  >   $ head -n 3 "\$RUNTESTDIR"/../contrib/check-code.py
+  >   #!/usr/bin/env python
+  >   #
+  >   # check-code - a style and portability checker for Mercurial
+  > EOF
+  $ run-tests.py test-runtestdir.t
+  .
+  # Ran 1 tests, 0 skipped, 0 warned, 0 failed.


More information about the Mercurial-devel mailing list