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

Test adapter loading strategy #3380

Merged
merged 10 commits into from
Feb 18, 2022
Prev Previous commit
Next Next commit
PR fixes.
  • Loading branch information
Haplois committed Feb 17, 2022
commit 98d2fe37be6a387f3e63588fd024a8deec4becf9
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,10 @@ public static IEnumerable<string> GetTestAdaptersPaths(string runSettings)
/// </summary>
/// <param name="runSettings">Test run settings</param>
/// <returns>Test adapter loading strategy</returns>
internal static TestAdapterLoadingStrategy GetLoadingStrategy(string runSettings) {
internal static TestAdapterLoadingStrategy GetLoadingStrategy(string runSettings)
{
var runConfiguration = XmlRunSettingsUtilities.GetRunConfigurationNode(runSettings);

return runConfiguration?.TestAdapterLoadingStrategy ?? TestAdapterLoadingStrategy.Default;
return runConfiguration.TestAdapterLoadingStrategy;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -502,15 +502,15 @@ public override XmlElement ToXml()
root.AppendChild(testAdaptersPaths);
}

if(this.TestAdapterLoadingStrategy != TestAdapterLoadingStrategy.Default)
if (this.TestAdapterLoadingStrategy != TestAdapterLoadingStrategy.Default)
{
XmlElement adapterLoadingStrategy = doc.CreateElement("TestAdapterLoadingStrategy");
adapterLoadingStrategy.InnerXml = this.TestAdapterLoadingStrategy.ToString();
root.AppendChild(adapterLoadingStrategy);
}

XmlElement treatTestAdapterErrorsAsWarnings = doc.CreateElement("TreatTestAdapterErrorsAsWarnings");
treatTestAdapterErrorsAsWarnings.InnerXml = this.TreatTestAdapterErrorsAsWarnings.ToString();
treatTestAdapterErrorsAsWarnings.InnerXml = TreatTestAdapterErrorsAsWarnings.ToString();
root.AppendChild(treatTestAdapterErrorsAsWarnings);

if (BinariesRoot != null)
Expand Down Expand Up @@ -772,10 +772,12 @@ public static RunConfiguration FromXml(XmlReader reader)
case "TestAdapterLoadingStrategy":
XmlRunSettingsUtilities.ThrowOnHasAttributes(reader);
value = reader.ReadElementContentAsString();
if (Enum.TryParse<TestAdapterLoadingStrategy>(value, out var loadingStrategy)) {
if (Enum.TryParse<TestAdapterLoadingStrategy>(value, out var loadingStrategy))
{
runConfiguration.TestAdapterLoadingStrategy = loadingStrategy;
}
else {
else
{
throw new SettingsException(string.Format(CultureInfo.CurrentCulture,
Resources.Resources.InvalidSettingsIncorrectValue, Constants.RunConfigurationSettingsName, value, elementName));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ internal enum TestAdapterLoadingStrategy
NextToSource = 0b0000_0000_0000_0010,

/// <summary>
/// Default runtime providers inside Extensions folder will be included
/// Default runtime providers inside Extensions folder will be included.
/// </summary>
DefaultRuntimeProviders = 0b0000_0000_0000_0100,

Expand All @@ -40,7 +40,7 @@ internal enum TestAdapterLoadingStrategy
ExtensionsDirectory = 0b0000_0000_0000_1000,

/// <summary>
/// Directory wide searches will be recursive, this is required to be with with NextToSource or Explicit.
/// Directory wide searches will be recursive, this is required to be used with <see cref="NextToSource" /> or <see cref="Explicit" />.
/// </summary>
Recursive = 0b0001_0000_0000_0000,
Haplois marked this conversation as resolved.
Show resolved Hide resolved
}
3 changes: 2 additions & 1 deletion src/vstest.console/CommandLine/Executor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,8 @@ private int GetArgumentProcessors(string[] args, out List<IArgumentProcessor> pr
var processorsToAlwaysExecute = processorFactory.GetArgumentProcessorsToAlwaysExecute();
foreach (var processor in processorsToAlwaysExecute)
{
if (processors.Any(i => i.Metadata.Value.CommandName == processor.Metadata.Value.CommandName)) {
if (processors.Any(i => i.Metadata.Value.CommandName == processor.Metadata.Value.CommandName))
{
continue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,11 @@ namespace Microsoft.VisualStudio.TestPlatform.CommandLine.Processors;
/// </summary>
internal class TestAdapterLoadingStrategyArgumentProcessor : IArgumentProcessor
{
#region Constants

/// <summary>
/// The name of the command line argument that the TestAdapterLoadingStrategyArgumentProcessor handles.
/// </summary>
public const string CommandName = "/TestAdapterLoadingStrategy";

#endregion

private Lazy<IArgumentProcessorCapabilities> _metadata;
Haplois marked this conversation as resolved.
Show resolved Hide resolved

private Lazy<IArgumentExecutor> _executor;
Expand Down Expand Up @@ -101,7 +97,6 @@ internal class TestAdapterLoadingStrategyArgumentProcessorCapabilities : BaseArg
/// </summary>
internal class TestAdapterLoadingStrategyArgumentExecutor : IArgumentExecutor
{
#region Fields
/// <summary>
/// Used for getting sources.
/// </summary>
Expand All @@ -122,12 +117,11 @@ internal class TestAdapterLoadingStrategyArgumentExecutor : IArgumentExecutor
/// </summary>
private readonly IFileHelper _fileHelper;

Haplois marked this conversation as resolved.
Show resolved Hide resolved

private static readonly string[] EmptyStringArray =
Haplois marked this conversation as resolved.
Show resolved Hide resolved
#if NET451
new string[0];
new string[0];
#else
Array.Empty<string>();
Array.Empty<string>();
#endif

#endregion
Expand Down Expand Up @@ -234,14 +228,11 @@ private void ValidateTestAdapterPaths(TestAdapterLoadingStrategy strategy)
var adapterPath = testAdapterPaths[i];
var testAdapterPath = _fileHelper.GetFullPath(Environment.ExpandEnvironmentVariables(adapterPath));

if (strategy == TestAdapterLoadingStrategy.Default)
if (strategy == TestAdapterLoadingStrategy.Default && !_fileHelper.DirectoryExists(testAdapterPath))
{
if (!_fileHelper.DirectoryExists(testAdapterPath))
{
throw new CommandLineException(
string.Format(CultureInfo.CurrentCulture, CommandLineResources.InvalidTestAdapterPathCommand, adapterPath, CommandLineResources.TestAdapterPathDoesNotExist)
);
}
throw new CommandLineException(
string.Format(CultureInfo.CurrentCulture, CommandLineResources.InvalidTestAdapterPathCommand, adapterPath, CommandLineResources.TestAdapterPathDoesNotExist)
);
}

testAdapterPaths[i] = testAdapterPath;
Expand All @@ -252,10 +243,8 @@ private void ValidateTestAdapterPaths(TestAdapterLoadingStrategy strategy)

private void SetStrategy(TestAdapterLoadingStrategy strategy)
{
var adapterStrategy = strategy.ToString();

_commandLineOptions.TestAdapterLoadingStrategy = strategy;
_runSettingsManager.UpdateRunSettingsNode(RunSettingsPath, adapterStrategy);
_runSettingsManager.UpdateRunSettingsNode(RunSettingsPath, strategy.ToString());
if ((strategy & TestAdapterLoadingStrategy.Explicit) == TestAdapterLoadingStrategy.Explicit)
{
ForceIsolation();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ internal class TestAdapterPathArgumentExecutor : IArgumentExecutor

private static readonly string[] EmptyStringArray =
Haplois marked this conversation as resolved.
Show resolved Hide resolved
#if NET451
new string[0];
new string[0];
#else
Array.Empty<string>();
Array.Empty<string>();
#endif

public const string RunSettingsPath = "RunConfiguration.TestAdaptersPaths";
Haplois marked this conversation as resolved.
Show resolved Hide resolved
Expand Down