Skip to content

[Bug]: tunit filtering with conditional operators #4580

Closed

Description

@mitchcapper

Description

Using an or operator, for example, seems to throw an error. MS source implies it might be something that should be handled by tunit. Potentially more likely tunit documentation is off.

Tunit test filters says (/*/*/Class1/*)|(/*/*/Class2/*) should work but ms throws:
A filter '/.*/.*/Class1/.*' should not contain a '/' character

The MS source says

// Note: Handling of other operations in valid scenarios should be handled by the caller.
//       Reaching this code for instance means that we're trying to process / operator
//       in the middle of a ( expression ).

Oddly --treenode-filter "/*/*/*/(Stdout_ReturnsExpectedOutput)|(Stderr_ReturnsExpectedErrorOutput)" doesn't throw an error, according to ms docs I believe is correct, yet results in neither test being run.

Expected Behavior

the two tests pass to run

Actual Behavior

Unhandled exception. System.ArgumentException: A filter '/.*/.*/Class1/.*' should not contain a '/' character
   at Microsoft.Testing.Platform.Requests.TreeNodeFilter.ValidateExpression(FilterExpression expr, Boolean isMatchAllAllowed) in /_/src/Platform/Microsoft.Testing.Platform/Requests/TreeNodeFilter/TreeNodeFilter.cs:line 300

or with the second filter:

--treenode-filter "/*/*/*/(Stdout_ReturnsExpectedOutput)|(Stderr_ReturnsExpectedErrorOutput)"
TUnit v1.12.65.0 | 64-bit | Microsoft Windows 10.0.26100 | win-x64 | .NET 10.0.2 | Microsoft Testing Platform v2.0.2

Test run summary: Zero tests ran -

--treenode-filter "/*/*/*/(Stdout_ReturnsExpectedOutput)" with just one test (but with parens) also throws the an error.

Steps to Reproduce

see above

TUnit Version

v1.12.65.0

.NET Version

net 10

Operating System

Windows

IDE / Test Runner

dotnet CLI (dotnet test / dotnet run)

Error Output / Stack Trace

Unhandled exception. System.ArgumentException: A filter '/.*/.*/Class1/.*' should not contain a '/' character
   at Microsoft.Testing.Platform.Requests.TreeNodeFilter.ValidateExpression(FilterExpression expr, Boolean isMatchAllAllowed) in /_/src/Platform/Microsoft.Testing.Platform/Requests/TreeNodeFilter/TreeNodeFilter.cs:line 300
   at Microsoft.Testing.Platform.Requests.TreeNodeFilter.ParseFilter(String filter) in /_/src/Platform/Microsoft.Testing.Platform/Requests/TreeNodeFilter/TreeNodeFilter.cs:line 255
   at Microsoft.Testing.Platform.Requests.TreeNodeFilter..ctor(String filter) in /_/src/Platform/Microsoft.Testing.Platform/Requests/TreeNodeFilter/TreeNodeFilter.cs:line 29
   at Microsoft.Testing.Platform.Requests.ConsoleTestExecutionFilterFactory.TryCreateAsync() in /_/src/Platform/Microsoft.Testing.Platform/Requests/ConsoleTestExecutionFilterFactory.cs:line 32
   at Microsoft.Testing.Platform.Requests.ConsoleTestExecutionRequestFactory.CreateRequestAsync(TestSessionContext session) in /_/src/Platform/Microsoft.Testing.Platform/Requests/ConsoleTestExecutionRequestFactory.cs:line 18
   at Microsoft.Testing.Platform.Requests.TestHostTestFrameworkInvoker.ExecuteAsync(ITestFramework testFramework, ClientInfo client, CancellationToken cancellationToken) in /_/src/Platform/Microsoft.Testing.Platform/Requests/TestHostTestFrameworkInvoker.cs:line 57
   at Microsoft.Testing.Platform.Hosts.CommonHost.ExecuteRequestAsync(ProxyOutputDevice outputDevice, ITestSessionContext testSessionInfo, ServiceProvider serviceProvider, BaseMessageBus baseMessageBus, ITestFramework testFramework, ClientInfo client) in /_/src/Platform/Microsoft.Testing.Platform/Hosts/CommonTestHost.cs:line 141
   at Microsoft.Testing.Platform.Hosts.ConsoleTestHost.InternalRunAsync(CancellationToken cancellationToken) in /_/src/Platform/Microsoft.Testing.Platform/Hosts/ConsoleTestHost.cs:line 82
   at Microsoft.Testing.Platform.Hosts.ConsoleTestHost.InternalRunAsync(CancellationToken cancellationToken) in /_/src/Platform/Microsoft.Testing.Platform/Hosts/ConsoleTestHost.cs:line 114
   at Microsoft.Testing.Platform.Hosts.CommonHost.RunTestAppAsync(CancellationToken testApplicationCancellationToken) in /_/src/Platform/Microsoft.Testing.Platform/Hosts/CommonTestHost.cs:line 115
   at Microsoft.Testing.Platform.Hosts.CommonHost.RunAsync() in /_/src/Platform/Microsoft.Testing.Platform/Hosts/CommonTestHost.cs:line 38
   at Microsoft.Testing.Platform.Hosts.CommonHost.RunAsync() in /_/src/Platform/Microsoft.Testing.Platform/Hosts/CommonTestHost.cs:line 74
   at Microsoft.Testing.Platform.Builder.TestApplication.RunAsync() in /_/src/Platform/Microsoft.Testing.Platform/Builder/TestApplication.cs:line 227

Additional Context

no trimming

IDE-Specific Issue?

  • I've confirmed this issue occurs when running via dotnet test or dotnet run, not just in my IDE

Activity

  1. added
    bug
    on Jan 28, 2026
  2. added a commit that references this issue on Jan 28, 2026
    84ce79a
  3. thomhurst commented on Jan 28, 2026

    @thomhurst
    Owner

    /*/*/*/(Stdout_ReturnsExpectedOutput)|(Stderr_ReturnsExpectedErrorOutput) - Might be worth raising this with MS if it's not working. I'll update the docs for the dodgy syntax throwing exceptions. Thanks!

  4. mitchcapper commented on Jan 28, 2026

    @mitchcapper
    Author

    FYI I did find a nonobvious pattern that works, well several, but the easiest is probably something like:
    --treenode-filter "/*/*/*/(MyTest1|MyTest2|MyTest3*)"

    it doesnt matter very much where you stick that final asterisk either so /*/*/*/(MyTest1*|MyTest2|MyTest3) also works and /*/*/*/(MyTest1|*MyTest2|MyTest3)

  5. thomhurst commented on Jan 28, 2026

    @thomhurst
    Owner

    Sounds like a bug where Microsoft won't accept multiple explicit test names without a wildcard or condition

  6. added a commit that references this issue on Jan 28, 2026
    bc50497
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions