changeset 38222:507bdc40bb17

run-tests: add support for running specific test cases Differential Revision: https://phab.mercurial-scm.org/D3555
author Boris Feld <boris.feld@octobus.net>
date Thu, 26 Apr 2018 23:57:20 +0200
parents ee1f052b45ef
children b865bba56db1
files tests/run-tests.py tests/test-run-tests.t
diffstat 2 files changed, 87 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/tests/run-tests.py	Sun Jun 03 17:02:38 2018 +0530
+++ b/tests/run-tests.py	Thu Apr 26 23:57:20 2018 +0200
@@ -2646,16 +2646,31 @@
                 expanded_args.append(arg)
         args = expanded_args
 
+        testcasepattern = re.compile(r'([\w-]+\.t|py)( \(case ([\w-])+\))')
         tests = []
         for t in args:
+            case = None
+
             if not (os.path.basename(t).startswith(b'test-')
                     and (t.endswith(b'.py') or t.endswith(b'.t'))):
-                continue
+
+                m = testcasepattern.match(t)
+                if m is not None:
+                    t, _, case = m.groups()
+                else:
+                    continue
+
             if t.endswith(b'.t'):
                 # .t file may contain multiple test cases
                 cases = sorted(parsettestcases(t))
                 if cases:
-                    tests += [{'path': t, 'case': c} for c in sorted(cases)]
+                    if case is not None and case in cases:
+                        tests += [{'path': t, 'case': case}]
+                    elif case is not None and case not in cases:
+                        # Ignore invalid cases
+                        pass
+                    else:
+                        tests += [{'path': t, 'case': c} for c in sorted(cases)]
                 else:
                     tests.append({'path': t})
             else:
--- a/tests/test-run-tests.t	Sun Jun 03 17:02:38 2018 +0530
+++ b/tests/test-run-tests.t	Thu Apr 26 23:57:20 2018 +0200
@@ -1571,7 +1571,77 @@
   ..
   # Ran 2 tests, 0 skipped, 0 failed.
 
+Support running a specific test case
+
+  $ rt "test-cases-abc.t (case B)"
+  
+  --- $TESTTMP/anothertests/cases/test-cases-abc.t
+  +++ $TESTTMP/anothertests/cases/test-cases-abc.t.B.err
+  @@ -7,7 +7,7 @@
+     $ V=C
+   #endif
+     $ echo $V | sed 's/A/C/'
+  -  C
+  +  B
+   #if C
+     $ [ $V = C ]
+   #endif
+  
+  ERROR: test-cases-abc.t (case B) output changed
+  !
+  Failed test-cases-abc.t (case B): output changed
+  # Ran 1 tests, 0 skipped, 1 failed.
+  python hash seed: * (glob)
+  [1]
+
+Support running multiple test cases in the same file
+
+  $ rt "test-cases-abc.t (case B)" "test-cases-abc.t (case C)"
+  
+  --- $TESTTMP/anothertests/cases/test-cases-abc.t
+  +++ $TESTTMP/anothertests/cases/test-cases-abc.t.B.err
+  @@ -7,7 +7,7 @@
+     $ V=C
+   #endif
+     $ echo $V | sed 's/A/C/'
+  -  C
+  +  B
+   #if C
+     $ [ $V = C ]
+   #endif
+  
+  ERROR: test-cases-abc.t (case B) output changed
+  !.
+  Failed test-cases-abc.t (case B): output changed
+  # Ran 2 tests, 0 skipped, 1 failed.
+  python hash seed: * (glob)
+  [1]
+
+Support running invalid test cases
+
+  $ rt "test-cases-abc.t (case B)" "test-cases-abc.t (case D)"
+  
+  --- $TESTTMP/anothertests/cases/test-cases-abc.t
+  +++ $TESTTMP/anothertests/cases/test-cases-abc.t.B.err
+  @@ -7,7 +7,7 @@
+     $ V=C
+   #endif
+     $ echo $V | sed 's/A/C/'
+  -  C
+  +  B
+   #if C
+     $ [ $V = C ]
+   #endif
+  
+  ERROR: test-cases-abc.t (case B) output changed
+  !
+  Failed test-cases-abc.t (case B): output changed
+  # Ran 1 tests, 0 skipped, 1 failed.
+  python hash seed: * (glob)
+  [1]
+
 Test automatic pattern replacement
+==================================
 
   $ cat << EOF >> common-pattern.py
   > substitutions = [