Patchwork run-tests: allow automatic test discovery when providing folder as argument

login
register
mail settings
Submitter matthieu.laneuville@octobus.net
Date Nov. 2, 2017, 11:41 p.m.
Message ID <0e692e27fb01c6c06190.1509666095@carbon>
Download mbox | patch
Permalink /patch/25369/
State Superseded
Headers show

Comments

matthieu.laneuville@octobus.net - Nov. 2, 2017, 11:41 p.m.
# HG changeset patch
# User Matthieu Laneuville <matthieu.laneuville@octobus.net>
# Date 1508422437 -32400
#      Thu Oct 19 23:13:57 2017 +0900
# Node ID 0e692e27fb01c6c0619054ac4f32ce756071bf5a
# Parent  7ebf850d3166a64ff33b4b85adb481b533ddbf86
# EXP-Topic hg122
run-tests: allow automatic test discovery when providing folder as argument

Currently `run-tests.py` automatically discovers test only in the current
directory if no argument is provided. This patch makes it possible to pass a
number of tests and folders as arguments.
Yuya Nishihara - Nov. 3, 2017, 2:24 p.m.
On Fri, 03 Nov 2017 08:41:35 +0900, matthieu.laneuville@octobus.net wrote:
> # HG changeset patch
> # User Matthieu Laneuville <matthieu.laneuville@octobus.net>
> # Date 1508422437 -32400
> #      Thu Oct 19 23:13:57 2017 +0900
> # Node ID 0e692e27fb01c6c0619054ac4f32ce756071bf5a
> # Parent  7ebf850d3166a64ff33b4b85adb481b533ddbf86
> # EXP-Topic hg122
> run-tests: allow automatic test discovery when providing folder as argument
> 
> Currently `run-tests.py` automatically discovers test only in the current
> directory if no argument is provided. This patch makes it possible to pass a
> number of tests and folders as arguments.

Seems fine.

> diff -r 7ebf850d3166 -r 0e692e27fb01 tests/run-tests.py
> --- a/tests/run-tests.py	Sat Oct 21 16:50:57 2017 +0900
> +++ b/tests/run-tests.py	Thu Oct 19 23:13:57 2017 +0900
> @@ -2510,6 +2510,16 @@ class TestRunner(object):
>              else:
>                  args = os.listdir(b'.')
>  
> +        expanded_args = []
> +        for arg in args:
> +            if os.path.isdir(arg):
> +                if not arg.endswith('/'):
> +                    arg += '/'

b'/'

> +                expanded_args.extend([arg + a for a in os.listdir(arg)])
> +            else:
> +                expanded_args.append(arg)
> +        args = expanded_args
> +
>          tests = []
>          for t in args:

If we want to find test files recursively, os.walk() can be used. I don't
know whether it is a good idea, though.
matthieu.laneuville@octobus.net - Nov. 3, 2017, 10:52 p.m.
I sent a follow-up with with bytes issue corrected.

On Fri, Nov 03, 2017 at 11:24 PM, Yuya Nishihara wrote:
>On Fri, 03 Nov 2017 08:41:35 +0900, matthieu.laneuville@octobus.net wrote:
>> # HG changeset patch
>> # User Matthieu Laneuville <matthieu.laneuville@octobus.net>
>> # Date 1508422437 -32400
>> #      Thu Oct 19 23:13:57 2017 +0900
>> # Node ID 0e692e27fb01c6c0619054ac4f32ce756071bf5a
>> # Parent  7ebf850d3166a64ff33b4b85adb481b533ddbf86
>> # EXP-Topic hg122
>> run-tests: allow automatic test discovery when providing folder as argument
>>
>> Currently `run-tests.py` automatically discovers test only in the current
>> directory if no argument is provided. This patch makes it possible to pass a
>> number of tests and folders as arguments.
>
>Seems fine.
>
>> diff -r 7ebf850d3166 -r 0e692e27fb01 tests/run-tests.py
>> --- a/tests/run-tests.py	Sat Oct 21 16:50:57 2017 +0900
>> +++ b/tests/run-tests.py	Thu Oct 19 23:13:57 2017 +0900
>> @@ -2510,6 +2510,16 @@ class TestRunner(object):
>>              else:
>>                  args = os.listdir(b'.')
>>
>> +        expanded_args = []
>> +        for arg in args:
>> +            if os.path.isdir(arg):
>> +                if not arg.endswith('/'):
>> +                    arg += '/'
>
>b'/'
>
>> +                expanded_args.extend([arg + a for a in os.listdir(arg)])
>> +            else:
>> +                expanded_args.append(arg)
>> +        args = expanded_args
>> +
>>          tests = []
>>          for t in args:
>
>If we want to find test files recursively, os.walk() can be used. I don't
>know whether it is a good idea, though.

Patch

diff -r 7ebf850d3166 -r 0e692e27fb01 tests/run-tests.py
--- a/tests/run-tests.py	Sat Oct 21 16:50:57 2017 +0900
+++ b/tests/run-tests.py	Thu Oct 19 23:13:57 2017 +0900
@@ -2510,6 +2510,16 @@  class TestRunner(object):
             else:
                 args = os.listdir(b'.')
 
+        expanded_args = []
+        for arg in args:
+            if os.path.isdir(arg):
+                if not arg.endswith('/'):
+                    arg += '/'
+                expanded_args.extend([arg + a for a in os.listdir(arg)])
+            else:
+                expanded_args.append(arg)
+        args = expanded_args
+
         tests = []
         for t in args:
             if not (os.path.basename(t).startswith(b'test-')
diff -r 7ebf850d3166 -r 0e692e27fb01 tests/test-run-tests.t
--- a/tests/test-run-tests.t	Sat Oct 21 16:50:57 2017 +0900
+++ b/tests/test-run-tests.t	Thu Oct 19 23:13:57 2017 +0900
@@ -1261,6 +1261,23 @@  support for running a test outside the c
   .
   # Ran 1 tests, 0 skipped, 0 failed.
 
+support for automatically discovering test if arg is a folder
+  $ mkdir tmp && cd tmp
+
+  $ cat > test-uno.t << EOF
+  >   $ echo line
+  >   line
+  > EOF
+
+  $ cp test-uno.t test-dos.t
+  $ cd ..
+  $ cp -R tmp tmpp
+  $ cp tmp/test-uno.t test-solo.t
+
+  $ $PYTHON $TESTDIR/run-tests.py tmp/ test-solo.t tmpp
+  .....
+  # Ran 5 tests, 0 skipped, 0 failed.
+
 support for running run-tests.py from another directory
   $ mkdir tmp && cd tmp
   $ cat > useful-file.sh << EOF