From bd712d0f7eecfc6ca048cd3d8e8aed9d1ef5f8b6 Mon Sep 17 00:00:00 2001 From: Marco Rossignoli Date: Wed, 21 Feb 2024 20:17:07 +0100 Subject: [PATCH] Remove the `TestingPlatformServer` if the runner is disabled (#2409) (#2410) --- eng/Versions.props | 2 +- .../Build/Common/MSTest.TestAdapter.targets | 1 + .../NetWithWinUI/MSTest.TestAdapter.targets | 1 + .../Universal/MSTest.TestAdapter.targets | 1 + .../MSTestRunnerTests.cs | 66 +++++++++++++++---- .../testsbaseline.txt | 16 +++++ 6 files changed, 74 insertions(+), 13 deletions(-) diff --git a/eng/Versions.props b/eng/Versions.props index 1569499db2..b11e622b8e 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -36,7 +36,7 @@ 17.10.4-preview.24120.6 4.18.4 - 2.1.858 + 2.2.169 8.2.0 1.1.1 0.2.5 diff --git a/src/Adapter/Build/Common/MSTest.TestAdapter.targets b/src/Adapter/Build/Common/MSTest.TestAdapter.targets index da96212c26..1bd172a93d 100644 --- a/src/Adapter/Build/Common/MSTest.TestAdapter.targets +++ b/src/Adapter/Build/Common/MSTest.TestAdapter.targets @@ -4,6 +4,7 @@ $(EnableMSTestRunner) false + true diff --git a/src/Adapter/Build/NetWithWinUI/MSTest.TestAdapter.targets b/src/Adapter/Build/NetWithWinUI/MSTest.TestAdapter.targets index 0be914ab15..af18aa4f91 100644 --- a/src/Adapter/Build/NetWithWinUI/MSTest.TestAdapter.targets +++ b/src/Adapter/Build/NetWithWinUI/MSTest.TestAdapter.targets @@ -4,6 +4,7 @@ $(EnableMSTestRunner) false + true diff --git a/src/Adapter/Build/Universal/MSTest.TestAdapter.targets b/src/Adapter/Build/Universal/MSTest.TestAdapter.targets index 5ec5705feb..0c208a23f9 100644 --- a/src/Adapter/Build/Universal/MSTest.TestAdapter.targets +++ b/src/Adapter/Build/Universal/MSTest.TestAdapter.targets @@ -5,6 +5,7 @@ $(EnableMSTestRunner) false + true diff --git a/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/MSTestRunnerTests.cs b/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/MSTestRunnerTests.cs index ad706dee91..4591320cda 100644 --- a/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/MSTestRunnerTests.cs +++ b/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/MSTestRunnerTests.cs @@ -1,8 +1,12 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. +using Microsoft.Build.Logging.StructuredLogger; using Microsoft.Testing.Platform.Acceptance.IntegrationTests.Helpers; +using SL = Microsoft.Build.Logging.StructuredLogger; +using SystemTask = System.Threading.Tasks.Task; + namespace Microsoft.Testing.Platform.Acceptance.IntegrationTests; [TestGroup] @@ -19,7 +23,7 @@ public MSTestRunnerTests(ITestExecutionContext testExecutionContext, AcceptanceF } [ArgumentsProvider(nameof(GetBuildMatrixTfmBuildVerbConfiguration))] - public async Task EnableMSTestRunner_True_Will_Run_Standalone(string tfm, BuildConfiguration buildConfiguration, Verb verb) + public async SystemTask EnableMSTestRunner_True_Will_Run_Standalone(string tfm, BuildConfiguration buildConfiguration, Verb verb) { await Lock.WaitAsync(); try @@ -39,6 +43,12 @@ public async Task EnableMSTestRunner_True_Will_Run_Standalone(string tfm, BuildC compilationResult = await DotnetCli.RunAsync( $"{verb} -m:1 -nodeReuse:false {generator.TargetAssetPath} -c {buildConfiguration} -bl:{binlogFile} -r {RID}", _acceptanceFixture.NuGetGlobalPackagesFolder.Path); + + SL.Build binLog = SL.Serialization.Read(binlogFile); + Assert.IsNotEmpty(binLog.FindChildrenRecursive() + .Where(x => x.Title.Contains("ProjectCapability")) + .Where(x => x.Children.Any(c => ((Item)c).Name == "TestingPlatformServer"))); + var testHost = TestInfrastructure.TestHost.LocateFrom(generator.TargetAssetPath, AssetName, tfm, buildConfiguration: buildConfiguration, verb: verb); var testHostResult = await testHost.ExecuteAsync(); testHostResult.AssertOutputContains("Passed! - Failed: 0, Passed: 1, Skipped: 0, Total: 1"); @@ -50,7 +60,7 @@ public async Task EnableMSTestRunner_True_Will_Run_Standalone(string tfm, BuildC } [ArgumentsProvider(nameof(GetBuildMatrixTfmBuildVerbConfiguration))] - public async Task EnableMSTestRunner_True_WithCustomEntryPoint_Will_Run_Standalone(string tfm, BuildConfiguration buildConfiguration, Verb verb) + public async SystemTask EnableMSTestRunner_True_WithCustomEntryPoint_Will_Run_Standalone(string tfm, BuildConfiguration buildConfiguration, Verb verb) { await Lock.WaitAsync(); try @@ -94,21 +104,21 @@ public async Task EnableMSTestRunner_True_WithCustomEntryPoint_Will_Run_Standalo } [ArgumentsProvider(nameof(GetBuildMatrixTfmBuildVerbConfiguration))] - public async Task EnableMSTestRunner_False_Will_Run_Empty_Program_EntryPoint_From_Tpv2_SDK(string tfm, BuildConfiguration buildConfiguration, Verb verb) + public async SystemTask EnableMSTestRunner_False_Will_Run_Empty_Program_EntryPoint_From_Tpv2_SDK(string tfm, BuildConfiguration buildConfiguration, Verb verb) { await Lock.WaitAsync(); try { using TestAsset generator = await TestAsset.GenerateAssetAsync( - AssetName, - CurrentMSTestSourceCode - .PatchCodeWithReplace("$TargetFramework$", $"{tfm}") - .PatchCodeWithReplace("$MicrosoftNETTestSdkVersion$", MicrosoftNETTestSdkVersion) - .PatchCodeWithReplace("$MSTestVersion$", MSTestVersion) - .PatchCodeWithReplace("$EnableMSTestRunner$", "false") - .PatchCodeWithReplace("$OutputType$", "Exe") - .PatchCodeWithReplace("$Extra$", string.Empty), - addPublicFeeds: true); + AssetName, + CurrentMSTestSourceCode + .PatchCodeWithReplace("$TargetFramework$", $"{tfm}") + .PatchCodeWithReplace("$MicrosoftNETTestSdkVersion$", MicrosoftNETTestSdkVersion) + .PatchCodeWithReplace("$MSTestVersion$", MSTestVersion) + .PatchCodeWithReplace("$EnableMSTestRunner$", "false") + .PatchCodeWithReplace("$OutputType$", "Exe") + .PatchCodeWithReplace("$Extra$", string.Empty), + addPublicFeeds: true); string binlogFile = Path.Combine(generator.TargetAssetPath, "msbuild.binlog"); var compilationResult = await DotnetCli.RunAsync($"restore -m:1 -nodeReuse:false {generator.TargetAssetPath} -r {RID}", _acceptanceFixture.NuGetGlobalPackagesFolder.Path); try @@ -134,4 +144,36 @@ public async Task EnableMSTestRunner_False_Will_Run_Empty_Program_EntryPoint_Fro Lock.Release(); } } + + [ArgumentsProvider(nameof(GetBuildMatrixTfmBuildVerbConfiguration))] + public async SystemTask EnableMSTestRunner_False_Wont_Flow_TestingPlatformServer_Capability(string tfm, BuildConfiguration buildConfiguration, Verb verb) + { + await Lock.WaitAsync(); + try + { + using TestAsset generator = await TestAsset.GenerateAssetAsync( + AssetName, + CurrentMSTestSourceCode + .PatchCodeWithReplace("$TargetFramework$", $"{tfm}") + .PatchCodeWithReplace("$MicrosoftNETTestSdkVersion$", MicrosoftNETTestSdkVersion) + .PatchCodeWithReplace("$MSTestVersion$", MSTestVersion) + .PatchCodeWithReplace("$EnableMSTestRunner$", string.Empty) + .PatchCodeWithReplace("$OutputType$", string.Empty) + .PatchCodeWithReplace("$Extra$", string.Empty), + addPublicFeeds: false); + + string binlogFile = Path.Combine(generator.TargetAssetPath, "msbuild.binlog"); + var compilationResult = await DotnetCli.RunAsync($"restore -m:1 -nodeReuse:false {generator.TargetAssetPath} -r {RID}", _acceptanceFixture.NuGetGlobalPackagesFolder.Path); + compilationResult = await DotnetCli.RunAsync($"{verb} -bl:{binlogFile} -m:1 -nodeReuse:false {generator.TargetAssetPath} -c {buildConfiguration} -r {RID} ", _acceptanceFixture.NuGetGlobalPackagesFolder.Path); + + SL.Build binLog = SL.Serialization.Read(binlogFile); + Assert.IsEmpty(binLog.FindChildrenRecursive() + .Where(x => x.Title.Contains("ProjectCapability")) + .Where(x => x.Children.Any(c => ((Item)c).Name == "TestingPlatformServer"))); + } + finally + { + Lock.Release(); + } + } } diff --git a/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/testsbaseline.txt b/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/testsbaseline.txt index 12e71e314d..29c6993bbe 100644 --- a/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/testsbaseline.txt +++ b/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/testsbaseline.txt @@ -170,6 +170,22 @@ Microsoft.Testing.Platform.Acceptance.IntegrationTests.Microsoft.Testing.Platfor Microsoft.Testing.Platform.Acceptance.IntegrationTests.Microsoft.Testing.Platform.Acceptance.IntegrationTests.MSTestRunnerTests.EnableMSTestRunner_False_Will_Run_Empty_Program_EntryPoint_From_Tpv2_SDK(string, Microsoft.Testing.TestInfrastructure.BuildConfiguration, Microsoft.Testing.TestInfrastructure.Verb) (net8.0,Debug,publish) Microsoft.Testing.Platform.Acceptance.IntegrationTests.Microsoft.Testing.Platform.Acceptance.IntegrationTests.MSTestRunnerTests.EnableMSTestRunner_False_Will_Run_Empty_Program_EntryPoint_From_Tpv2_SDK(string, Microsoft.Testing.TestInfrastructure.BuildConfiguration, Microsoft.Testing.TestInfrastructure.Verb) (net8.0,Release,build) Microsoft.Testing.Platform.Acceptance.IntegrationTests.Microsoft.Testing.Platform.Acceptance.IntegrationTests.MSTestRunnerTests.EnableMSTestRunner_False_Will_Run_Empty_Program_EntryPoint_From_Tpv2_SDK(string, Microsoft.Testing.TestInfrastructure.BuildConfiguration, Microsoft.Testing.TestInfrastructure.Verb) (net8.0,Release,publish) +Microsoft.Testing.Platform.Acceptance.IntegrationTests.Microsoft.Testing.Platform.Acceptance.IntegrationTests.MSTestRunnerTests.EnableMSTestRunner_False_Wont_Flow_TestingPlatformServer_Capability(string, Microsoft.Testing.TestInfrastructure.BuildConfiguration, Microsoft.Testing.TestInfrastructure.Verb) (net462,Debug,build) +Microsoft.Testing.Platform.Acceptance.IntegrationTests.Microsoft.Testing.Platform.Acceptance.IntegrationTests.MSTestRunnerTests.EnableMSTestRunner_False_Wont_Flow_TestingPlatformServer_Capability(string, Microsoft.Testing.TestInfrastructure.BuildConfiguration, Microsoft.Testing.TestInfrastructure.Verb) (net462,Debug,publish) +Microsoft.Testing.Platform.Acceptance.IntegrationTests.Microsoft.Testing.Platform.Acceptance.IntegrationTests.MSTestRunnerTests.EnableMSTestRunner_False_Wont_Flow_TestingPlatformServer_Capability(string, Microsoft.Testing.TestInfrastructure.BuildConfiguration, Microsoft.Testing.TestInfrastructure.Verb) (net462,Release,build) +Microsoft.Testing.Platform.Acceptance.IntegrationTests.Microsoft.Testing.Platform.Acceptance.IntegrationTests.MSTestRunnerTests.EnableMSTestRunner_False_Wont_Flow_TestingPlatformServer_Capability(string, Microsoft.Testing.TestInfrastructure.BuildConfiguration, Microsoft.Testing.TestInfrastructure.Verb) (net462,Release,publish) +Microsoft.Testing.Platform.Acceptance.IntegrationTests.Microsoft.Testing.Platform.Acceptance.IntegrationTests.MSTestRunnerTests.EnableMSTestRunner_False_Wont_Flow_TestingPlatformServer_Capability(string, Microsoft.Testing.TestInfrastructure.BuildConfiguration, Microsoft.Testing.TestInfrastructure.Verb) (net6.0,Debug,build) +Microsoft.Testing.Platform.Acceptance.IntegrationTests.Microsoft.Testing.Platform.Acceptance.IntegrationTests.MSTestRunnerTests.EnableMSTestRunner_False_Wont_Flow_TestingPlatformServer_Capability(string, Microsoft.Testing.TestInfrastructure.BuildConfiguration, Microsoft.Testing.TestInfrastructure.Verb) (net6.0,Debug,publish) +Microsoft.Testing.Platform.Acceptance.IntegrationTests.Microsoft.Testing.Platform.Acceptance.IntegrationTests.MSTestRunnerTests.EnableMSTestRunner_False_Wont_Flow_TestingPlatformServer_Capability(string, Microsoft.Testing.TestInfrastructure.BuildConfiguration, Microsoft.Testing.TestInfrastructure.Verb) (net6.0,Release,build) +Microsoft.Testing.Platform.Acceptance.IntegrationTests.Microsoft.Testing.Platform.Acceptance.IntegrationTests.MSTestRunnerTests.EnableMSTestRunner_False_Wont_Flow_TestingPlatformServer_Capability(string, Microsoft.Testing.TestInfrastructure.BuildConfiguration, Microsoft.Testing.TestInfrastructure.Verb) (net6.0,Release,publish) +Microsoft.Testing.Platform.Acceptance.IntegrationTests.Microsoft.Testing.Platform.Acceptance.IntegrationTests.MSTestRunnerTests.EnableMSTestRunner_False_Wont_Flow_TestingPlatformServer_Capability(string, Microsoft.Testing.TestInfrastructure.BuildConfiguration, Microsoft.Testing.TestInfrastructure.Verb) (net7.0,Debug,build) +Microsoft.Testing.Platform.Acceptance.IntegrationTests.Microsoft.Testing.Platform.Acceptance.IntegrationTests.MSTestRunnerTests.EnableMSTestRunner_False_Wont_Flow_TestingPlatformServer_Capability(string, Microsoft.Testing.TestInfrastructure.BuildConfiguration, Microsoft.Testing.TestInfrastructure.Verb) (net7.0,Debug,publish) +Microsoft.Testing.Platform.Acceptance.IntegrationTests.Microsoft.Testing.Platform.Acceptance.IntegrationTests.MSTestRunnerTests.EnableMSTestRunner_False_Wont_Flow_TestingPlatformServer_Capability(string, Microsoft.Testing.TestInfrastructure.BuildConfiguration, Microsoft.Testing.TestInfrastructure.Verb) (net7.0,Release,build) +Microsoft.Testing.Platform.Acceptance.IntegrationTests.Microsoft.Testing.Platform.Acceptance.IntegrationTests.MSTestRunnerTests.EnableMSTestRunner_False_Wont_Flow_TestingPlatformServer_Capability(string, Microsoft.Testing.TestInfrastructure.BuildConfiguration, Microsoft.Testing.TestInfrastructure.Verb) (net7.0,Release,publish) +Microsoft.Testing.Platform.Acceptance.IntegrationTests.Microsoft.Testing.Platform.Acceptance.IntegrationTests.MSTestRunnerTests.EnableMSTestRunner_False_Wont_Flow_TestingPlatformServer_Capability(string, Microsoft.Testing.TestInfrastructure.BuildConfiguration, Microsoft.Testing.TestInfrastructure.Verb) (net8.0,Debug,build) +Microsoft.Testing.Platform.Acceptance.IntegrationTests.Microsoft.Testing.Platform.Acceptance.IntegrationTests.MSTestRunnerTests.EnableMSTestRunner_False_Wont_Flow_TestingPlatformServer_Capability(string, Microsoft.Testing.TestInfrastructure.BuildConfiguration, Microsoft.Testing.TestInfrastructure.Verb) (net8.0,Debug,publish) +Microsoft.Testing.Platform.Acceptance.IntegrationTests.Microsoft.Testing.Platform.Acceptance.IntegrationTests.MSTestRunnerTests.EnableMSTestRunner_False_Wont_Flow_TestingPlatformServer_Capability(string, Microsoft.Testing.TestInfrastructure.BuildConfiguration, Microsoft.Testing.TestInfrastructure.Verb) (net8.0,Release,build) +Microsoft.Testing.Platform.Acceptance.IntegrationTests.Microsoft.Testing.Platform.Acceptance.IntegrationTests.MSTestRunnerTests.EnableMSTestRunner_False_Wont_Flow_TestingPlatformServer_Capability(string, Microsoft.Testing.TestInfrastructure.BuildConfiguration, Microsoft.Testing.TestInfrastructure.Verb) (net8.0,Release,publish) Microsoft.Testing.Platform.Acceptance.IntegrationTests.Microsoft.Testing.Platform.Acceptance.IntegrationTests.MSTestRunnerTests.EnableMSTestRunner_True_Will_Run_Standalone(string, Microsoft.Testing.TestInfrastructure.BuildConfiguration, Microsoft.Testing.TestInfrastructure.Verb) (net462,Debug,build) Microsoft.Testing.Platform.Acceptance.IntegrationTests.Microsoft.Testing.Platform.Acceptance.IntegrationTests.MSTestRunnerTests.EnableMSTestRunner_True_Will_Run_Standalone(string, Microsoft.Testing.TestInfrastructure.BuildConfiguration, Microsoft.Testing.TestInfrastructure.Verb) (net462,Debug,publish) Microsoft.Testing.Platform.Acceptance.IntegrationTests.Microsoft.Testing.Platform.Acceptance.IntegrationTests.MSTestRunnerTests.EnableMSTestRunner_True_Will_Run_Standalone(string, Microsoft.Testing.TestInfrastructure.BuildConfiguration, Microsoft.Testing.TestInfrastructure.Verb) (net462,Release,build)