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

Suggest publish for running on an isolated machine #1726

Merged
merged 3 commits into from
Aug 13, 2018
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 @@ -214,17 +214,8 @@ public virtual TestProcessStartInfo GetTestHostProcessStartInfo(
var runtimeConfigDevPath = Path.Combine(sourceDirectory, string.Concat(sourceFile, ".runtimeconfig.dev.json"));
var testHostPath = this.GetTestHostPath(runtimeConfigDevPath, depsFilePath, sourceDirectory);

if (this.fileHelper.Exists(testHostPath))
{
EqtTrace.Verbose("DotnetTestHostmanager: Full path of testhost.dll is {0}", testHostPath);
args += " " + testHostPath.AddDoubleQuote() + " " + connectionInfo.ToCommandLineOptions();
}
else
{
string message = string.Format(CultureInfo.CurrentCulture, Resources.NoTestHostFileExist, sourcePath);
EqtTrace.Verbose("DotnetTestHostmanager: " + message);
throw new FileNotFoundException(message);
}
EqtTrace.Verbose("DotnetTestHostmanager: Full path of testhost.dll is {0}", testHostPath);
args += " " + testHostPath.AddDoubleQuote() + " " + connectionInfo.ToCommandLineOptions();

// Create a additional probing path args with Nuget.Client
// args += "--additionalprobingpath xxx"
Expand Down Expand Up @@ -345,74 +336,90 @@ private string GetTestHostPath(string runtimeConfigDevPath, string depsFilePath,
{
string testHostPackageName = "microsoft.testplatform.testhost";
string testHostPath = string.Empty;
string errorMessage = null;

if (this.fileHelper.Exists(runtimeConfigDevPath) && this.fileHelper.Exists(depsFilePath))
if (this.fileHelper.Exists(depsFilePath))
{
EqtTrace.Verbose("DotnetTestHostmanager: Reading file {0} to get path of testhost.dll", depsFilePath);

// Get testhost relative path
using (var stream = this.fileHelper.GetStream(depsFilePath, FileMode.Open, FileAccess.Read))
if (this.fileHelper.Exists(runtimeConfigDevPath))
{
var context = new DependencyContextJsonReader().Read(stream);
var testhostPackage = context.RuntimeLibraries.Where(lib => lib.Name.Equals(testHostPackageName, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
EqtTrace.Verbose("DotnetTestHostmanager: Reading file {0} to get path of testhost.dll", depsFilePath);

if (testhostPackage != null)
// Get testhost relative path
using (var stream = this.fileHelper.GetStream(depsFilePath, FileMode.Open, FileAccess.Read))
{
foreach (var runtimeAssemblyGroup in testhostPackage.RuntimeAssemblyGroups)
var context = new DependencyContextJsonReader().Read(stream);
var testhostPackage = context.RuntimeLibraries.Where(lib => lib.Name.Equals(testHostPackageName, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();

if (testhostPackage != null)
{
foreach (var path in runtimeAssemblyGroup.AssetPaths)
foreach (var runtimeAssemblyGroup in testhostPackage.RuntimeAssemblyGroups)
{
if (path.EndsWith("testhost.dll", StringComparison.OrdinalIgnoreCase))
foreach (var path in runtimeAssemblyGroup.AssetPaths)
{
testHostPath = path;
break;
if (path.EndsWith("testhost.dll", StringComparison.OrdinalIgnoreCase))
{
testHostPath = path;
break;
}
}
}
}

testHostPath = Path.Combine(testhostPackage.Path, testHostPath);
this.hostPackageVersion = testhostPackage.Version;
EqtTrace.Verbose("DotnetTestHostmanager: Relative path of testhost.dll with respect to package folder is {0}", testHostPath);
testHostPath = Path.Combine(testhostPackage.Path, testHostPath);
this.hostPackageVersion = testhostPackage.Version;
EqtTrace.Verbose("DotnetTestHostmanager: Relative path of testhost.dll with respect to package folder is {0}", testHostPath);
}
}
}

// Get probing path
using (StreamReader file = new StreamReader(this.fileHelper.GetStream(runtimeConfigDevPath, FileMode.Open, FileAccess.Read)))
using (JsonTextReader reader = new JsonTextReader(file))
{
JObject context = (JObject)JToken.ReadFrom(reader);
JObject runtimeOptions = (JObject)context.GetValue("runtimeOptions");
JToken additionalProbingPaths = runtimeOptions.GetValue("additionalProbingPaths");
foreach (var x in additionalProbingPaths)
// Get probing path
using (StreamReader file = new StreamReader(this.fileHelper.GetStream(runtimeConfigDevPath, FileMode.Open, FileAccess.Read)))
using (JsonTextReader reader = new JsonTextReader(file))
{
EqtTrace.Verbose("DotnetTestHostmanager: Looking for path {0} in folder {1}", testHostPath, x.ToString());
string testHostFullPath;
try
{
testHostFullPath = Path.Combine(x.ToString(), testHostPath);
}
catch (ArgumentException)
JObject context = (JObject)JToken.ReadFrom(reader);
JObject runtimeOptions = (JObject)context.GetValue("runtimeOptions");
JToken additionalProbingPaths = runtimeOptions.GetValue("additionalProbingPaths");
foreach (var x in additionalProbingPaths)
{
// https://github.com/Microsoft/vstest/issues/847
// skip any invalid paths and continue checking the others
continue;
}
EqtTrace.Verbose("DotnetTestHostmanager: Looking for path {0} in folder {1}", testHostPath, x.ToString());
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;
if (this.fileHelper.Exists(testHostFullPath))
{
return testHostFullPath;
}
}
}
}
}
else
{
errorMessage = string.Format(CultureInfo.CurrentCulture, Resources.UnableToFindDepsFile, depsFilePath);
}

// If we are here it means it couldnt resolve testhost.dll from nuget chache.
// If we are here it means it couldnt resolve testhost.dll from nuget cache.
// Try resolving testhost from output directory of test project. This is required if user has published the test project
// and is running tests in an isolated machine. A second scenario is self test: test platform unit tests take a project
// dependency on testhost (instead of nuget dependency), this drops testhost to output path.
testHostPath = Path.Combine(sourceDirectory, "testhost.dll");
EqtTrace.Verbose("DotnetTestHostManager: Assume published test project, with test host path = {0}.", testHostPath);

if (!this.fileHelper.Exists(testHostPath))
Copy link
Contributor

Choose a reason for hiding this comment

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

seems like we could simply replace the message above at line 216 with this new resource?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We are caching the error above, and then throwing that.

{
// If deps file is not found, suggest adding Microsoft.Net.Test.Sdk reference to the project
// Otherwise, suggest publishing the test project so that test host gets dropped next to the test source.
errorMessage = errorMessage ?? string.Format(CultureInfo.CurrentCulture, Resources.SuggestPublishTestProject, testHostPath);
throw new TestPlatformException(errorMessage);
}

return testHostPath;
}
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,10 @@
<value>Multiple versions of same extension found. Selecting the highest version.
{0}</value>
</data>
<data name="NoTestHostFileExist" xml:space="preserve">
<value>Unable to find tests for {0}. Make sure test project has a nuget reference of package "Microsoft.NET.Test.Sdk" and framework version settings are appropriate. Rerun with /diag option to diagnose further.</value>
<data name="UnableToFindDepsFile" xml:space="preserve">
<value>Unable to find {0}. Make sure test project has a nuget reference of package "Microsoft.NET.Test.Sdk".</value>
</data>
<data name="SuggestPublishTestProject" xml:space="preserve">
<value>Unable to find {0}. Please publish your test project and retry.</value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,23 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="cs" original="../Resources.resx" build-num="1496413687">
<body>
<trans-unit id="NoTestHostFileExist">
<source>Unable to find tests for {0}. Make sure test project has a nuget reference of package "Microsoft.NET.Test.Sdk" and framework version settings are appropriate. Rerun with /diag option to diagnose further.</source>
<target state="translated">Nepovedlo se najít testy pro {0}. Ověřte, jestli má testovací projekt odkaz na balíček nuget Microsoft.NET.Test.Sdk a jestli je nastavení verze rozhraní správné. Při dalším spuštění použijte možnost with /diag, aby se vypsaly diagnostické informace.</target>
<note />
</trans-unit>
<trans-unit id="MultipleFileVersions">
<source>Multiple versions of same extension found. Selecting the highest version.
{0}</source>
<target state="translated">Našlo se více verzí stejného rozšíření. Vybere se nejvyšší verze.
{0}</target>
<note />
</trans-unit>
<trans-unit id="UnableToFindDepsFile">
<source>Unable to find {0}. Make sure test project has a nuget reference of package "Microsoft.NET.Test.Sdk".</source>
<target state="new">Unable to find {0}. Make sure test project has a nuget reference of package "Microsoft.NET.Test.Sdk".</target>
<note></note>
</trans-unit>
<trans-unit id="SuggestPublishTestProject">
<source>Unable to find {0}. Please publish your test project and retry.</source>
<target state="new">Unable to find {0}. Please publish your test project and retry.</target>
<note></note>
</trans-unit>
</body>
</file>
</xliff>
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,23 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="de" original="../Resources.resx" build-num="-1605532954">
<body>
<trans-unit id="NoTestHostFileExist">
<source>Unable to find tests for {0}. Make sure test project has a nuget reference of package "Microsoft.NET.Test.Sdk" and framework version settings are appropriate. Rerun with /diag option to diagnose further.</source>
<target state="translated">Für "{0}" wurden keine Tests gefunden. Stellen Sie sicher, dass das Testprojekt einen NuGet-Verweis des Pakets "Microsoft.NET.Test.Sdk" aufweist und geeignete Einstellungen für die Frameworkversion verwendet. Führen Sie den Vorgang zur weiteren Diagnose anschließend mit der Option "/diag" erneut aus.</target>
<note />
</trans-unit>
<trans-unit id="MultipleFileVersions">
<source>Multiple versions of same extension found. Selecting the highest version.
{0}</source>
<target state="translated">Es wurden mehrere Versionen derselben Erweiterung gefunden. Die höchste Version wird ausgewählt.
{0}</target>
<note />
</trans-unit>
<trans-unit id="UnableToFindDepsFile">
<source>Unable to find {0}. Make sure test project has a nuget reference of package "Microsoft.NET.Test.Sdk".</source>
<target state="new">Unable to find {0}. Make sure test project has a nuget reference of package "Microsoft.NET.Test.Sdk".</target>
<note></note>
</trans-unit>
<trans-unit id="SuggestPublishTestProject">
<source>Unable to find {0}. Please publish your test project and retry.</source>
<target state="new">Unable to find {0}. Please publish your test project and retry.</target>
<note></note>
</trans-unit>
</body>
</file>
</xliff>
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,23 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="es" original="../Resources.resx" build-num="1392533617">
<body>
<trans-unit id="NoTestHostFileExist">
<source>Unable to find tests for {0}. Make sure test project has a nuget reference of package "Microsoft.NET.Test.Sdk" and framework version settings are appropriate. Rerun with /diag option to diagnose further.</source>
<target state="translated">No se encuentran pruebas para {0}. Asegúrese de que el proyecto de prueba tiene una referencia NuGet del paquete "Microsoft.NET.Test.Sdk" y de que la configuración de la versión de Framework es correcta. Vuelva a ejecutar con la opción /diag para realizar un diagnóstico más detallado.</target>
<note />
</trans-unit>
<trans-unit id="MultipleFileVersions">
<source>Multiple versions of same extension found. Selecting the highest version.
{0}</source>
<target state="translated">Se encontraron varias versiones de la misma extensión. Seleccionando la versión más alta.
{0}</target>
<note />
</trans-unit>
<trans-unit id="UnableToFindDepsFile">
<source>Unable to find {0}. Make sure test project has a nuget reference of package "Microsoft.NET.Test.Sdk".</source>
<target state="new">Unable to find {0}. Make sure test project has a nuget reference of package "Microsoft.NET.Test.Sdk".</target>
<note></note>
</trans-unit>
<trans-unit id="SuggestPublishTestProject">
<source>Unable to find {0}. Please publish your test project and retry.</source>
<target state="new">Unable to find {0}. Please publish your test project and retry.</target>
<note></note>
</trans-unit>
</body>
</file>
</xliff>
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,23 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="fr" original="../Resources.resx" build-num="-1747068205">
<body>
<trans-unit id="NoTestHostFileExist">
<source>Unable to find tests for {0}. Make sure test project has a nuget reference of package "Microsoft.NET.Test.Sdk" and framework version settings are appropriate. Rerun with /diag option to diagnose further.</source>
<target state="translated">Tests introuvables pour {0}. Vérifiez que le projet de test a une référence NuGet de package "Microsoft.NET.Test.Sdk" et que les paramètres de version du framework sont corrects. Relancez l’exécution avec l'option /diag pour effectuer un diagnostic plus poussé.</target>
<note />
</trans-unit>
<trans-unit id="MultipleFileVersions">
<source>Multiple versions of same extension found. Selecting the highest version.
{0}</source>
<target state="translated">Plusieurs versions de la même extension ont été trouvées. Sélection de la version la plus élevée.
{0}</target>
<note />
</trans-unit>
<trans-unit id="UnableToFindDepsFile">
<source>Unable to find {0}. Make sure test project has a nuget reference of package "Microsoft.NET.Test.Sdk".</source>
<target state="new">Unable to find {0}. Make sure test project has a nuget reference of package "Microsoft.NET.Test.Sdk".</target>
<note></note>
</trans-unit>
<trans-unit id="SuggestPublishTestProject">
<source>Unable to find {0}. Please publish your test project and retry.</source>
<target state="new">Unable to find {0}. Please publish your test project and retry.</target>
<note></note>
</trans-unit>
</body>
</file>
</xliff>
Loading