diff --git a/tests/run-tests.py b/tests/run-tests.py --- a/tests/run-tests.py +++ b/tests/run-tests.py @@ -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: 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 @@ -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 = [