Skip to content

[Bug]: tunit filtering with conditional operators #4580

@mitchcapper

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions