Skip to content

Commit

Permalink
Skip invalid additional probing paths
Browse files Browse the repository at this point in the history
dotnet/sdk#1306 brought in templated probing paths into the runtime.config.json.  These are breaking dotnet test because we assume the paths are valid.

Skipping any invalid paths by catching exceptions from Path.Combine.

Fixes microsoft#847
  • Loading branch information
eerhardt committed Jun 8, 2017
1 parent 59e046d commit fd8f10b
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,18 @@ private string GetTestHostPath(string runtimeConfigDevPath, string depsFilePath,
foreach (var x in additionalProbingPaths)
{
EqtTrace.Verbose("DotnetTestHostmanager: Looking for path {0} in folder {1}", testHostPath, x.ToString());
string testHostFullPath = Path.Combine(x.ToString(), testHostPath);
string testHostFullPath;
try
{
testHostFullPath = Path.Combine(x.ToString(), testHostPath);
}
catch (ArgumentException)
{
// https://github.com/Microsoft/vstest/issues/847
// skip any invalid paths and continue checking the others
continue;
}

if (this.fileHelper.Exists(testHostFullPath))
{
return testHostFullPath;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,72 @@ public void GetTestHostProcessStartInfoShouldIncludeTestHostPathFromSourceDirect
Assert.IsTrue(startInfo.Arguments.Contains(testHostPath));
}

[TestMethod]
public void GetTestHostProcessStartInfoShouldSkipInvalidAdditionalProbingPaths()
{
// Absolute path to the source directory
var sourcePath = Path.Combine($"{Path.DirectorySeparatorChar}tmp", "test.dll");

string runtimeConfigFileContent =
@"{
""runtimeOptions"": {
""additionalProbingPaths"": [
""C:\\Users\\bob\\.dotnet\\store\\|arch|\\|tfm|"",
""C:\\packages""
]
}
}";

string depsFileContent =
@"{
""runtimeTarget"": {
""name"": "".NETCoreApp,Version=v1.0"",
""signature"": ""8f25843f8e35a3e80ef4ae98b95117ea5c468b3f""
},
""compilationOptions"": {},
""targets"": {
"".NETCoreApp,Version=v1.0"": {
""microsoft.testplatform.testhost/15.0.0-Dev"": {
""dependencies"": {
""Microsoft.TestPlatform.ObjectModel"": ""15.0.0-Dev"",
""Newtonsoft.Json"": ""9.0.1""
},
""runtime"": {
""lib/netstandard1.5/Microsoft.TestPlatform.CommunicationUtilities.dll"": { },
""lib/netstandard1.5/Microsoft.TestPlatform.CrossPlatEngine.dll"": { },
""lib/netstandard1.5/Microsoft.VisualStudio.TestPlatform.Common.dll"": { },
""lib/netstandard1.5/testhost.dll"": { }
}
}
}
},
""libraries"": {
""microsoft.testplatform.testhost/15.0.0-Dev"": {
""type"": ""package"",
""serviceable"": true,
""sha512"": ""sha512-enO8sZmjbhXOfiZ6hV2ncaknaHnQbrGVsHUJzzu2Dmoh4fHFro4BF1Y4+sb4LOQhu4b3DFYPRj1ncd1RQK6HmQ=="",
""path"": ""microsoft.testplatform.testhost/15.0.0-Dev"",
""hashPath"": ""microsoft.testplatform.testhost.15.0.0-Dev""
}
}
}";

MemoryStream runtimeConfigStream = new MemoryStream(Encoding.UTF8.GetBytes(runtimeConfigFileContent));
this.mockFileHelper.Setup(ph => ph.GetStream("\\tmp\\test.runtimeconfig.dev.json", FileMode.Open, FileAccess.ReadWrite)).Returns(runtimeConfigStream);
this.mockFileHelper.Setup(ph => ph.Exists("\\tmp\\test.runtimeconfig.dev.json")).Returns(true);

MemoryStream depsFileStream = new MemoryStream(Encoding.UTF8.GetBytes(depsFileContent));
this.mockFileHelper.Setup(ph => ph.GetStream("\\tmp\\test.deps.json", FileMode.Open, FileAccess.ReadWrite)).Returns(depsFileStream);
this.mockFileHelper.Setup(ph => ph.Exists("\\tmp\\test.deps.json")).Returns(true);

string testHostFullPath = @"C:\packages\microsoft.testplatform.testhost/15.0.0-Dev\lib/netstandard1.5/testhost.dll";
this.mockFileHelper.Setup(ph => ph.Exists(testHostFullPath)).Returns(true);

var startInfo = this.dotnetHostManager.GetTestHostProcessStartInfo(new[] { sourcePath }, null, this.defaultConnectionInfo);

Assert.IsTrue(startInfo.Arguments.Contains(testHostFullPath));
}

[TestMethod]
public async Task DotNetCoreErrorMessageShouldBeReadAsynchronouslyAsync()
{
Expand Down

0 comments on commit fd8f10b

Please sign in to comment.