Patchwork run-tests: allow run-tests.py to run tests outside current directory

login
register
mail settings
Submitter David MacIver
Date Feb. 18, 2016, 8:57 a.m.
Message ID <d2b736d7b31c3d663eab.1455785831@laser-shark>
Download mbox | patch
Permalink /patch/13253/
State Accepted
Headers show

Comments

David MacIver - Feb. 18, 2016, 8:57 a.m.
# HG changeset patch
# User David R. MacIver <david@drmaciver.com>
# Date 1455785535 0
#      Thu Feb 18 08:52:15 2016 +0000
# Branch all
# Node ID d2b736d7b31c3d663eab7a5e993fab9d7c68d12f
# Parent  e7cab0207ae16a6f77b673c5d4e0f26d64d6a056
run-tests: allow run-tests.py to run tests outside current directory

When reloading tests, run-tests.py was assuming that it could look
up the test by the basename, which only works if you are running
tests which are in the current directory.

This patch changes that lookup to use the full path. This is all
that was needed, and does not appear to cause any problems for
any of the existing testing work flows based on running the
suggested commands at the top of run-tests.py.

Motivation: In order to test Mercurial with Hypothesis (according
to https://www.mercurial-scm.org/wiki/HypothesisPlan) it is
useful to be able to generate temporary test files and execute
them. Generating temporary files in the tests/ directory leads to
a lot of suboptimal clutter.
Augie Fackler - Feb. 22, 2016, 8:26 p.m.
On Thu, Feb 18, 2016 at 08:57:11AM +0000, David R. MacIver wrote:
> # HG changeset patch
> # User David R. MacIver <david@drmaciver.com>
> # Date 1455785535 0
> #      Thu Feb 18 08:52:15 2016 +0000
> # Branch all
> # Node ID d2b736d7b31c3d663eab7a5e993fab9d7c68d12f
> # Parent  e7cab0207ae16a6f77b673c5d4e0f26d64d6a056
> run-tests: allow run-tests.py to run tests outside current directory

queued this, thanks!

>
> When reloading tests, run-tests.py was assuming that it could look
> up the test by the basename, which only works if you are running
> tests which are in the current directory.
>
> This patch changes that lookup to use the full path. This is all
> that was needed, and does not appear to cause any problems for
> any of the existing testing work flows based on running the
> suggested commands at the top of run-tests.py.
>
> Motivation: In order to test Mercurial with Hypothesis (according
> to https://www.mercurial-scm.org/wiki/HypothesisPlan) it is
> useful to be able to generate temporary test files and execute
> them. Generating temporary files in the tests/ directory leads to
> a lot of suboptimal clutter.
>
> diff -r e7cab0207ae1 -r d2b736d7b31c tests/run-tests.py
> --- a/tests/run-tests.py	Wed Feb 17 17:21:14 2016 +0000
> +++ b/tests/run-tests.py	Thu Feb 18 08:52:15 2016 +0000
> @@ -1485,7 +1485,7 @@
>              def get():
>                  num_tests[0] += 1
>                  if getattr(test, 'should_reload', False):
> -                    return self._loadtest(test.bname, num_tests[0])
> +                    return self._loadtest(test.path, num_tests[0])
>                  return test
>              if not os.path.exists(test.path):
>                  result.addSkip(test, "Doesn't exist")
> diff -r e7cab0207ae1 -r d2b736d7b31c tests/test-run-tests.t
> --- a/tests/test-run-tests.t	Wed Feb 17 17:21:14 2016 +0000
> +++ b/tests/test-run-tests.t	Thu Feb 18 08:52:15 2016 +0000
> @@ -701,3 +701,14 @@
>    $ rt $HGTEST_RUN_TESTS_PURE --allow-slow-tests test-very-slow-test.t
>    .
>    # Ran 1 tests, 0 skipped, 0 warned, 0 failed.
> +
> +
> +support for running a test outside the current directory
> +  $ mkdir nonlocal
> +  $ cat > nonlocal/test-is-not-here.t << EOF
> +  >   $ echo pass
> +  >   pass
> +  > EOF
> +  $ rt nonlocal/test-is-not-here.t
> +  .
> +  # Ran 1 tests, 0 skipped, 0 warned, 0 failed.
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Patch

diff -r e7cab0207ae1 -r d2b736d7b31c tests/run-tests.py
--- a/tests/run-tests.py	Wed Feb 17 17:21:14 2016 +0000
+++ b/tests/run-tests.py	Thu Feb 18 08:52:15 2016 +0000
@@ -1485,7 +1485,7 @@ 
             def get():
                 num_tests[0] += 1
                 if getattr(test, 'should_reload', False):
-                    return self._loadtest(test.bname, num_tests[0])
+                    return self._loadtest(test.path, num_tests[0])
                 return test
             if not os.path.exists(test.path):
                 result.addSkip(test, "Doesn't exist")
diff -r e7cab0207ae1 -r d2b736d7b31c tests/test-run-tests.t
--- a/tests/test-run-tests.t	Wed Feb 17 17:21:14 2016 +0000
+++ b/tests/test-run-tests.t	Thu Feb 18 08:52:15 2016 +0000
@@ -701,3 +701,14 @@ 
   $ rt $HGTEST_RUN_TESTS_PURE --allow-slow-tests test-very-slow-test.t
   .
   # Ran 1 tests, 0 skipped, 0 warned, 0 failed.
+
+
+support for running a test outside the current directory
+  $ mkdir nonlocal
+  $ cat > nonlocal/test-is-not-here.t << EOF
+  >   $ echo pass
+  >   pass
+  > EOF
+  $ rt nonlocal/test-is-not-here.t
+  .
+  # Ran 1 tests, 0 skipped, 0 warned, 0 failed.