浏览代码

[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
Julian Lettner 5 年之前
父节点
当前提交
3087d14c03
共有 3 个文件被更改,包括 17 次插入22 次删除
  1. 13 4
      utils/lit/lit/cl_arguments.py
  2. 1 11
      utils/lit/lit/main.py
  3. 3 7
      utils/lit/tests/selecting.py

+ 13 - 4
utils/lit/lit/cl_arguments.py

@@ -152,6 +152,7 @@ def parse_args():
             default=False)
             default=False)
     selection_group.add_argument("--filter",
     selection_group.add_argument("--filter",
             metavar="REGEX",
             metavar="REGEX",
+            type=_case_insensitive_regex,
             help="Only run tests with paths matching the given regular expression",
             help="Only run tests with paths matching the given regular expression",
             default=os.environ.get("LIT_FILTER"))
             default=os.environ.get("LIT_FILTER"))
     selection_group.add_argument("--num-shards",
     selection_group.add_argument("--num-shards",
@@ -201,14 +202,22 @@ def parse_args():
     return opts
     return opts
 
 
 def _positive_int(arg):
 def _positive_int(arg):
+    desc = "requires positive integer, but found '{}'"
     try:
     try:
         n = int(arg)
         n = int(arg)
     except ValueError:
     except ValueError:
-        raise _arg_error('positive integer', arg)
+        raise _error(desc, arg)
     if n <= 0:
     if n <= 0:
-        raise _arg_error('positive integer', arg)
+        raise _error(desc, arg)
     return n
     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)
     return argparse.ArgumentTypeError(msg)

+ 1 - 11
utils/lit/lit/main.py

@@ -10,7 +10,6 @@ from __future__ import absolute_import
 import os
 import os
 import platform
 import platform
 import random
 import random
-import re
 import sys
 import sys
 import time
 import time
 import tempfile
 import tempfile
@@ -115,7 +114,7 @@ def main_with_tmp(builtinParameters):
     numTotalTests = len(run.tests)
     numTotalTests = len(run.tests)
 
 
     if opts.filter:
     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)
     order_tests(run, opts)
 
 
@@ -277,15 +276,6 @@ def print_suites_or_tests(run, opts):
     # Exit.
     # Exit.
     sys.exit(0)
     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):
 def order_tests(run, opts):
     if opts.shuffle:
     if opts.shuffle:
         random.shuffle(run.tests)
         random.shuffle(run.tests)

+ 3 - 7
utils/lit/tests/selecting.py

@@ -1,17 +1,13 @@
 # RUN: %{lit} %{inputs}/discovery | FileCheck --check-prefix=CHECK-BASIC %s
 # RUN: %{lit} %{inputs}/discovery | FileCheck --check-prefix=CHECK-BASIC %s
 # CHECK-BASIC: Testing: 5 tests
 # 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: %{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-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
 # Check that maximum counts work
 #
 #
 # RUN: %{lit} --max-tests 3 %{inputs}/discovery | FileCheck --check-prefix=CHECK-MAX %s
 # RUN: %{lit} --max-tests 3 %{inputs}/discovery | FileCheck --check-prefix=CHECK-MAX %s