44namespace Microsoft . Testing . Platform . Acceptance . IntegrationTests ;
55
66[ TestClass ]
7+ [ DoNotParallelize ]
78public class ExecutionTests : AcceptanceTestBase < ExecutionTests . TestAssetFixture >
89{
910 private const string AssetName = "ExecutionTests" ;
1011 private const string FilterProviderAEnvironmentVariable = "MTP_TEST_FILTER_PROVIDER_A" ;
1112 private const string FilterProviderBEnvironmentVariable = "MTP_TEST_FILTER_PROVIDER_B" ;
13+ private const string UseMixedTreeNodePathsEnvironmentVariable = "MTP_TEST_USE_MIXED_TREE_NODE_PATHS" ;
1214
1315 [ DynamicData ( nameof ( TargetFrameworks . AllForDynamicData ) , typeof ( TargetFrameworks ) ) ]
1416 [ TestMethod ]
@@ -125,6 +127,44 @@ public async Task Exec_WhenFilterIsSpecified_OnlyFilteredTestsAreRun(string tfm)
125127 testHostResult . AssertOutputMatchesRegex ( $ "Passed! - .*\\ .(dll|exe) \\ (net.+\\ |.+\\ )") ;
126128 }
127129
130+ [ DynamicData ( nameof ( TargetFrameworks . AllForDynamicData ) , typeof ( TargetFrameworks ) ) ]
131+ [ TestMethod ]
132+ public async Task Exec_WhenMixedPrecedenceFilterIsSpecified_OnlyMatchingTestIsRun ( string tfm )
133+ {
134+ var testHost = TestInfrastructure . TestHost . LocateFrom ( AssetFixture . TargetAssetPath , AssetName , tfm ) ;
135+ const string filter = "A|B&C/D" ;
136+ Dictionary < string , string ? > discoveryEnvironmentVariables = new ( )
137+ {
138+ [ UseMixedTreeNodePathsEnvironmentVariable ] = "1" ,
139+ } ;
140+
141+ TestHostResult discoveryResult = await testHost . ExecuteAsync (
142+ $ "--list-tests --treenode-filter \" { filter } \" ",
143+ environmentVariables : discoveryEnvironmentVariables ,
144+ cancellationToken : TestContext . CancellationToken ) ;
145+
146+ discoveryResult . AssertExitCodeIs ( ExitCode . Success ) ;
147+ discoveryResult . AssertOutputMatchesRegex ( """
148+ Test1
149+ Test discovery summary: found 1 test\(s\)
150+ """ ) ;
151+ Assert . DoesNotContain ( "Test2" , discoveryResult . StandardOutput ) ;
152+
153+ Dictionary < string , string ? > runEnvironmentVariables = new ( )
154+ {
155+ [ UseMixedTreeNodePathsEnvironmentVariable ] = "1" ,
156+ } ;
157+ TestHostResult runResult = await testHost . ExecuteAsync (
158+ $ "--treenode-filter \" { filter } \" ",
159+ environmentVariables : runEnvironmentVariables ,
160+ cancellationToken : TestContext . CancellationToken ) ;
161+
162+ runResult . AssertExitCodeIs ( ExitCode . Success ) ;
163+ runResult . AssertOutputContainsSummary ( failed : 0 , passed : 1 , skipped : 0 ) ;
164+ Assert . Contains ( "Executed Test1" , runResult . StandardOutput ) ;
165+ Assert . DoesNotContain ( "Executed Test2" , runResult . StandardOutput ) ;
166+ }
167+
128168 [ DynamicData ( nameof ( TargetFrameworks . AllForDynamicData ) , typeof ( TargetFrameworks ) ) ]
129169 [ TestMethod ]
130170 public async Task Exec_WhenBothTreeNodeFilterAndUidFilterAreSpecified_ResultIsNotOk ( string tfm )
@@ -401,6 +441,7 @@ .. value
401441
402442public class DummyTestFramework : ITestFramework, IDataProducer
403443{
444+ private const string UseMixedTreeNodePathsEnvironmentVariable = "MTP_TEST_USE_MIXED_TREE_NODE_PATHS";
404445 private readonly MyExtension _myExtension;
405446
406447 public DummyTestFramework(MyExtension myExtension)
@@ -432,8 +473,9 @@ public async Task ExecuteRequestAsync(ExecuteRequestContext context)
432473 // Simulate that here.
433474 TestExecutionRequest request = (TestExecutionRequest)context.Request;
434475 bool isDiscovery = request is DiscoverTestExecutionRequest;
435- bool excludeUid0 = !MatchesFilter(request.Filter, "0", "/<whatever>");
436- bool excludeUid1 = !MatchesFilter(request.Filter, "1", "/other");
476+ bool useMixedTreeNodePaths = Environment.GetEnvironmentVariable(UseMixedTreeNodePathsEnvironmentVariable) is not null;
477+ bool excludeUid0 = !MatchesFilter(request.Filter, "0", useMixedTreeNodePaths ? "/A/D" : "/<whatever>");
478+ bool excludeUid1 = !MatchesFilter(request.Filter, "1", useMixedTreeNodePaths ? "/B/C/D" : "/other");
437479
438480 if (!excludeUid0)
439481 {
@@ -445,6 +487,10 @@ public async Task ExecuteRequestAsync(ExecuteRequestContext context)
445487 {
446488 await context.MessageBus.PublishAsync(this, new TestNodeUpdateMessage(context.Request.Session.SessionUid,
447489 new TestNode() { Uid = "0", DisplayName = "Test1", Properties = new(PassedTestNodeStateProperty.CachedInstance) }));
490+ if (useMixedTreeNodePaths)
491+ {
492+ Console.WriteLine("Executed Test1");
493+ }
448494 }
449495
450496 if (!excludeUid1)
@@ -456,6 +502,10 @@ public async Task ExecuteRequestAsync(ExecuteRequestContext context)
456502 {
457503 await context.MessageBus.PublishAsync(this, new TestNodeUpdateMessage(context.Request.Session.SessionUid,
458504 new TestNode() { Uid = "1", DisplayName = "Test2", Properties = new(PassedTestNodeStateProperty.CachedInstance) }));
505+ if (useMixedTreeNodePaths)
506+ {
507+ Console.WriteLine("Executed Test2");
508+ }
459509 }
460510 }
461511
0 commit comments