Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow DotNetHostPath to contain env vars #3858

Merged
merged 7 commits into from
Aug 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -891,7 +891,13 @@ 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);
Expand Down
7 changes: 7 additions & 0 deletions src/Microsoft.TestPlatform.Utilities/ClientUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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";

/// <summary>
Expand Down Expand Up @@ -43,6 +44,12 @@ public static void FixRelativePathsInRunSettings(XmlDocument xmlDocument, string
{
FixNodeFilePath(resultsDirectoryNode, root);
}

var dotnetHostPathNode = xmlDocument.SelectSingleNode(DotnetHostPathXPath);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests are failing because SelectSingleNode is likely case sensitive?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No test is failing on CI. Is there any change you would have forgot to push?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check previous CI runs, the problem was with the casing. If I used <RunConfiguration><DotnetHostPath> instead of DotNetHostPath it would break.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! We are planning on improving the way we read/write values in runsettings so I guess this could be handled here.

if (dotnetHostPathNode != null)
{
FixNodeFilePath(dotnetHostPathNode, root);
}
}

private static void AddRunSettingsDirectoryNode(XmlDocument doc, string path)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "<RunSettings><RunConfiguration><ResultsDirectory>%TEST_TEMP%\\results</ResultsDirectory></RunConfiguration></RunSettings>";
var runSettingsXml = "<RunSettings><RunConfiguration><ResultsDirectory>%TEST_TEMP%\\results</ResultsDirectory><DotNetHostPath>%TEST_TEMP%\\hostpath</DotNetHostPath></RunConfiguration></RunSettings>";

var doc = new XmlDocument();
doc.LoadXml(runSettingsXml);
Expand All @@ -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(
"<RunSettings><RunConfiguration><ResultsDirectory>",
expectedPath,
"</ResultsDirectory></RunConfiguration><RunSettingsDirectory>",
expectedResultsPath,
"</ResultsDirectory><DotNetHostPath>",
expectedDotNetHostPath,
"</DotNetHostPath></RunConfiguration><RunSettingsDirectory>",
Path.GetDirectoryName(currentAssemblyLocation),
"</RunSettingsDirectory></RunSettings>");

Expand Down