From 46a08964798d1c539c46598a4f8af5d8585b0f97 Mon Sep 17 00:00:00 2001 From: Marius Ungureanu Date: Fri, 15 Jul 2022 20:48:09 +0300 Subject: [PATCH 1/7] Allow DotnetHostPath to contain env vars This is useful for controlling the paths to the dotnet host path when you're running `dotnet test src/tests/TestProjectA.csproj` to avoid duplicating the runsettings --- src/Microsoft.TestPlatform.Utilities/ClientUtilities.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Microsoft.TestPlatform.Utilities/ClientUtilities.cs b/src/Microsoft.TestPlatform.Utilities/ClientUtilities.cs index d671781bdd..e845863727 100644 --- a/src/Microsoft.TestPlatform.Utilities/ClientUtilities.cs +++ b/src/Microsoft.TestPlatform.Utilities/ClientUtilities.cs @@ -16,6 +16,7 @@ public static class ClientUtilities { private const string TestSettingsFileXPath = "RunSettings/MSTest/SettingsFile"; private const string ResultsDirectoryXPath = "RunSettings/RunConfiguration/ResultsDirectory"; + private const string DotnetHostPathXPath = "RunSettings/RunConfiguration/DotnetHostPath"; private const string RunsettingsDirectory = "RunSettingsDirectory"; /// @@ -43,6 +44,12 @@ public static void FixRelativePathsInRunSettings(XmlDocument xmlDocument, string { FixNodeFilePath(resultsDirectoryNode, root); } + + var dotnetHostPathNode = xmlDocument.SelectSingleNode(DotnetHostPathXPath); + if (dotnetHostPathNode != null) + { + FixNodeFilePath(dotnetHostPathNode, root); + } } private static void AddRunSettingsDirectoryNode(XmlDocument doc, string path) From de7c94c236b24406d47d1b714125f077cd06993a Mon Sep 17 00:00:00 2001 From: Marius Ungureanu Date: Fri, 15 Jul 2022 20:53:20 +0300 Subject: [PATCH 2/7] Another place where it should expand --- .../RunSettings/RunConfiguration.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.TestPlatform.ObjectModel/RunSettings/RunConfiguration.cs b/src/Microsoft.TestPlatform.ObjectModel/RunSettings/RunConfiguration.cs index 05d28b5e48..c237e57644 100644 --- a/src/Microsoft.TestPlatform.ObjectModel/RunSettings/RunConfiguration.cs +++ b/src/Microsoft.TestPlatform.ObjectModel/RunSettings/RunConfiguration.cs @@ -891,7 +891,14 @@ public static RunConfiguration FromXml(XmlReader reader) case "DotNetHostPath": XmlRunSettingsUtilities.ThrowOnHasAttributes(reader); - runConfiguration.DotnetHostPath = reader.ReadElementContentAsString(); + + string? dotnetHostPath = reader.ReadElementContentAsString(); + +#if !NETSTANDARD1_0 + dotnetHostPath = Environment.ExpandEnvironmentVariables(dotnetHostPath); +#endif + + runConfiguration.DotnetHostPath = dotnetHostPath; break; case "TreatNoTestsAsError": XmlRunSettingsUtilities.ThrowOnHasAttributes(reader); From 7a906880f57989c2b4de6d28dd3447e278360736 Mon Sep 17 00:00:00 2001 From: Marius Ungureanu Date: Fri, 15 Jul 2022 21:10:42 +0300 Subject: [PATCH 3/7] Fix formatting --- .../RunSettings/RunConfiguration.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Microsoft.TestPlatform.ObjectModel/RunSettings/RunConfiguration.cs b/src/Microsoft.TestPlatform.ObjectModel/RunSettings/RunConfiguration.cs index c237e57644..66d1f22a17 100644 --- a/src/Microsoft.TestPlatform.ObjectModel/RunSettings/RunConfiguration.cs +++ b/src/Microsoft.TestPlatform.ObjectModel/RunSettings/RunConfiguration.cs @@ -891,7 +891,6 @@ public static RunConfiguration FromXml(XmlReader reader) case "DotNetHostPath": XmlRunSettingsUtilities.ThrowOnHasAttributes(reader); - string? dotnetHostPath = reader.ReadElementContentAsString(); #if !NETSTANDARD1_0 From 4a92613170dbbd215d88b2a4925f41a3af2be1bf Mon Sep 17 00:00:00 2001 From: Marius Ungureanu Date: Fri, 15 Jul 2022 23:36:26 +0300 Subject: [PATCH 4/7] Fix casing to match all the other properties --- .../Hosting/DotnetTestHostManagerTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Microsoft.TestPlatform.TestHostProvider.UnitTests/Hosting/DotnetTestHostManagerTests.cs b/test/Microsoft.TestPlatform.TestHostProvider.UnitTests/Hosting/DotnetTestHostManagerTests.cs index c3cf1a5d7a..aacc774242 100644 --- a/test/Microsoft.TestPlatform.TestHostProvider.UnitTests/Hosting/DotnetTestHostManagerTests.cs +++ b/test/Microsoft.TestPlatform.TestHostProvider.UnitTests/Hosting/DotnetTestHostManagerTests.cs @@ -289,7 +289,7 @@ public void GetTestHostProcessStartInfoShouldUseDotnetHostPathFromRunsettings() var dotnetHostPath = @"C:\dotnet.exe"; _mockFileHelper.Setup(ph => ph.Exists("testhost.dll")).Returns(true); _mockEnvironment.Setup(ev => ev.OperatingSystem).Returns(PlatformOperatingSystem.Windows); - _dotnetHostManager.Initialize(_mockMessageLogger.Object, $"{dotnetHostPath}"); + _dotnetHostManager.Initialize(_mockMessageLogger.Object, $"{dotnetHostPath}"); var startInfo = GetDefaultStartInfo(); StringAssert.Contains(startInfo.FileName, dotnetHostPath); From d933215a6fef25b1078cace51cd4e49d8b3b621f Mon Sep 17 00:00:00 2001 From: Marius Ungureanu Date: Sat, 16 Jul 2022 03:22:17 +0300 Subject: [PATCH 5/7] Use upper-case as expected --- src/Microsoft.TestPlatform.Utilities/ClientUtilities.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.TestPlatform.Utilities/ClientUtilities.cs b/src/Microsoft.TestPlatform.Utilities/ClientUtilities.cs index e845863727..d637998729 100644 --- a/src/Microsoft.TestPlatform.Utilities/ClientUtilities.cs +++ b/src/Microsoft.TestPlatform.Utilities/ClientUtilities.cs @@ -16,7 +16,7 @@ public static class ClientUtilities { private const string TestSettingsFileXPath = "RunSettings/MSTest/SettingsFile"; private const string ResultsDirectoryXPath = "RunSettings/RunConfiguration/ResultsDirectory"; - private const string DotnetHostPathXPath = "RunSettings/RunConfiguration/DotnetHostPath"; + private const string DotnetHostPathXPath = "RunSettings/RunConfiguration/DotNetHostPath"; private const string RunsettingsDirectory = "RunSettingsDirectory"; /// From f0d6c140139322dc0e36140e1ac6f4c9cdf3393a Mon Sep 17 00:00:00 2001 From: Marius Ungureanu Date: Sat, 16 Jul 2022 03:22:36 +0300 Subject: [PATCH 6/7] Update DotnetTestHostManagerTests.cs --- .../Hosting/DotnetTestHostManagerTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Microsoft.TestPlatform.TestHostProvider.UnitTests/Hosting/DotnetTestHostManagerTests.cs b/test/Microsoft.TestPlatform.TestHostProvider.UnitTests/Hosting/DotnetTestHostManagerTests.cs index aacc774242..c3cf1a5d7a 100644 --- a/test/Microsoft.TestPlatform.TestHostProvider.UnitTests/Hosting/DotnetTestHostManagerTests.cs +++ b/test/Microsoft.TestPlatform.TestHostProvider.UnitTests/Hosting/DotnetTestHostManagerTests.cs @@ -289,7 +289,7 @@ public void GetTestHostProcessStartInfoShouldUseDotnetHostPathFromRunsettings() var dotnetHostPath = @"C:\dotnet.exe"; _mockFileHelper.Setup(ph => ph.Exists("testhost.dll")).Returns(true); _mockEnvironment.Setup(ev => ev.OperatingSystem).Returns(PlatformOperatingSystem.Windows); - _dotnetHostManager.Initialize(_mockMessageLogger.Object, $"{dotnetHostPath}"); + _dotnetHostManager.Initialize(_mockMessageLogger.Object, $"{dotnetHostPath}"); var startInfo = GetDefaultStartInfo(); StringAssert.Contains(startInfo.FileName, dotnetHostPath); From f086126a4c07f7de9773ad3ca580ab0016543457 Mon Sep 17 00:00:00 2001 From: Marius Ungureanu Date: Tue, 2 Aug 2022 16:19:39 +0300 Subject: [PATCH 7/7] Retrofit existing test to also handle DotNetHostPAth expansion --- .../ClientUtilitiesTests.cs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/test/Microsoft.TestPlatform.Utilities.UnitTests/ClientUtilitiesTests.cs b/test/Microsoft.TestPlatform.Utilities.UnitTests/ClientUtilitiesTests.cs index 9807fed377..ecb2407bcf 100644 --- a/test/Microsoft.TestPlatform.Utilities.UnitTests/ClientUtilitiesTests.cs +++ b/test/Microsoft.TestPlatform.Utilities.UnitTests/ClientUtilitiesTests.cs @@ -195,7 +195,7 @@ public void FixRelativePathsInRunSettingsShouldExpandEnvironmentVariable() Environment.SetEnvironmentVariable("TEST_TEMP", Path.GetTempPath()); // using TEST_TEMP because TMP or TEMP, or HOME are not defined across all tested OSes // Using \\ instead of platform specifc path separator does not matter, because the paths are not interpreted by the OS. - var runSettingsXml = "%TEST_TEMP%\\results"; + var runSettingsXml = "%TEST_TEMP%\\results%TEST_TEMP%\\hostpath"; var doc = new XmlDocument(); doc.LoadXml(runSettingsXml); @@ -206,12 +206,15 @@ public void FixRelativePathsInRunSettingsShouldExpandEnvironmentVariable() var finalSettingsXml = doc.OuterXml; - var expectedPath = $"{Environment.GetEnvironmentVariable("TEST_TEMP")}\\results"; + var expectedResultsPath = $"{Environment.GetEnvironmentVariable("TEST_TEMP")}\\results"; + var expectedDotNetHostPath = $"{Environment.GetEnvironmentVariable("TEST_TEMP")}\\hostpath"; var expectedSettingsXml = string.Concat( "", - expectedPath, - "", + expectedResultsPath, + "", + expectedDotNetHostPath, + "", Path.GetDirectoryName(currentAssemblyLocation), "");