diff --git a/TestPlatform.sln b/TestPlatform.sln index d917217c24..6026dafc1e 100644 --- a/TestPlatform.sln +++ b/TestPlatform.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 -VisualStudioVersion = 15.0.26605.1 +VisualStudioVersion = 15.0.26507.0 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{ED0C35EB-7F31-4841-A24F-8EB708FFA959}" EndProject @@ -157,6 +157,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.TestPlatform.Exte EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlameUnitTestProject", "test\TestAssets\BlameUnitTestProject\BlameUnitTestProject.csproj", "{6B2B841C-CCFF-469A-9939-EB07EA0401AE}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SampleProjectWithOldTestHost", "test\TestAssets\SampleProjectWithOldTestHost\SampleProjectWithOldTestHost.csproj", "{DFF82C76-9498-4E8B-8B5E-D12E2B92FA46}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -827,6 +829,18 @@ Global {6B2B841C-CCFF-469A-9939-EB07EA0401AE}.Release|x64.Build.0 = Release|Any CPU {6B2B841C-CCFF-469A-9939-EB07EA0401AE}.Release|x86.ActiveCfg = Release|Any CPU {6B2B841C-CCFF-469A-9939-EB07EA0401AE}.Release|x86.Build.0 = Release|Any CPU + {DFF82C76-9498-4E8B-8B5E-D12E2B92FA46}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {DFF82C76-9498-4E8B-8B5E-D12E2B92FA46}.Debug|Any CPU.Build.0 = Debug|Any CPU + {DFF82C76-9498-4E8B-8B5E-D12E2B92FA46}.Debug|x64.ActiveCfg = Debug|Any CPU + {DFF82C76-9498-4E8B-8B5E-D12E2B92FA46}.Debug|x64.Build.0 = Debug|Any CPU + {DFF82C76-9498-4E8B-8B5E-D12E2B92FA46}.Debug|x86.ActiveCfg = Debug|Any CPU + {DFF82C76-9498-4E8B-8B5E-D12E2B92FA46}.Debug|x86.Build.0 = Debug|Any CPU + {DFF82C76-9498-4E8B-8B5E-D12E2B92FA46}.Release|Any CPU.ActiveCfg = Release|Any CPU + {DFF82C76-9498-4E8B-8B5E-D12E2B92FA46}.Release|Any CPU.Build.0 = Release|Any CPU + {DFF82C76-9498-4E8B-8B5E-D12E2B92FA46}.Release|x64.ActiveCfg = Release|Any CPU + {DFF82C76-9498-4E8B-8B5E-D12E2B92FA46}.Release|x64.Build.0 = Release|Any CPU + {DFF82C76-9498-4E8B-8B5E-D12E2B92FA46}.Release|x86.ActiveCfg = Release|Any CPU + {DFF82C76-9498-4E8B-8B5E-D12E2B92FA46}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -896,5 +910,6 @@ Global {76D4BB7E-D981-42D5-BE96-6FAD8DEF9A4A} = {ED0C35EB-7F31-4841-A24F-8EB708FFA959} {488675EC-C8BB-40E0-AD4F-91F623D548B3} = {B27FAFDF-2DBA-4AB0-BA85-FD5F21D359D6} {6B2B841C-CCFF-469A-9939-EB07EA0401AE} = {8DA7CBD9-F17E-41B6-90C4-CFF55848A25A} + {DFF82C76-9498-4E8B-8B5E-D12E2B92FA46} = {8DA7CBD9-F17E-41B6-90C4-CFF55848A25A} EndGlobalSection EndGlobal diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/Client/ProxyExecutionManager.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/Client/ProxyExecutionManager.cs index e36c96d2f1..1b5d1a7198 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/Client/ProxyExecutionManager.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/Client/ProxyExecutionManager.cs @@ -8,7 +8,6 @@ namespace Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client using System.Collections.ObjectModel; using System.Linq; using System.Threading; - using Microsoft.VisualStudio.TestPlatform.Common; using Microsoft.VisualStudio.TestPlatform.Common.ExtensionFramework; using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities; @@ -20,7 +19,6 @@ namespace Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client using Microsoft.VisualStudio.TestPlatform.ObjectModel.Engine.ClientProtocol; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Host; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging; - using Constants = Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Constants; /// @@ -121,11 +119,13 @@ public virtual int StartTestRun(TestRunCriteria testRunCriteria, ITestRunEventsH isDebug: (testRunCriteria.TestHostLauncher != null && testRunCriteria.TestHostLauncher.IsDebug), testCaseFilter: testRunCriteria.TestCaseFilter); + // This is workaround for the bug https://github.com/Microsoft/vstest/issues/970 + var runsettings = this.RemoveNodesFromRunsettingsIfRequired(testRunCriteria.TestRunSettings, (testMessageLevel, message) => { this.LogMessage(testMessageLevel, message, eventHandler); }); if (testRunCriteria.HasSpecificSources) { var runRequest = new TestRunCriteriaWithSources( testRunCriteria.AdapterSourceMap, - testRunCriteria.TestRunSettings, + runsettings, executionContext); this.RequestSender.StartTestRun(runRequest, eventHandler); @@ -134,7 +134,7 @@ public virtual int StartTestRun(TestRunCriteria testRunCriteria, ITestRunEventsH { var runRequest = new TestRunCriteriaWithTests( testRunCriteria.Tests, - testRunCriteria.TestRunSettings, + runsettings, executionContext); this.RequestSender.StartTestRun(runRequest, eventHandler); @@ -144,14 +144,7 @@ public virtual int StartTestRun(TestRunCriteria testRunCriteria, ITestRunEventsH catch (Exception exception) { EqtTrace.Error("ProxyExecutionManager.StartTestRun: Failed to start test run: {0}", exception); - - // Log to vs ide test output - var testMessagePayload = new TestMessagePayload { MessageLevel = TestMessageLevel.Error, Message = exception.Message }; - var rawMessage = this.dataSerializer.SerializePayload(MessageType.TestMessage, testMessagePayload); - eventHandler.HandleRawMessage(rawMessage); - - // Log to vstest.console - eventHandler.HandleLogMessage(TestMessageLevel.Error, exception.Message); + this.LogMessage(TestMessageLevel.Error, exception.Message, eventHandler); // Send a run complete to caller. Similar logic is also used in ParallelProxyExecutionManager.StartTestRunOnConcurrentManager // Aborted is `true`: in case of parallel run (or non shared host), an aborted message ensures another execution manager @@ -187,6 +180,17 @@ public void Abort() #endregion + private void LogMessage(TestMessageLevel testMessageLevel, string message, ITestRunEventsHandler eventHandler) + { + // Log to vs ide test output + var testMessagePayload = new TestMessagePayload { MessageLevel = testMessageLevel, Message = message }; + var rawMessage = this.dataSerializer.SerializePayload(MessageType.TestMessage, testMessagePayload); + eventHandler.HandleRawMessage(rawMessage); + + // Log to vstest.console + eventHandler.HandleLogMessage(testMessageLevel, message); + } + private void InitializeExtensions(IEnumerable sources) { var extensions = new List(); diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/Client/ProxyOperationManager.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/Client/ProxyOperationManager.cs index db835205c5..4f2a1d3035 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/Client/ProxyOperationManager.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/Client/ProxyOperationManager.cs @@ -10,11 +10,11 @@ namespace Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client using System.Linq; using System.Reflection; using System.Threading; - using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.Interfaces; using Microsoft.VisualStudio.TestPlatform.CoreUtilities.Extensions; using Microsoft.VisualStudio.TestPlatform.ObjectModel; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Host; + using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging; using Microsoft.VisualStudio.TestPlatform.PlatformAbstractions; using Microsoft.VisualStudio.TestPlatform.PlatformAbstractions.Interfaces; using Microsoft.VisualStudio.TestPlatform.Utilities; @@ -30,6 +30,10 @@ public abstract class ProxyOperationManager private readonly IProcessHelper processHelper; private readonly int connectionTimeout; private readonly string versionCheckPropertyName = "IsVersionCheckRequired"; + private readonly string makeRunsettingsCompatiblePropertyName = "MakeRunsettingsCompatible"; + private bool versionCheckRequired = true; + private bool makeRunsettingsCompatible; + private bool makeRunsettingsCompatibleSet; private readonly ManualResetEventSlim testHostExited = new ManualResetEventSlim(false); private int testHostProcessId; @@ -157,14 +161,9 @@ public virtual bool SetupChannel(IEnumerable sources, CancellationToken // Handling special case for dotnet core projects with older test hosts // Older test hosts are not aware of protocol version check // Hence we should not be sending VersionCheck message to these test hosts - bool checkRequired = true; - var property = this.testHostManager.GetType().GetRuntimeProperties().FirstOrDefault(p => string.Equals(p.Name, versionCheckPropertyName, StringComparison.OrdinalIgnoreCase)); - if (property != null) - { - checkRequired = (bool)property.GetValue(this.testHostManager); - } + this.CompatIssueWithVersionCheckAndRunsettings(); - if (checkRequired) + if (this.versionCheckRequired) { this.RequestSender.CheckVersionWithTestHost(); } @@ -203,7 +202,7 @@ public virtual void Close() this.initialized = false; EqtTrace.Warning("ProxyOperationManager: Timed out waiting for test host to exit. Will terminate process."); - + // please clean up test host. this.testHostManager.CleanTestHostAsync(CancellationToken.None).Wait(); @@ -245,6 +244,46 @@ protected string GetTimestampedLogFile(string logFile) Path.GetExtension(logFile))).AddDoubleQuote(); } + /// + /// This function will remove the unknown runsettings node from runsettings for old testhost who throws exception for unknown node. + /// + /// runsettings string + /// runsetting after removing unrequired nodes + protected string RemoveNodesFromRunsettingsIfRequired(string runsettingsXml, Action logMessage) + { + var updatedRunSettingsXml = runsettingsXml; + if (!this.makeRunsettingsCompatibleSet) + { + this.CompatIssueWithVersionCheckAndRunsettings(); + } + + if (this.makeRunsettingsCompatible) + { + logMessage.Invoke(TestMessageLevel.Warning, CrossPlatEngineResources.OldTestHostIsGettingUsed); + updatedRunSettingsXml = InferRunSettingsHelper.MakeRunsettingsCompatible(runsettingsXml); + } + + return updatedRunSettingsXml; + } + + private void CompatIssueWithVersionCheckAndRunsettings() + { + var properties = this.testHostManager.GetType().GetRuntimeProperties(); + + var versionCheckProperty = properties.FirstOrDefault(p => string.Equals(p.Name, versionCheckPropertyName, StringComparison.OrdinalIgnoreCase)); + if (versionCheckProperty != null) + { + this.versionCheckRequired = (bool)versionCheckProperty.GetValue(this.testHostManager); + } + + var makeRunsettingsCompatibleProperty = properties.FirstOrDefault(p => string.Equals(p.Name, makeRunsettingsCompatiblePropertyName, StringComparison.OrdinalIgnoreCase)); + if (makeRunsettingsCompatibleProperty != null) + { + this.makeRunsettingsCompatible = (bool)makeRunsettingsCompatibleProperty.GetValue(this.testHostManager); + this.makeRunsettingsCompatibleSet = true; + } + } + private void TestHostManagerHostLaunched(object sender, HostProviderEventArgs e) { EqtTrace.Verbose(e.Data); diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/Execution/ExecutionManager.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/Execution/ExecutionManager.cs index 209c29c99d..627f7b9c2e 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/Execution/ExecutionManager.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/Execution/ExecutionManager.cs @@ -87,6 +87,11 @@ public void StartTestRun( this.activeTestRun.RunTests(); } + catch(Exception e) + { + this.testRunEventsHandler.HandleLogMessage(ObjectModel.Logging.TestMessageLevel.Error, e.ToString()); + this.Abort(); + } finally { this.activeTestRun = null; @@ -121,6 +126,11 @@ public void StartTestRun( this.activeTestRun.RunTests(); } + catch(Exception e) + { + this.testRunEventsHandler.HandleLogMessage(ObjectModel.Logging.TestMessageLevel.Error, e.ToString()); + this.Abort(); + } finally { this.activeTestRun = null; diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/Resources.Designer.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/Resources.Designer.cs index a382ed02f6..d52cc9a12e 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/Resources.Designer.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/Resources.Designer.cs @@ -132,7 +132,7 @@ internal static string FailedToLaunchTestHost { return ResourceManager.GetString("FailedToLaunchTestHost", resourceCulture); } } - + /// /// Looks up a localized string similar to Could not find file {0}.. /// @@ -205,6 +205,15 @@ internal static string NoValidSourceFoundForDiscovery { } } + /// + /// Looks up a localized string similar to You are using an older version of Microsoft.NET.Test.Sdk. Kindly move to a version equal or greater than 15.3.0.. + /// + internal static string OldTestHostIsGettingUsed { + get { + return ResourceManager.GetString("OldTestHostIsGettingUsed", resourceCulture); + } + } + /// /// Looks up a localized string similar to , . /// diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/Resources.resx b/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/Resources.resx index 6deb494c5a..8a929007f8 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/Resources.resx +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/Resources.resx @@ -183,4 +183,7 @@ Failed to launch testhost with error: {0} + + You are using an older version of Microsoft.NET.Test.Sdk. Kindly move to a version equal or greater than 15.3.0. + \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.cs.xlf b/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.cs.xlf index 3da2d24bfa..51343cd1d6 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.cs.xlf +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.cs.xlf @@ -181,6 +181,11 @@ Failed to launch testhost with error: {0} + + You are using an older version of Microsoft.NET.Test.Sdk. Kindly move to a version equal or greater than 15.3.0. + You are using an older version of Microsoft.NET.Test.Sdk. Kindly move to a version equal or greater than 15.3.0 + + \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.de.xlf b/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.de.xlf index 5f26e71591..32e1367d26 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.de.xlf +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.de.xlf @@ -181,6 +181,11 @@ Failed to launch testhost with error: {0} + + You are using an older version of Microsoft.NET.Test.Sdk. Kindly move to a version equal or greater than 15.3.0. + You are using an older version of Microsoft.NET.Test.Sdk. Kindly move to a version equal or greater than 15.3.0 + + \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.es.xlf b/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.es.xlf index d84f87c43c..165f1cd329 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.es.xlf +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.es.xlf @@ -181,6 +181,11 @@ Failed to launch testhost with error: {0} + + You are using an older version of Microsoft.NET.Test.Sdk. Kindly move to a version equal or greater than 15.3.0. + You are using an older version of Microsoft.NET.Test.Sdk. Kindly move to a version equal or greater than 15.3.0 + + \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.fr.xlf b/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.fr.xlf index 3684f59198..0dfb5cc3d1 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.fr.xlf +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.fr.xlf @@ -181,6 +181,11 @@ Failed to launch testhost with error: {0} + + You are using an older version of Microsoft.NET.Test.Sdk. Kindly move to a version equal or greater than 15.3.0. + You are using an older version of Microsoft.NET.Test.Sdk. Kindly move to a version equal or greater than 15.3.0 + + \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.it.xlf b/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.it.xlf index 3bfbc8d768..b8cb523592 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.it.xlf +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.it.xlf @@ -181,6 +181,11 @@ Failed to launch testhost with error: {0} + + You are using an older version of Microsoft.NET.Test.Sdk. Kindly move to a version equal or greater than 15.3.0. + You are using an older version of Microsoft.NET.Test.Sdk. Kindly move to a version equal or greater than 15.3.0 + + \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.ja.xlf b/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.ja.xlf index be5c851092..413155bfd4 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.ja.xlf +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.ja.xlf @@ -181,6 +181,11 @@ Failed to launch testhost with error: {0} + + You are using an older version of Microsoft.NET.Test.Sdk. Kindly move to a version equal or greater than 15.3.0. + You are using an older version of Microsoft.NET.Test.Sdk. Kindly move to a version equal or greater than 15.3.0 + + \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.ko.xlf b/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.ko.xlf index 252254258a..d2169ed529 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.ko.xlf +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.ko.xlf @@ -181,6 +181,11 @@ Failed to launch testhost with error: {0} + + You are using an older version of Microsoft.NET.Test.Sdk. Kindly move to a version equal or greater than 15.3.0. + You are using an older version of Microsoft.NET.Test.Sdk. Kindly move to a version equal or greater than 15.3.0 + + \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.pl.xlf b/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.pl.xlf index a6f5d1a242..59a6f1e348 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.pl.xlf +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.pl.xlf @@ -181,6 +181,11 @@ Failed to launch testhost with error: {0} + + You are using an older version of Microsoft.NET.Test.Sdk. Kindly move to a version equal or greater than 15.3.0. + You are using an older version of Microsoft.NET.Test.Sdk. Kindly move to a version equal or greater than 15.3.0 + + \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.pt-BR.xlf b/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.pt-BR.xlf index 0c9d36a48a..a416eb75bd 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.pt-BR.xlf +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.pt-BR.xlf @@ -181,6 +181,11 @@ Failed to launch testhost with error: {0} + + You are using an older version of Microsoft.NET.Test.Sdk. Kindly move to a version equal or greater than 15.3.0. + You are using an older version of Microsoft.NET.Test.Sdk. Kindly move to a version equal or greater than 15.3.0 + + \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.ru.xlf b/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.ru.xlf index 4a55e65b8e..ae70e83282 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.ru.xlf +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.ru.xlf @@ -181,6 +181,11 @@ Failed to launch testhost with error: {0} + + You are using an older version of Microsoft.NET.Test.Sdk. Kindly move to a version equal or greater than 15.3.0. + You are using an older version of Microsoft.NET.Test.Sdk. Kindly move to a version equal or greater than 15.3.0 + + \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.tr.xlf b/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.tr.xlf index 7647ef52d6..3c5a44b74e 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.tr.xlf +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.tr.xlf @@ -181,6 +181,11 @@ Failed to launch testhost with error: {0} + + You are using an older version of Microsoft.NET.Test.Sdk. Kindly move to a version equal or greater than 15.3.0. + You are using an older version of Microsoft.NET.Test.Sdk. Kindly move to a version equal or greater than 15.3.0 + + \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.xlf b/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.xlf index c57a581f32..57b0031555 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.xlf +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.xlf @@ -92,6 +92,11 @@ Failed to launch testhost with error: {0} + + You are using an older version of Microsoft.NET.Test.Sdk. Kindly move to a version equal or greater than 15.3.0. + You are using an older version of Microsoft.NET.Test.Sdk. Kindly move to a version equal or greater than 15.3.0 + + \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.zh-Hans.xlf b/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.zh-Hans.xlf index 58871cb27f..081838cf51 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.zh-Hans.xlf +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.zh-Hans.xlf @@ -181,6 +181,11 @@ Failed to launch testhost with error: {0} + + You are using an older version of Microsoft.NET.Test.Sdk. Kindly move to a version equal or greater than 15.3.0. + You are using an older version of Microsoft.NET.Test.Sdk. Kindly move to a version equal or greater than 15.3.0 + + \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.zh-Hant.xlf b/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.zh-Hant.xlf index ce6d7f427f..0fa75bc912 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.zh-Hant.xlf +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/Resources/xlf/Resources.zh-Hant.xlf @@ -181,6 +181,11 @@ Failed to launch testhost with error: {0} + + You are using an older version of Microsoft.NET.Test.Sdk. Kindly move to a version equal or greater than 15.3.0. + You are using an older version of Microsoft.NET.Test.Sdk. Kindly move to a version equal or greater than 15.3.0 + + \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DotnetTestHostManager.cs b/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DotnetTestHostManager.cs index d544aaa4ea..791fdc848b 100644 --- a/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DotnetTestHostManager.cs +++ b/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DotnetTestHostManager.cs @@ -109,6 +109,11 @@ internal DotnetTestHostManager( /// internal virtual bool IsVersionCheckRequired => !this.hostPackageVersion.StartsWith("15.0.0"); + /// + /// Gets a value indicating whether the test host supports protocol version check + /// + internal bool MakeRunsettingsCompatible => this.hostPackageVersion.StartsWith("15.0.0-preview"); + /// /// Gets or sets the error length for runtime error stream. /// diff --git a/src/Microsoft.TestPlatform.Utilities/InferRunSettingsHelper.cs b/src/Microsoft.TestPlatform.Utilities/InferRunSettingsHelper.cs index 737f5d5f8d..a9b40dac68 100644 --- a/src/Microsoft.TestPlatform.Utilities/InferRunSettingsHelper.cs +++ b/src/Microsoft.TestPlatform.Utilities/InferRunSettingsHelper.cs @@ -4,7 +4,9 @@ namespace Microsoft.VisualStudio.TestPlatform.Utilities { using System; + using System.Collections.Generic; using System.Globalization; + using System.IO; using System.Xml; using System.Xml.XPath; @@ -33,6 +35,90 @@ public class InferRunSettingsHelper private const string TargetFrameworkNodePath = @"/RunSettings/RunConfiguration/TargetFrameworkVersion"; private const string ResultsDirectoryNodePath = @"/RunSettings/RunConfiguration/ResultsDirectory"; + + /// + /// Make runsettings compatible with testhost of version 15.0.0-preview + /// Due to bug https://github.com/Microsoft/vstest/issues/970 we need this function + /// + /// string content of runsettings + /// compatible runsettings + public static string MakeRunsettingsCompatible(string runsettingsXml) + { + var updatedRunSettingsXml = runsettingsXml; + + if (!string.IsNullOrWhiteSpace(runsettingsXml)) + { + using (var stream = new StringReader(runsettingsXml)) + using (var reader = XmlReader.Create(stream, XmlRunSettingsUtilities.ReaderSettings)) + { + var document = new XmlDocument(); + document.Load(reader); + + var runSettingsNavigator = document.CreateNavigator(); + + // Move navigator to RunConfiguration node + if (!runSettingsNavigator.MoveToChild(RunSettingsNodeName, string.Empty) || + !runSettingsNavigator.MoveToChild(RunConfigurationNodeName, string.Empty)) + { + EqtTrace.Error("InferRunSettingsHelper.MakeRunsettingsCompatible: Unable to navigate to RunConfiguration. Current node: " + runSettingsNavigator.LocalName); + } + else if(runSettingsNavigator.HasChildren) + { + var listOfInValidRunConfigurationSettings = new List(); + + // These are the list of valid RunConfiguration setting name which old testhost understand. + var listOfValidRunConfigurationSettings = new HashSet + { + "TargetPlatform", + "TargetFrameworkVersion", + "TestAdaptersPaths", + "ResultsDirectory", + "SolutionDirectory", + "MaxCpuCount", + "DisableParallelization", + "DisableAppDomain" + }; + + // Find all invalid RunConfiguration Settings + runSettingsNavigator.MoveToFirstChild(); + do + { + if(!listOfValidRunConfigurationSettings.Contains(runSettingsNavigator.LocalName)) + { + listOfInValidRunConfigurationSettings.Add(runSettingsNavigator.LocalName); + } + + } while (runSettingsNavigator.MoveToNext()); + + // Delete all invalid RunConfiguration Settings + if (listOfInValidRunConfigurationSettings.Count > 0) + { + if(EqtTrace.IsWarningEnabled) + { + string settingsName = string.Join(", ", listOfInValidRunConfigurationSettings); + EqtTrace.Warning(string.Format("InferRunSettingsHelper.MakeRunsettingsCompatible: Removing the following settings: {0} from RunSettings file. To use those settings please move to latest version of Microsoft.NET.Test.Sdk", settingsName)); + } + + // move navigator to RunConfiguration node + runSettingsNavigator.MoveToParent(); + + foreach(var s in listOfInValidRunConfigurationSettings) + { + var nodePath = RunConfigurationNodePath + "/" + s; + XmlUtilities.RemoveChildNode(runSettingsNavigator, nodePath, s); + } + + runSettingsNavigator.MoveToRoot(); + updatedRunSettingsXml = runSettingsNavigator.OuterXml; + } + } + } + } + + return updatedRunSettingsXml; + } + + /// /// Updates the run settings XML with the specified values. /// @@ -89,7 +175,7 @@ public static void UpdateRunSettingsWithUserProvidedSwitches(XPathNavigator runS /// Value to set public static void UpdateDesignMode(XPathNavigator runSettingsNavigator, bool designModeValue) { - AddNodeIfNotPresent(runSettingsNavigator, DesignModeNodePath, DesignModeNodeName, designModeValue); + AddNodeIfNotPresent(runSettingsNavigator, DesignModeNodePath, DesignModeNodeName, designModeValue); } /// diff --git a/src/Microsoft.TestPlatform.Utilities/XmlUtilities.cs b/src/Microsoft.TestPlatform.Utilities/XmlUtilities.cs index d62e4b4b88..90d195b49e 100644 --- a/src/Microsoft.TestPlatform.Utilities/XmlUtilities.cs +++ b/src/Microsoft.TestPlatform.Utilities/XmlUtilities.cs @@ -101,5 +101,15 @@ internal static void AppendOrModifyChild( } } } + + internal static void RemoveChildNode(XPathNavigator parentNavigator, string nodeXPath, string childName) + { + var childNodeNavigator = parentNavigator.SelectSingleNode(nodeXPath); + if (childNodeNavigator != null) + { + parentNavigator.MoveToChild(childName, string.Empty); + parentNavigator.DeleteSelf(); + } + } } } diff --git a/src/vstest.console/TestPlatformHelpers/TestRequestManager.cs b/src/vstest.console/TestPlatformHelpers/TestRequestManager.cs index b6be96a68f..9144444bee 100644 --- a/src/vstest.console/TestPlatformHelpers/TestRequestManager.cs +++ b/src/vstest.console/TestPlatformHelpers/TestRequestManager.cs @@ -280,14 +280,10 @@ private bool UpdateRunSettingsIfRequired(string runsettingsXml, out string updat var navigator = document.CreateNavigator(); - // If user is already setting DesignMode via runsettings or CLI args; we skip. We also skip if the target framework - // is not known or current run is targeted to netcoreapp (since it is a breaking change; user may be running older - // NET.Test.Sdk; we will remove this constraint in 15.1). + // If user is already setting DesignMode via runsettings or CLI args; we skip. var runConfiguration = XmlRunSettingsUtilities.GetRunConfigurationNode(runsettingsXml); - if (!runConfiguration.DesignModeSet && runConfiguration.TargetFrameworkSet && - runConfiguration.TargetFrameworkVersion.Name.IndexOf("netstandard", StringComparison.OrdinalIgnoreCase) < 0 && - runConfiguration.TargetFrameworkVersion.Name.IndexOf("netcoreapp", StringComparison.OrdinalIgnoreCase) < 0) + if (!runConfiguration.DesignModeSet) { InferRunSettingsHelper.UpdateDesignMode(navigator, this.commandLineOptions.IsDesignMode); settingsUpdated = true; diff --git a/test/Microsoft.TestPlatform.AcceptanceTests/ExecutionTests.cs b/test/Microsoft.TestPlatform.AcceptanceTests/ExecutionTests.cs index 771403719f..75e21b37db 100644 --- a/test/Microsoft.TestPlatform.AcceptanceTests/ExecutionTests.cs +++ b/test/Microsoft.TestPlatform.AcceptanceTests/ExecutionTests.cs @@ -95,6 +95,20 @@ public void TestSessionTimeOutTests(string runnerFramework, string targetFramewo this.StdOutputDoesNotContains("Total tests: 6"); } + [CustomDataTestMethod] + [NETCORETargetFramework] + public void TestPlatformShouldBeCompatibleWithOldTestHost(string runnerFramework, string targetFramework, string targetRuntime) + { + AcceptanceTestBase.SetTestEnvironment(this.testEnvironment, runnerFramework, targetFramework, targetRuntime); + + var assemblyPaths = this.BuildMultipleAssemblyPath("SampleProjectWithOldTestHost.dll").Trim('\"'); + var arguments = PrepareArguments(assemblyPaths, this.GetTestAdapterPath(), string.Empty, this.FrameworkArgValue); + + this.InvokeVsTest(arguments); + + this.ValidateSummaryStatus(1, 0, 0); + } + [CustomDataTestMethod] [NETFullTargetFramework] [NETCORETargetFramework] diff --git a/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Execution/ExecutionManagerTests.cs b/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Execution/ExecutionManagerTests.cs index 38b8ee4c77..ee0fc1652c 100644 --- a/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Execution/ExecutionManagerTests.cs +++ b/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Execution/ExecutionManagerTests.cs @@ -19,6 +19,7 @@ namespace TestPlatform.CrossPlatEngine.UnitTests.Execution using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Engine; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Engine.ClientProtocol; + using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging; using Microsoft.VisualStudio.TestTools.UnitTesting; using Moq; @@ -31,6 +32,7 @@ namespace TestPlatform.CrossPlatEngine.UnitTests.Execution public class ExecutionManagerTests { private ExecutionManager executionManager; + private TestExecutionContext testExecutionContext; [TestInitialize] public void TestInit() @@ -38,6 +40,17 @@ public void TestInit() this.executionManager = new ExecutionManager(); TestPluginCache.Instance = null; + + testExecutionContext = new TestExecutionContext( + frequencyOfRunStatsChangeEvent: 1, + runStatsChangeEventTimeout: TimeSpan.MaxValue, + inIsolation: false, + keepAlive: false, + isDataCollectionEnabled: false, + areTestCaseLevelEventsRequired: false, + hasTestRun: false, + isDebug: false, + testCaseFilter: null); } [TestCleanup] @@ -98,17 +111,6 @@ public void StartTestRunShouldRunTestsInTheProvidedSources() var adapterSourceMap = new Dictionary>(); adapterSourceMap.Add(assemblyLocation, new List { assemblyLocation }); - var testExecutionContext = new TestExecutionContext( - frequencyOfRunStatsChangeEvent: 1, - runStatsChangeEventTimeout: TimeSpan.MaxValue, - inIsolation: false, - keepAlive: false, - isDataCollectionEnabled: false, - areTestCaseLevelEventsRequired: false, - hasTestRun: false, - isDebug: false, - testCaseFilter: null); - var mockTestRunEventsHandler = new Mock(); var isExecutorCalled = false; @@ -147,17 +149,6 @@ public void StartTestRunShouldRunTestsForTheProvidedTests() new TestCase("A.C.M1", new Uri(RunTestsWithSourcesTestsExecutorUri), assemblyLocation) }; - var testExecutionContext = new TestExecutionContext( - frequencyOfRunStatsChangeEvent: 1, - runStatsChangeEventTimeout: TimeSpan.MaxValue, - inIsolation: false, - keepAlive: false, - isDataCollectionEnabled: false, - areTestCaseLevelEventsRequired: false, - hasTestRun: false, - isDebug: false, - testCaseFilter: null); - var mockTestRunEventsHandler = new Mock(); var isExecutorCalled = false; @@ -187,5 +178,31 @@ public void StartTestRunShouldRunTestsForTheProvidedTests() // Also verify that run stats are passed through. mockTestRunEventsHandler.Verify(treh => treh.HandleTestRunStatsChange(It.IsAny()), Times.Once); } + + [TestMethod] + public void StartTestRunShouldAbortTheRunIfAnyExceptionComesForTheProvidedTests() + { + var mockTestRunEventsHandler = new Mock(); + + // Call StartTestRun with faulty runsettings so that it will throw exception + this.executionManager.StartTestRun(new List(), @"0", testExecutionContext, null, mockTestRunEventsHandler.Object); + + // Verify that TestRunComplete get called and error message are getting logged + mockTestRunEventsHandler.Verify(treh => treh.HandleTestRunComplete(It.IsAny(), null, null, null), Times.Once); + mockTestRunEventsHandler.Verify(treh => treh.HandleLogMessage(TestMessageLevel.Error, It.IsAny()), Times.Once); + } + + [TestMethod] + public void StartTestRunShouldAbortTheRunIfAnyExceptionComesForTheProvidedSources() + { + var mockTestRunEventsHandler = new Mock(); + + // Call StartTestRun with faulty runsettings so that it will throw exception + this.executionManager.StartTestRun(new Dictionary>(), @"0", testExecutionContext, null, mockTestRunEventsHandler.Object); + + // Verify that TestRunComplete get called and error message are getting logged + mockTestRunEventsHandler.Verify(treh => treh.HandleTestRunComplete(It.IsAny(), null, null, null), Times.Once); + mockTestRunEventsHandler.Verify(treh => treh.HandleLogMessage(TestMessageLevel.Error, It.IsAny()), Times.Once); + } } } diff --git a/test/Microsoft.TestPlatform.Utilities.UnitTests/InferRunSettingsHelperTests.cs b/test/Microsoft.TestPlatform.Utilities.UnitTests/InferRunSettingsHelperTests.cs index c1d71f4d14..d78f03df73 100644 --- a/test/Microsoft.TestPlatform.Utilities.UnitTests/InferRunSettingsHelperTests.cs +++ b/test/Microsoft.TestPlatform.Utilities.UnitTests/InferRunSettingsHelperTests.cs @@ -264,7 +264,47 @@ public void UpdateDesignModeOrCsiShouldModifyXmlToValueProvided(bool val) Assert.AreEqual(val.ToString(), this.GetValueOf(navigator, "/RunSettings/RunConfiguration/DesignMode")); Assert.AreEqual(val.ToString(), this.GetValueOf(navigator, "/RunSettings/RunConfiguration/CollectSourceInformation")); - } + } + + [TestMethod] + public void MakeRunsettingsCompatibleShouldDeleteNewlyAddedRunConfigurationNode() + { + var settings = @"FalseFalse"; + + var result = InferRunSettingsHelper.MakeRunsettingsCompatible(settings); + + Assert.IsTrue(result.IndexOf("DesignMode", StringComparison.OrdinalIgnoreCase) < 0); + } + + [TestMethod] + public void MakeRunsettingsCompatibleShouldNotDeleteOldRunConfigurationNode() + { + var settings = @" + + False + False + x86 + net46 + dummypath + dummypath + dummypath + 2 + False + False + + "; + + var result = InferRunSettingsHelper.MakeRunsettingsCompatible(settings); + + Assert.IsTrue(result.IndexOf("TargetPlatform", StringComparison.OrdinalIgnoreCase) > 0); + Assert.IsTrue(result.IndexOf("TargetFrameworkVersion", StringComparison.OrdinalIgnoreCase) > 0); + Assert.IsTrue(result.IndexOf("TestAdaptersPaths", StringComparison.OrdinalIgnoreCase) > 0); + Assert.IsTrue(result.IndexOf("ResultsDirectory", StringComparison.OrdinalIgnoreCase) > 0); + Assert.IsTrue(result.IndexOf("SolutionDirectory", StringComparison.OrdinalIgnoreCase) > 0); + Assert.IsTrue(result.IndexOf("MaxCpuCount", StringComparison.OrdinalIgnoreCase) > 0); + Assert.IsTrue(result.IndexOf("DisableParallelization", StringComparison.OrdinalIgnoreCase) > 0); + Assert.IsTrue(result.IndexOf("DisableAppDomain", StringComparison.OrdinalIgnoreCase) > 0); + } #region private methods diff --git a/test/Microsoft.TestPlatform.Utilities.UnitTests/XmlUtilitiesTests.cs b/test/Microsoft.TestPlatform.Utilities.UnitTests/XmlUtilitiesTests.cs index 4395131619..b35d1a4fbd 100644 --- a/test/Microsoft.TestPlatform.Utilities.UnitTests/XmlUtilitiesTests.cs +++ b/test/Microsoft.TestPlatform.Utilities.UnitTests/XmlUtilitiesTests.cs @@ -162,6 +162,36 @@ public void AppendOrModifyChildShouldCreateAnEmptyNewNodeIfInnerXmlPassedInIsNul #endregion + #region AppendOrModifyChild tests + + [TestMethod] + public void RemoveChildNodeShouldNotModifyExistingXmlIfNodeDoesnotExist() + { + var settingsXml = @""; + var navigator = this.GetNavigator(settingsXml); + + navigator.MoveToChild("RunSettings", string.Empty); + + XmlUtilities.RemoveChildNode(navigator, @"/RunSettings/RC", "RC"); + + Assert.AreEqual(settingsXml, navigator.OuterXml); + } + + [TestMethod] + public void RemoveChildNodeShouldRemoveXmlIfExist() + { + var settingsXml = @"abc"; + var navigator = this.GetNavigator(settingsXml); + + navigator.MoveToChild("RunSettings", string.Empty); + + XmlUtilities.RemoveChildNode(navigator, @"/RunSettings/RC", "RC"); + + Assert.AreEqual(@"", navigator.OuterXml); + } + + #endregion + #region private methods private XPathNavigator GetNavigator(string settingsXml) diff --git a/test/TestAssets/SampleProjectWithOldTestHost/SampleProjectWithOldTestHost.csproj b/test/TestAssets/SampleProjectWithOldTestHost/SampleProjectWithOldTestHost.csproj new file mode 100644 index 0000000000..cc188af0ff --- /dev/null +++ b/test/TestAssets/SampleProjectWithOldTestHost/SampleProjectWithOldTestHost.csproj @@ -0,0 +1,23 @@ + + + + + + + + netcoreapp1.0;netcoreapp1.1;netcoreapp2.0 + true + false + + + + + + $(MSTestFrameworkVersion) + + + $(MSTestAdapterVersion) + + + + diff --git a/test/TestAssets/SampleProjectWithOldTestHost/UnitTest1.cs b/test/TestAssets/SampleProjectWithOldTestHost/UnitTest1.cs new file mode 100644 index 0000000000..4df22575dc --- /dev/null +++ b/test/TestAssets/SampleProjectWithOldTestHost/UnitTest1.cs @@ -0,0 +1,13 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace SampleProjectWithOldTestHost +{ + [TestClass] + public class UnitTest1 + { + [TestMethod] + public void TestMethod1() + { + } + } +} diff --git a/test/vstest.console.UnitTests/TestPlatformHelpers/TestRequestManagerTests.cs b/test/vstest.console.UnitTests/TestPlatformHelpers/TestRequestManagerTests.cs index 0ed135d0e1..c842f19770 100644 --- a/test/vstest.console.UnitTests/TestPlatformHelpers/TestRequestManagerTests.cs +++ b/test/vstest.console.UnitTests/TestPlatformHelpers/TestRequestManagerTests.cs @@ -565,32 +565,6 @@ public void DiscoverTestsShouldNotUpdateDesignModeIfUserHasSetDesignModeInRunSet tp => tp.CreateDiscoveryRequest(It.Is(dc => dc.RunSettings.Contains(designmode)), It.IsAny())); } - [TestMethod] - public void DiscoverTestsShouldNotUpdateDesignModeIfTargetFrameworkIsNotSetInRunSettings() - { - var runsettings = ""; - var discoveryPayload = CreateDiscoveryPayload(runsettings); - - this.testRequestManager.DiscoverTests(discoveryPayload, new Mock().Object, It.IsAny()); - - var designmode = "DesignMode"; - this.mockTestPlatform.Verify( - tp => tp.CreateDiscoveryRequest(It.Is(dc => !dc.RunSettings.Contains(designmode)), It.IsAny())); - } - - [TestMethod] - public void DiscoverTestsShouldNotUpdateDesignModeIfTargetFrameworkIsSetToNetCoreInRunSettings() - { - var runsettings = ".NETCoreApp,Version=v1.0"; - var discoveryPayload = CreateDiscoveryPayload(runsettings); - - this.testRequestManager.DiscoverTests(discoveryPayload, new Mock().Object, It.IsAny()); - - var designmode = "DesignMode"; - this.mockTestPlatform.Verify( - tp => tp.CreateDiscoveryRequest(It.Is(dc => !dc.RunSettings.Contains(designmode)), It.IsAny())); - } - [DataTestMethod] [DataRow(true)] [DataRow(false)]