-
-
Notifications
You must be signed in to change notification settings - Fork 111
fix: prevent substring matching in UID filter causing incorrect test inclusion #4659
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| using Shouldly; | ||
| using TUnit.Engine.Tests.Enums; | ||
|
|
||
| namespace TUnit.Engine.Tests; | ||
|
|
||
| /// <summary> | ||
| /// Regression test for GitHub issue #4656: TestDiscoveryContext.AllTests incorrectly | ||
| /// includes tests when class names overlap (ABCV vs ABCVC) due to substring matching. | ||
| /// https://github.com/thomhurst/TUnit/issues/4656 | ||
| /// </summary> | ||
| public class OverlappingClassNameFilterTests(TestMode testMode) : InvokableTestBase(testMode) | ||
| { | ||
| [Test] | ||
| public async Task Filtering_ABCVC_B2_ShouldNotInclude_ABCV_B2() | ||
| { | ||
| // Filter for only ABCVC.B2 (and its dependency ABCVC.B0) | ||
| // Bug #4656: ABCV.B2 was incorrectly included because "ABCV" is a substring of "ABCVC" | ||
| // With the fix, only ABCVC tests should run (B2 + B0 dependency = 2 tests) | ||
| // Without the fix, ABCV.B2 and ABCV.A1 (dependency) would also run (4 tests total) | ||
| await RunTestsWithFilter( | ||
| "/*/TUnit.TestProject.Bugs._4656/ABCVC/B2", | ||
| [ | ||
| result => result.ResultSummary.Outcome.ShouldBe("Completed"), | ||
| result => | ||
| { | ||
| // Key assertion: exactly 2 tests should run (ABCVC.B2 + ABCVC.B0) | ||
| // If the bug exists, 4 tests would run (also ABCV.B2 + ABCV.A1) | ||
| result.ResultSummary.Counters.Total.ShouldBe(2, | ||
| $"Expected 2 tests (ABCVC.B2 + ABCVC.B0) but got {result.ResultSummary.Counters.Total}. " + | ||
| $"Test names: {string.Join(", ", result.Results.Select(r => r.TestName))}. " + | ||
| "If more than 2 tests ran, the substring matching bug (#4656) may be present."); | ||
| }, | ||
| result => result.ResultSummary.Counters.Passed.ShouldBe(2), | ||
| result => result.ResultSummary.Counters.Failed.ShouldBe(0) | ||
| ]); | ||
| } | ||
|
|
||
| [Test] | ||
| public async Task Filtering_ABCV_ShouldNotMatch_ABCVC() | ||
| { | ||
| // Filter for all tests in ABCV class (A1, B1, B2 = 3 tests) | ||
| // Should NOT include any ABCVC tests | ||
| await RunTestsWithFilter( | ||
| "/*/TUnit.TestProject.Bugs._4656/ABCV/*", | ||
| [ | ||
| result => result.ResultSummary.Outcome.ShouldBe("Completed"), | ||
| result => | ||
| { | ||
| // Expected: 3 tests from ABCV (A1, B1, B2) | ||
| // If ABCVC tests were incorrectly included, we'd have 6 tests | ||
| result.ResultSummary.Counters.Total.ShouldBe(3, | ||
| $"Expected 3 tests (ABCV.A1, ABCV.B1, ABCV.B2) but got {result.ResultSummary.Counters.Total}. " + | ||
| $"Test names: {string.Join(", ", result.Results.Select(r => r.TestName))}"); | ||
| }, | ||
| result => result.ResultSummary.Counters.Passed.ShouldBe(3), | ||
| result => result.ResultSummary.Counters.Failed.ShouldBe(0) | ||
| ]); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
TUnit.TestProject/Bugs/4656/OverlappingClassNameFilterTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| using TUnit.TestProject.Attributes; | ||
|
|
||
| namespace TUnit.TestProject.Bugs._4656; | ||
|
|
||
| /// <summary> | ||
| /// Regression test for GitHub issue #4656: TestDiscoveryContext.AllTests is incorrect | ||
| /// when filtering tests with overlapping class names (e.g., ABCV vs ABCVC). | ||
| /// The bug caused ABCV.B2 to incorrectly appear in AllTests when filtering for | ||
| /// ABCD.B2, ABCV.B1, ABCVC.B2, and VPCU.A1000. | ||
| /// https://github.com/thomhurst/TUnit/issues/4656 | ||
| /// </summary> | ||
| [EngineTest(ExpectedResult.Pass)] | ||
| public class ABCD | ||
| { | ||
| [Test] | ||
| public async Task B1() | ||
| { | ||
| await Assert.That(true).IsEqualTo(true); | ||
| } | ||
|
|
||
| [Test] | ||
| public async Task B2() | ||
| { | ||
| await Assert.That(true).IsEqualTo(true); | ||
| } | ||
| } | ||
|
|
||
| [EngineTest(ExpectedResult.Pass)] | ||
| public class VPCU | ||
| { | ||
| [Test, DependsOn<ABCV>(nameof(ABCV.B1))] | ||
| public async Task A1000() | ||
| { | ||
| await Assert.That(true).IsEqualTo(true); | ||
| } | ||
| } | ||
|
|
||
| [EngineTest(ExpectedResult.Pass)] | ||
| public class ABCV | ||
| { | ||
| [Test] | ||
| public async Task A1() | ||
| { | ||
| await Assert.That(true).IsEqualTo(true); | ||
| } | ||
|
|
||
| [Test, DependsOn(nameof(A1))] | ||
| public async Task B1() | ||
| { | ||
| await Assert.That(true).IsEqualTo(true); | ||
| } | ||
|
|
||
| [Test, DependsOn(nameof(A1))] | ||
| public async Task B2() | ||
| { | ||
| // This test should NOT be included when filtering for ABCVC.B2 | ||
| // Bug #4656: substring matching caused this to be incorrectly included | ||
| await Assert.That(true).IsEqualTo(true); | ||
| } | ||
| } | ||
|
|
||
| [EngineTest(ExpectedResult.Pass)] | ||
| public class ABCVC | ||
| { | ||
| [Test] | ||
| public async Task B0() | ||
| { | ||
| await Assert.That(true).IsEqualTo(true); | ||
| } | ||
|
|
||
| [Test, DependsOn(nameof(B0))] | ||
| public async Task B1() | ||
| { | ||
| await Assert.That(true).IsEqualTo(true); | ||
| } | ||
|
|
||
| [Test, DependsOn(nameof(B0))] | ||
| public async Task B2() | ||
| { | ||
| await Assert.That(true).IsEqualTo(true); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
classNameForMatching = className.AsSpan().Slice(0, backtickIndex);and makeReadOnlySpan<char> classNameForMatchingCould prolly use
ValueStringBuilderforexpectedClassPrefixandexpectedGenericClassPrefixbut that's pretty pendanitc