From 3087d14c03f943e931405de988e16f412b9d2f9b Mon Sep 17 00:00:00 2001 From: Julian Lettner Date: Fri, 11 Oct 2019 21:57:06 +0000 Subject: [PATCH] [lit] Change regex filter to ignore case Make regex filter `--filter=REGEX` option more lenient via `re.IGNORECASE`. Reviewed By: yln Differential Revision: https://reviews.llvm.org/D68834 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@374601 91177308-0d34-0410-b5e6-96231b3b80d8 --- utils/lit/lit/cl_arguments.py | 17 +++++++++++++---- utils/lit/lit/main.py | 12 +----------- utils/lit/tests/selecting.py | 10 +++------- 3 files changed, 17 insertions(+), 22 deletions(-) diff --git a/utils/lit/lit/cl_arguments.py b/utils/lit/lit/cl_arguments.py index 29a4bfd522e..bf44a31513d 100644 --- a/utils/lit/lit/cl_arguments.py +++ b/utils/lit/lit/cl_arguments.py @@ -152,6 +152,7 @@ def parse_args(): 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 @@ def parse_args(): 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/utils/lit/lit/main.py b/utils/lit/lit/main.py index 52a8400bdcf..b0f851df7e6 100755 --- a/utils/lit/lit/main.py +++ b/utils/lit/lit/main.py @@ -10,7 +10,6 @@ from __future__ import absolute_import import os import platform import random -import re import sys import time import tempfile @@ -115,7 +114,7 @@ def main_with_tmp(builtinParameters): 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 @@ def print_suites_or_tests(run, opts): # 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/utils/lit/tests/selecting.py b/utils/lit/tests/selecting.py index 0d6fa938e4a..0921cdd31ac 100644 --- a/utils/lit/tests/selecting.py +++ b/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 -- 2.40.0