Patchwork run-tests: $TESTDIR can be something else than $PWD

login
register
mail settings
Submitter matthieu.laneuville@octobus.net
Date Nov. 2, 2017, 1:37 p.m.
Message ID <c4cc170d65e2dbcb075d.1509629865@carbon>
Download mbox | patch
Permalink /patch/25349/
State Accepted
Headers show

Comments

matthieu.laneuville@octobus.net - Nov. 2, 2017, 1:37 p.m.
# HG changeset patch
# User Matthieu Laneuville <matthieu.laneuville@octobus.net>
# Date 1501648065 -32400
#      Wed Aug 02 13:27:45 2017 +0900
# Node ID c4cc170d65e2dbcb075d09c26f5884aa8c0ceb31
# Parent  3ce0e4b51f789eff195ec900a07c1fa5e8d5c5f2
# EXP-Topic hg122
run-tests: $TESTDIR can be something else than $PWD

$TESTDIR is expected to be the directory were the test lives, and is often used
to reference helper functions. However, it is now set to $PWD at test invocation
time, so if `run-tests.py` is called from another folder, the test will fail.

The solution is to force $TESTDIR to be the base directory of the test itself,
irrespective of where the runner is called from.
Augie Fackler - Nov. 2, 2017, 2:01 p.m.
queued, sure

> On Nov 2, 2017, at 09:37, matthieu.laneuville@octobus.net wrote:
> 
> # HG changeset patch
> # User Matthieu Laneuville <matthieu.laneuville@octobus.net>
> # Date 1501648065 -32400
> #      Wed Aug 02 13:27:45 2017 +0900
> # Node ID c4cc170d65e2dbcb075d09c26f5884aa8c0ceb31
> # Parent  3ce0e4b51f789eff195ec900a07c1fa5e8d5c5f2
> # EXP-Topic hg122
> run-tests: $TESTDIR can be something else than $PWD
> 
> $TESTDIR is expected to be the directory were the test lives, and is often used
> to reference helper functions. However, it is now set to $PWD at test invocation
> time, so if `run-tests.py` is called from another folder, the test will fail.
> 
> The solution is to force $TESTDIR to be the base directory of the test itself,
> irrespective of where the runner is called from.
> 
> diff -r 3ce0e4b51f78 -r c4cc170d65e2 tests/run-tests.py
> --- a/tests/run-tests.py	Wed Nov 01 17:19:45 2017 -0500
> +++ b/tests/run-tests.py	Wed Aug 02 13:27:45 2017 +0900
> @@ -2353,6 +2353,12 @@ class TestRunner(object):
> 
>         self._testdir = osenvironb[b'TESTDIR'] = getattr(
>             os, 'getcwdb', os.getcwd)()
> +        # assume all tests in same folder for now
> +        if testdescs:
> +            pathname = os.path.dirname(testdescs[0]['path'])
> +            if pathname and not osenvironb[b'TESTDIR'].endswith('/'):
> +                osenvironb[b'TESTDIR'] += '/'
> +            osenvironb[b'TESTDIR'] += pathname
>         if self.options.outputdir:
>             self._outputdir = canonpath(_bytespath(self.options.outputdir))
>         else:
> diff -r 3ce0e4b51f78 -r c4cc170d65e2 tests/test-run-tests.t
> --- a/tests/test-run-tests.t	Wed Nov 01 17:19:45 2017 -0500
> +++ b/tests/test-run-tests.t	Wed Aug 02 13:27:45 2017 +0900
> @@ -1261,6 +1261,22 @@ support for running a test outside the c
>   .
>   # Ran 1 tests, 0 skipped, 0 failed.
> 
> +support for running run-tests.py from another directory
> +  $ mkdir tmp && cd tmp
> +  $ cat > useful-file.sh << EOF
> +  > important command
> +  > EOF
> +
> +  $ cat > test-folder.t << EOF
> +  >   $ cat \$TESTDIR/useful-file.sh
> +  >   important command
> +  > EOF
> +
> +  $ cd ..
> +  $ $PYTHON $TESTDIR/run-tests.py tmp/test-folder.t
> +  .
> +  # Ran 1 tests, 0 skipped, 0 failed.
> +
> support for bisecting failed tests automatically
>   $ hg init bisect
>   $ cd bisect
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
Yuya Nishihara - Nov. 3, 2017, 2:09 a.m.
On Thu, 02 Nov 2017 22:37:45 +0900, matthieu.laneuville@octobus.net wrote:
> # HG changeset patch
> # User Matthieu Laneuville <matthieu.laneuville@octobus.net>
> # Date 1501648065 -32400
> #      Wed Aug 02 13:27:45 2017 +0900
> # Node ID c4cc170d65e2dbcb075d09c26f5884aa8c0ceb31
> # Parent  3ce0e4b51f789eff195ec900a07c1fa5e8d5c5f2
> # EXP-Topic hg122
> run-tests: $TESTDIR can be something else than $PWD
> 
> $TESTDIR is expected to be the directory were the test lives, and is often used
> to reference helper functions. However, it is now set to $PWD at test invocation
> time, so if `run-tests.py` is called from another folder, the test will fail.
> 
> The solution is to force $TESTDIR to be the base directory of the test itself,
> irrespective of where the runner is called from.
> 
> diff -r 3ce0e4b51f78 -r c4cc170d65e2 tests/run-tests.py
> --- a/tests/run-tests.py	Wed Nov 01 17:19:45 2017 -0500
> +++ b/tests/run-tests.py	Wed Aug 02 13:27:45 2017 +0900
> @@ -2353,6 +2353,12 @@ class TestRunner(object):
>  
>          self._testdir = osenvironb[b'TESTDIR'] = getattr(
>              os, 'getcwdb', os.getcwd)()
> +        # assume all tests in same folder for now
> +        if testdescs:
> +            pathname = os.path.dirname(testdescs[0]['path'])
> +            if pathname and not osenvironb[b'TESTDIR'].endswith('/'):
> +                osenvironb[b'TESTDIR'] += '/'

