diff --git a/llvm/utils/lit/lit/cl_arguments.py b/llvm/utils/lit/lit/cl_arguments.py --- a/llvm/utils/lit/lit/cl_arguments.py +++ b/llvm/utils/lit/lit/cl_arguments.py @@ -152,6 +152,7 @@ default=False) selection_group.add_argument("--filter", metavar="REGEX", + type=_case_insensitive_regex, help="Only run tests with paths matching the given regular expression", default=os.environ.get("LIT_FILTER")) selection_group.add_argument("--num-shards", @@ -201,14 +202,22 @@ return opts def _positive_int(arg): + desc = "requires positive integer, but found '{}'" try: n = int(arg) except ValueError: - raise _arg_error('positive integer', arg) + raise _error(desc, arg) if n <= 0: - raise _arg_error('positive integer', arg) + raise _error(desc, arg) return n -def _arg_error(desc, arg): - msg = "requires %s, but found '%s'" % (desc, arg) +def _case_insensitive_regex(arg): + import re + try: + return re.compile(arg, re.IGNORECASE) + except re.error as reason: + raise _error("invalid regular expression: '{}', {}", arg, reason) + +def _error(desc, *args): + msg = desc.format(*args) return argparse.ArgumentTypeError(msg) diff --git a/llvm/utils/lit/lit/main.py b/llvm/utils/lit/lit/main.py --- a/llvm/utils/lit/lit/main.py +++ b/llvm/utils/lit/lit/main.py @@ -10,7 +10,6 @@ import os import platform import random -import re import sys import time import tempfile @@ -115,7 +114,7 @@ numTotalTests = len(run.tests) if opts.filter: - filter_tests(run, opts) + run.tests = [t for t in run.tests if opts.filter.search(t.getFullName())] order_tests(run, opts) @@ -277,15 +276,6 @@ # Exit. sys.exit(0) -def filter_tests(run, opts): - try: - rex = re.compile(opts.filter) - except: - parser.error("invalid regular expression for --filter: %r" % ( - opts.filter)) - run.tests = [result_test for result_test in run.tests - if rex.search(result_test.getFullName())] - def order_tests(run, opts): if opts.shuffle: random.shuffle(run.tests) diff --git a/llvm/utils/lit/tests/selecting.py b/llvm/utils/lit/tests/selecting.py --- a/llvm/utils/lit/tests/selecting.py +++ b/llvm/utils/lit/tests/selecting.py @@ -1,17 +1,13 @@ # RUN: %{lit} %{inputs}/discovery | FileCheck --check-prefix=CHECK-BASIC %s # CHECK-BASIC: Testing: 5 tests -# Check that regex-filtering works +# Check that regex-filtering works, is case-insensitive, and can be configured via env var. # # RUN: %{lit} --filter 'o[a-z]e' %{inputs}/discovery | FileCheck --check-prefix=CHECK-FILTER %s +# RUN: %{lit} --filter 'O[A-Z]E' %{inputs}/discovery | FileCheck --check-prefix=CHECK-FILTER %s +# RUN: env LIT_FILTER='o[a-z]e' %{lit} %{inputs}/discovery | FileCheck --check-prefix=CHECK-FILTER %s # CHECK-FILTER: Testing: 2 of 5 tests -# Check that regex-filtering based on environment variables work. -# -# RUN: env LIT_FILTER='o[a-z]e' %{lit} %{inputs}/discovery | FileCheck --check-prefix=CHECK-FILTER-ENV %s -# CHECK-FILTER-ENV: Testing: 2 of 5 tests - - # Check that maximum counts work # # RUN: %{lit} --max-tests 3 %{inputs}/discovery | FileCheck --check-prefix=CHECK-MAX %s