Repository navigation
Description
Describe the bug
I wanted to run two tests at once, easy enough assumed the OR operator was straightforward but couldn't get it to work.
In short the following filter patterns don't work for selecting two tests (named MyTest1/MyTest2) (and the first one doesn't even work selecting just the one):
/*/*/*/(MyTest1)
/*/*/*/(MyTest1)|(MyTest2)
/*/*/*/(MyTest1|MyTest2)
(/*/*/*/MyTest1)|(/*/*/*/MyTest2) # this one crashes as wellThese all work to select both, even though some are a bit non-obvious to me as to why:
/*/*/*/(MyTest1)|(MyTest2*)
/*/*/*/(MyTest1*)|(MyTest2)
/*/*/*/(MyTest1*)|(MyTest2*)
/*/*/*/(MyTest1*)|(MyTest2*)
/*/*/*/(MyTest1*|MyTest2)
/*/*/*/(MyTest1*|MyTest2*)
/*/*/*/MyTest*
/*/*/*/(MyTest1)|(*MyTest2)
/*/*/*/(*MyTest1)|(MyTest2)
/*/*/*/*(MyTest1)|(MyTest2)
/*/*/*/(MyTest1*)|MyTest2
/*/*/*/(MyTest1)|MyTest2*Here is a short powershell script. I tried to repro without tunit with the TestingPlatformExamples\TestingPlatformExplorer however in VS 2026 while the tests pass they don't have their status picked up and it looks like they haven't run.
Command line works but oddly the command line doesn't show (or accept) the --treenode-filter or --filter to dotnet run -- only --filter-uid even though it looks like the CLI should be included. I tried manually shoehorning it in with
var cliOpts = new TestingFrameworkCommandLineOptions();
testApplicationBuilder.CommandLine.AddProvider(() => cliOpts);
testApplicationBuilder.AddTreeNodeFilterService(cliOpts);but while it builds still doesnt have the option. I wasn't sure originally if it was a tunit or vstest thing (thomhurst/TUnit#4580) but it seems vstest.
Steps To Reproduce
Set-PSDebug -Trace 1
dotnet new console --name YourTestProjectNameHere
cd YourTestProjectNameHere
dotnet add package TUnit --prerelease
rm Program.cs
"namespace YourTestProjectNameHere;`npublic class MyTests {`n [Test]`n public async Task MyTest1() => await Assert.That(true).IsTrue();`n [Test]`n public async Task MyTest2() => await Assert.That(true).IsTrue();`n}" | Out-File -FilePath MyTests.cs
dotnet run --disable-logo --list-tests
Write-Host -Foreground Red "These Filters fail"
dotnet run --disable-logo --treenode-filter "/*/*/*/(MyTest1)"
dotnet run --disable-logo --treenode-filter "/*/*/*/(MyTest1)|(MyTest2)"
dotnet run --disable-logo --treenode-filter "/*/*/*/(MyTest1|MyTest2)"
# this fails but crashes dotnet run --disable-logo --treenode-filter "(/*/*/*/MyTest1)|(/*/*/*/MyTest2)"
Write-Host -Foreground Green "These filters work"
dotnet run --disable-logo --treenode-filter "/*/*/*/(MyTest1)|(MyTest2*)"
dotnet run --disable-logo --treenode-filter "/*/*/*/(MyTest1*)|(MyTest2)"
dotnet run --disable-logo --treenode-filter "/*/*/*/(MyTest1*)|(MyTest2*)"
dotnet run --disable-logo --treenode-filter "/*/*/*/(MyTest1*)|(MyTest2*)"
dotnet run --disable-logo --treenode-filter "/*/*/*/(MyTest1*|MyTest2)"
dotnet run --disable-logo --treenode-filter "/*/*/*/(MyTest1*|MyTest2*)"
dotnet run --disable-logo --treenode-filter "/*/*/*/MyTest*"
dotnet run --disable-logo --treenode-filter "/*/*/*/(MyTest1)|(*MyTest2)"
dotnet run --disable-logo --treenode-filter "/*/*/*/(*MyTest1)|(MyTest2)"
dotnet run --disable-logo --treenode-filter "/*/*/*/*(MyTest1)|(MyTest2)"
dotnet run --disable-logo --treenode-filter "/*/*/*/(MyTest1*)|MyTest2"
dotnet run --disable-logo --treenode-filter "/*/*/*/(MyTest1)|MyTest2*"
Log of said script attached
also, with 3 tests it is no more obvious this doesn't work: /*/*/*/(MyTest1|MyTest2|MyTest3) but /*/*/*/(MyTest1|MyTest2*|MyTest3) does.
Activity
Clarify test name and intent for known literal-vs-suffix limitation
Evangelink commentedon May 28, 2026
Diagnosis
After a deep investigation, the remaining cases here turned out to be a bug in TUnit's pre-filter, not in MTP. Posting the full root-cause analysis for posterity:
Cases 1-3 (
/*/*/*/(MyTest1),/*/*/*/(MyTest1|MyTest2),/*/*/*/MyTests/(MyTest1|MyTest2))Microsoft.Testing.Platform.Requests.TreeNodeFilteractually matches all three. A reflection probe againstMicrosoft.Testing.Platform 2.0.2(the version TUnit 1.12.65 bundles):MatchesFilterreturns/*/*/*/(MyTest1)/*/*/*/(MyTest1|MyTest2)/*/*/*/MyTests/(MyTest1|MyTest2)against
/YourTestProjectNameHere/YourTestProjectNameHere/MyTests/MyTest1(the path TUnit'sTestFilterService.BuildPathproduces for the repro). The existingOrExpression_WorksForSinglePathSegmentInsideParenthesesunit test confirms the same.The reason no tests actually run is that TUnit's
MetadataFilterMatcher.ExtractFilterHintspre-filters all discovered descriptors withAotTestDataCollector.CouldDescriptorMatchbefore MTP'sTreeNodeFilterever gets a chance. The pre-filter does:So for
/*/*/*/(MyTest1)→parts[4]is"(MyTest1)"→IsWildcardreturns false → TUnit decides "the user is filtering on a literal method named(MyTest1)" and rejects every descriptor. The asymmetry observed in this issue matches perfectly: every "failing" pattern has no*/?inside the parenthesised last segment; the working workaround/*/*/*/(MyTest1*)only succeeds because the*makesIsWildcardreturn true and disables the broken hint.Filed upstream as thomhurst/TUnit#6026 with a suggested fix.
Case 4 (
(/*/*/*/MyTest1)|(/*/*/*/MyTest2))This was the only true MTP-side issue and was fixed in #7415 — it now throws an actionable diagnostic with the original filter and a syntax suggestion (
/A/B/C/(X|Y)).Follow-up housekeeping
#7415 also added a
LiteralSegment_RequiresWildcardToMatchNodesWithAdditionalSuffixunit test based on a hypothesis that turned out to be wrong (TUnit's node IDs don't append()or any suffix). I'm removing it in #8663.Resolution
I'll close this once TUnit ships their fix for #6026, or earlier — feel free to close as "not a testfx bug" if you'd rather.
Evangelink commentedon May 28, 2026
Closing as not planned on the testfx side:
(/*/*/*/MyTest1)|(/*/*/*/MyTest2)) was fixed in Fix TreeNodeFilter OR-pattern diagnostics #7415 — it now throws an actionable diagnostic./*/*/*/(MyTest1),/*/*/*/(MyTest1|MyTest2),/*/*/*/MyTests/(MyTest1|MyTest2)) are an upstream bug in TUnit'sMetadataFilterMatcherpre-filter — MTP'sTreeNodeFiltermatches all of them correctly. Tracked at MetadataFilterMatcher.ExtractFilterHints misinterprets parenthesised path segments as literal method names thomhurst/TUnit#6026.Please reopen if you hit another
--treenode-filtersymptom that doesn't reduce to either of the above.