Not work on Python 3 because of u'/' vs b'/' issue. Can you send a follow up?

Patch

diff -r 3ce0e4b51f78 -r c4cc170d65e2 tests/run-tests.py
--- a/tests/run-tests.py	Wed Nov 01 17:19:45 2017 -0500
+++ b/tests/run-tests.py	Wed Aug 02 13:27:45 2017 +0900
@@ -2353,6 +2353,12 @@  class TestRunner(object):
 
         self._testdir = osenvironb[b'TESTDIR'] = getattr(
             os, 'getcwdb', os.getcwd)()
+        # assume all tests in same folder for now
+        if testdescs:
+            pathname = os.path.dirname(testdescs[0]['path'])
+            if pathname and not osenvironb[b'TESTDIR'].endswith('/'):
+                osenvironb[b'TESTDIR'] += '/'
+            osenvironb[b'TESTDIR'] += pathname
         if self.options.outputdir:
             self._outputdir = canonpath(_bytespath(self.options.outputdir))
         else:
diff -r 3ce0e4b51f78 -r c4cc170d65e2 tests/test-run-tests.t
--- a/tests/test-run-tests.t	Wed Nov 01 17:19:45 2017 -0500
+++ b/tests/test-run-tests.t	Wed Aug 02 13:27:45 2017 +0900
@@ -1261,6 +1261,22 @@  support for running a test outside the c
   .
   # Ran 1 tests, 0 skipped, 0 failed.
 
+support for running run-tests.py from another directory
+  $ mkdir tmp && cd tmp
+  $ cat > useful-file.sh << EOF
+  > important command
+  > EOF
+
+  $ cat > test-folder.t << EOF
+  >   $ cat \$TESTDIR/useful-file.sh
+  >   important command
+  > EOF
+
+  $ cd ..
+  $ $PYTHON $TESTDIR/run-tests.py tmp/test-folder.t
+  .
+  # Ran 1 tests, 0 skipped, 0 failed.
+
 support for bisecting failed tests automatically
   $ hg init bisect
   $ cd bisect