Skip to content

Commit 6188e0d

Browse files
rogeralsingclaude
andcommitted
Fix Method filter to check only method name, not full FQN
Previously "Method=RegExp" would match any test with "RegExp" anywhere in the fully qualified name (namespace, class, or method). Now it properly parses the FQN and checks only the method name portion. Co-Authored-By: Claude Opus 4.5 <[email protected]>
1 parent 20931f4 commit 6188e0d

File tree

1 file changed

+29
-4
lines changed

1 file changed

+29
-4
lines changed

src/Asynkron.TestRunner/TestDiscovery.cs

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,16 @@ public bool Matches(DiscoveredTest test)
7878
/// </summary>
7979
public bool Matches(string fullyQualifiedName, string displayName)
8080
{
81-
// FQN format: Namespace.Class.Method
82-
if (Namespace != null && !fullyQualifiedName.Contains(Namespace, StringComparison.OrdinalIgnoreCase))
81+
// FQN format: Namespace.Class.Method or Namespace.Class.Method(args)
82+
var (ns, className, methodName) = ParseFqn(fullyQualifiedName);
83+
84+
if (Namespace != null && !ns.Contains(Namespace, StringComparison.OrdinalIgnoreCase))
8385
return false;
8486

85-
if (Class != null && !fullyQualifiedName.Contains(Class, StringComparison.OrdinalIgnoreCase))
87+
if (Class != null && !className.Contains(Class, StringComparison.OrdinalIgnoreCase))
8688
return false;
8789

88-
if (Method != null && !fullyQualifiedName.Contains(Method, StringComparison.OrdinalIgnoreCase))
90+
if (Method != null && !methodName.Contains(Method, StringComparison.OrdinalIgnoreCase))
8991
return false;
9092

9193
if (DisplayName != null && !displayName.Contains(DisplayName, StringComparison.OrdinalIgnoreCase))
@@ -94,6 +96,29 @@ public bool Matches(string fullyQualifiedName, string displayName)
9496
return true;
9597
}
9698

99+
private static (string Namespace, string ClassName, string MethodName) ParseFqn(string fqn)
100+
{
101+
// Remove args if present: "Namespace.Class.Method(args)" -> "Namespace.Class.Method"
102+
var parenIndex = fqn.IndexOf('(');
103+
var baseFqn = parenIndex >= 0 ? fqn[..parenIndex] : fqn;
104+
105+
var lastDot = baseFqn.LastIndexOf('.');
106+
if (lastDot < 0)
107+
return ("", "", baseFqn);
108+
109+
var methodName = baseFqn[(lastDot + 1)..];
110+
var remainder = baseFqn[..lastDot];
111+
112+
var secondLastDot = remainder.LastIndexOf('.');
113+
if (secondLastDot < 0)
114+
return ("", remainder, methodName);
115+
116+
var className = remainder[(secondLastDot + 1)..];
117+
var ns = remainder[..secondLastDot];
118+
119+
return (ns, className, methodName);
120+
}
121+
97122
public bool IsEmpty => Namespace == null && Class == null && Method == null && DisplayName == null;
98123

99124
public override string ToString()

0 commit comments

Comments
 (0)