Skip to content

Commit 649d487

Browse files
EvangelinkCopilot
andauthored
Add MTP core mutation tests and fix tree-node filter precedence (#12574)
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent 60ec2e6 commit 649d487

62 files changed

Lines changed: 7411 additions & 3 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎docs/decisions/mtp-mutation-testing.md‎

Lines changed: 261 additions & 0 deletions
Large diffs are not rendered by default.

‎src/MTP/Microsoft.Testing.Platform/Requests/TreeNodeFilter/TreeNodeFilter.Parsing.cs‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,6 @@ static void ProcessHigherPrecedenceOperators(
253253
{
254254
OperatorKind topStackOperator = operatorStack.Pop();
255255
ProcessStackOperator(topStackOperator, expressionStack, operatorStack, currentFilter);
256-
break;
257256
}
258257

259258
operatorStack.Push(currentOp);

‎test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/ExecutionTests.cs‎

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@
44
namespace Microsoft.Testing.Platform.Acceptance.IntegrationTests;
55

66
[TestClass]
7+
[DoNotParallelize]
78
public 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
402442
public 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
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
namespace Microsoft.Testing.Platform.UnitTests;
5+
6+
/// <summary>
7+
/// Bounded wait usable on every target framework (Task.WaitAsync does not exist on net462): a regression that makes
8+
/// the awaited task hang fails fast with an assertion instead of blocking the whole test run.
9+
/// </summary>
10+
internal static class BoundedTaskWait
11+
{
12+
public static async Task CompleteWithinAsync(Task task, int seconds = 30)
13+
{
14+
Task finished = await Task.WhenAny(task, Task.Delay(TimeSpan.FromSeconds(seconds)));
15+
Assert.AreSame(task, finished, $"The task did not complete within {seconds} seconds.");
16+
await task;
17+
}
18+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
using Microsoft.Testing.Platform.TestHost;
5+
6+
namespace Microsoft.Testing.Platform.UnitTests;
7+
8+
[TestClass]
9+
public sealed class ClientInfoTests
10+
{
11+
[TestMethod]
12+
public void Constructor_ExposesIdAndVersion()
13+
{
14+
ClientInfo clientInfo = new("vs-client", "17.12.3");
15+
16+
Assert.AreEqual("vs-client", clientInfo.Id);
17+
Assert.AreEqual("17.12.3", clientInfo.Version);
18+
}
19+
}

‎test/UnitTests/Microsoft.Testing.Platform.UnitTests/CommandLine/CommandLineArgumentsRedactorTests.cs‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,49 @@ public void Redact_RemovesEndpointPathAndPreservesOtherArguments()
3636
CommandLineArgumentsRedactor.Redact(arguments));
3737
}
3838

39+
[TestMethod]
40+
public void Redact_TokenValueStartingWithDashIsRedactedAndLaterValuesStayPlain()
41+
=> Assert.AreEqual(
42+
"--dotnet-test-http-token ***REDACTED*** plain --server dotnettestcli",
43+
CommandLineArgumentsRedactor.Redact(
44+
["--dotnet-test-http-token", "-secret", "plain", "--server", "dotnettestcli"]));
45+
46+
[TestMethod]
47+
public void Redact_EndpointValueStartingWithDashIsRedactedAndLaterValuesStayPlain()
48+
=> Assert.AreEqual(
49+
"--dotnet-test-http-endpoint ***REDACTED*** plain",
50+
CommandLineArgumentsRedactor.Redact(
51+
["--dotnet-test-http-endpoint", "-https://gateway.example/private/run-id", "plain"]));
52+
53+
[TestMethod]
54+
[DataRow("-")]
55+
[DataRow("--")]
56+
[DataRow("---")]
57+
[DataRow(" --")]
58+
public void Redact_ArgumentMadeOnlyOfDashesIsReturnedUnchanged(string argument)
59+
=> Assert.AreEqual(argument, CommandLineArgumentsRedactor.Redact([argument]));
60+
61+
[TestMethod]
62+
[DataRow(" --other")]
63+
[DataRow("--")]
64+
[DataRow("-")]
65+
[DataRow("---other")]
66+
public void Redact_ArgumentThatIsNotAnOptionNameAfterInlineTokenIsTreatedAsPositional(string next)
67+
=> Assert.AreEqual(
68+
"--dotnet-test-http-token=***REDACTED*** ***REDACTED***",
69+
CommandLineArgumentsRedactor.Redact(["--dotnet-test-http-token=secret", next]));
70+
71+
[TestMethod]
72+
public void Redact_EndpointKeepsHttpSchemeHostAndPortButDropsPath()
73+
{
74+
Assert.AreEqual(
75+
"--dotnet-test-http-endpoint http://localhost:8080",
76+
CommandLineArgumentsRedactor.Redact(["--dotnet-test-http-endpoint", "http://localhost:8080/path/x"]));
77+
Assert.AreEqual(
78+
"--dotnet-test-http-endpoint ***REDACTED***",
79+
CommandLineArgumentsRedactor.Redact(["--dotnet-test-http-endpoint", "ftp://localhost:8080/path/x"]));
80+
}
81+
3982
[TestMethod]
4083
public void Redact_RepeatedTokenOptionDoesNotExposeValue()
4184
=> Assert.AreEqual(

0 commit comments

Comments
 (0)