[Lldb-commits] [lldb] [lldb] Make duplicate test names a conditional exception (PR #137681)
Dave Lee via lldb-commits
lldb-commits at lists.llvm.org
Mon Apr 28 11:18:34 PDT 2025
https://github.com/kastiglione updated https://github.com/llvm/llvm-project/pull/137681
>From bbf439758fd2b98389c6df81dd9bede24c59a029 Mon Sep 17 00:00:00 2001
From: Dave Lee <davelee.com at gmail.com>
Date: Mon, 28 Apr 2025 10:55:55 -0700
Subject: [PATCH 1/2] [lldb] Make duplicate test names a conditional exception
When two or more tests have the same name, dotest will raise an exception. However, when
using a test name pattern (`-p`) which does not match the duplicate test names, there
seems to be no reason to prevent the user from running they wish to run.
This changes the exception to be raised only when a pattern matches duplicate tests.
---
lldb/packages/Python/lldbsuite/test/dotest.py | 37 +++++++++----------
1 file changed, 18 insertions(+), 19 deletions(-)
diff --git a/lldb/packages/Python/lldbsuite/test/dotest.py b/lldb/packages/Python/lldbsuite/test/dotest.py
index 7cc8f2985043e..e9b5985e03c11 100644
--- a/lldb/packages/Python/lldbsuite/test/dotest.py
+++ b/lldb/packages/Python/lldbsuite/test/dotest.py
@@ -619,12 +619,12 @@ def visit_file(dir, name):
if configuration.regexp:
if not re.search(configuration.regexp, name):
# We didn't match the regex, we're done.
- return
+ return False
if configuration.skip_tests:
for file_regexp in configuration.skip_tests:
if re.search(file_regexp, name):
- return
+ return False
# We found a match for our test. Add it to the suite.
@@ -659,22 +659,20 @@ def iter_filters():
if check(value, parts):
yield key + "." + filterspec
- filtered = False
- for filterspec in iter_filters():
- filtered = True
- print("adding filter spec %s to module %s" % (filterspec, repr(module)))
- tests = unittest.defaultTestLoader.loadTestsFromName(filterspec, module)
- configuration.suite.addTests(tests)
-
- # Forgo this module if the (base, filterspec) combo is invalid
- if configuration.filters and not filtered:
- return
+ if configuration.filters:
+ filtered = False
+ for filterspec in iter_filters():
+ filtered = True
+ print(f"adding filter spec {filterspec} to module {module!r}")
+ tests = unittest.defaultTestLoader.loadTestsFromName(filterspec, module)
+ configuration.suite.addTests(tests)
+ return filtered
- if not filtered:
- # Add the entire file's worth of tests since we're not filtered.
- # Also the fail-over case when the filterspec branch
- # (base, filterspec) combo doesn't make sense.
- configuration.suite.addTests(unittest.defaultTestLoader.loadTestsFromName(base))
+ # Add the entire file's worth of tests since we're not filtered.
+ # Also the fail-over case when the filterspec branch
+ # (base, filterspec) combo doesn't make sense.
+ configuration.suite.addTests(unittest.defaultTestLoader.loadTestsFromName(base))
+ return True
def visit(prefix, dir, names):
@@ -699,10 +697,11 @@ def visit(prefix, dir, names):
# to disambiguate these, so we shouldn't need this constraint.
if name in configuration.all_tests:
raise Exception("Found multiple tests with the name %s" % name)
- configuration.all_tests.add(name)
# Run the relevant tests in the python file.
- visit_file(dir, name)
+ if visit_file(dir, name):
+ # Only add to all_tests if the test wasn't skipped/filtered.
+ configuration.all_tests.add(name)
# ======================================== #
>From 73ce14fbb4d90120c9b1010f9ca4116a9600db39 Mon Sep 17 00:00:00 2001
From: Dave Lee <davelee.com at gmail.com>
Date: Mon, 28 Apr 2025 11:18:06 -0700
Subject: [PATCH 2/2] Break from loop when matching a filterspec
---
lldb/packages/Python/lldbsuite/test/dotest.py | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/lldb/packages/Python/lldbsuite/test/dotest.py b/lldb/packages/Python/lldbsuite/test/dotest.py
index e9b5985e03c11..3fc9b2fea5c9b 100644
--- a/lldb/packages/Python/lldbsuite/test/dotest.py
+++ b/lldb/packages/Python/lldbsuite/test/dotest.py
@@ -660,13 +660,13 @@ def iter_filters():
yield key + "." + filterspec
if configuration.filters:
- filtered = False
for filterspec in iter_filters():
- filtered = True
print(f"adding filter spec {filterspec} to module {module!r}")
tests = unittest.defaultTestLoader.loadTestsFromName(filterspec, module)
configuration.suite.addTests(tests)
- return filtered
+ return True
+ # Forgo this module if the (base, filterspec) combo is invalid
+ return False
# Add the entire file's worth of tests since we're not filtered.
# Also the fail-over case when the filterspec branch
More information about the lldb-commits
mailing list