Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion TUnit.Engine/Services/MetadataDependencyExpander.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,11 @@ public HashSet<TestMetadata> ExpandToIncludeDependencies(
// Get candidate list based on dependency type for O(1) lookup
IEnumerable<TestMetadata> candidates;

// When matching same-class dependencies by method name only, the candidate
// list spans all classes, so we must additionally filter by the current
// test's class type inside the loop below (avoids a per-iteration closure).
var filterByCurrentClassType = false;

if (dependency.ClassType != null && !string.IsNullOrEmpty(dependency.MethodName))
{
// Specific class and method - use most specific index
Expand Down Expand Up @@ -176,7 +181,8 @@ public HashSet<TestMetadata> ExpandToIncludeDependencies(
// Same-class dependency by method name - look up by method name, then filter by class
if (byMethodName.TryGetValue(dependency.MethodName!, out var list))
{
candidates = list.Where(m => m.TestClassType == current.TestClassType);
candidates = list;
filterByCurrentClassType = true;
}
else
{
Expand All @@ -191,6 +197,11 @@ public HashSet<TestMetadata> ExpandToIncludeDependencies(

foreach (var candidateMetadata in candidates)
{
if (filterByCurrentClassType && candidateMetadata.TestClassType != current.TestClassType)
{
continue;
}

if (dependency.Matches(candidateMetadata, current))
{
if (result.Add(candidateMetadata))
Expand Down
Loading