[llvm] r374601 - [lit] Change regex filter to ignore case

Julian Lettner via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 11 14:57:06 PDT 2019


Author: yln
Date: Fri Oct 11 14:57:06 2019
New Revision: 374601

URL: http://llvm.org/viewvc/llvm-project?rev=374601&view=rev
Log:
[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

Modified:
    llvm/trunk/utils/lit/lit/cl_arguments.py
    llvm/trunk/utils/lit/lit/main.py
    llvm/trunk/utils/lit/tests/selecting.py

Modified: llvm/trunk/utils/lit/lit/cl_arguments.py
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/lit/lit/cl_arguments.py?rev=374601&r1=374600&r2=374601&view=diff
==============================================================================
--- llvm/trunk/utils/lit/lit/cl_arguments.py (original)
+++ llvm/trunk/utils/lit/lit/cl_arguments.py Fri Oct 11 14:57:06 2019
@@ -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)

Modified: llvm/trunk/utils/lit/lit/main.py
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/lit/lit/main.py?rev=374601&r1=374600&r2=374601&view=diff
==============================================================================
--- llvm/trunk/utils/lit/lit/main.py (original)
+++ llvm/trunk/utils/lit/lit/main.py Fri Oct 11 14:57:06 2019
@@ -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)

Modified: llvm/trunk/utils/lit/tests/selecting.py
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/lit/tests/selecting.py?rev=374601&r1=374600&r2=374601&view=diff
==============================================================================
--- llvm/trunk/utils/lit/tests/selecting.py (original)
+++ llvm/trunk/utils/lit/tests/selecting.py Fri Oct 11 14:57:06 2019
@@ -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




More information about the llvm-commits mailing list