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

TestPlugin cache refactored. #709

Merged
merged 16 commits into from
Apr 18, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
46 changes: 19 additions & 27 deletions src/vstest.console/Processors/TestAdapterPathArgumentProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,63 +155,55 @@ public void Initialize(string argument)
string.Format(CultureInfo.CurrentCulture, CommandLineResources.TestAdapterPathValueRequired));
}

string fullPathTestAdapterPathsString = string.Empty;
var fullPathTestAdapterPaths = new List<string>();
string customAdaptersPath;

try
{
// Remove leading and trailing ' " ' chars...
argument = argument.Trim().Trim(new char[] { '\"' });

var testadapterPaths = argument.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries).ToList();
customAdaptersPath = Path.GetFullPath(argument);
if (!fileHelper.DirectoryExists(customAdaptersPath))
{
throw new DirectoryNotFoundException(CommandLineResources.TestAdapterPathDoesNotExist);
}

// Get testadapter paths from RunSettings.
var testAdapterPathsInRunSettings = this.runSettingsManager.QueryRunSettingsNode("RunConfiguration.TestAdaptersPaths");

if (!string.IsNullOrWhiteSpace(testAdapterPathsInRunSettings))
{
var testAdapterFullPaths = new List<string>();
var testAdapterPathsInRunSettingsArray = testAdapterPathsInRunSettings.Split(
new[] { ';' },
StringSplitOptions.RemoveEmptyEntries);

if (testAdapterPathsInRunSettingsArray.Length > 0)
foreach (var testadapterPath in testAdapterPathsInRunSettingsArray)
{
testadapterPaths.AddRange(testAdapterPathsInRunSettingsArray);
}
}
var testAdapterFullPath = Path.GetFullPath(testadapterPath);

foreach (var testadapterPath in testadapterPaths)
{
var customAdaptersPath = Path.GetFullPath(testadapterPath);
if (!this.fileHelper.DirectoryExists(testAdapterFullPath))
{
throw new DirectoryNotFoundException(CommandLineResources.TestAdapterPathDoesNotExist);
}

if (!this.fileHelper.DirectoryExists(customAdaptersPath))
{
throw new DirectoryNotFoundException(CommandLineResources.TestAdapterPathDoesNotExist);
testAdapterFullPaths.Add(testAdapterFullPath);
}

fullPathTestAdapterPaths.Add(customAdaptersPath);
testAdapterFullPaths.Add(customAdaptersPath);
testAdapterFullPaths = testAdapterFullPaths.Distinct().ToList();
customAdaptersPath = string.Join(";", testAdapterFullPaths.ToArray());
}

fullPathTestAdapterPaths = fullPathTestAdapterPaths.Distinct().ToList();

fullPathTestAdapterPathsString = string.Join(";", fullPathTestAdapterPaths.ToArray());

this.runSettingsManager.UpdateRunSettingsNode("RunConfiguration.TestAdaptersPaths", fullPathTestAdapterPathsString);
this.runSettingsManager.UpdateRunSettingsNode("RunConfiguration.TestAdaptersPaths", customAdaptersPath);
}
catch (Exception e)
{
throw new CommandLineException(
string.Format(CultureInfo.CurrentCulture, CommandLineResources.InvalidTestAdapterPathCommand, argument, e.Message));
}

this.commandLineOptions.TestAdapterPath = fullPathTestAdapterPathsString;

if (fullPathTestAdapterPaths.Count <= 0)
{
// Print a warning about not finding any test adapter in provided path...
this.output.Warning(CommandLineResources.NoAdaptersFoundInTestAdapterPath, argument);
this.output.WriteLine(string.Empty, OutputLevel.Information);
}
this.commandLineOptions.TestAdapterPath = customAdaptersPath;
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we please check uses of this. earlier it were taking single path but now u are passing list of paths

}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,39 +168,15 @@ public void InitializeShouldUpdatTestAdapterPathsInRunSettings()
var currentAssemblyPath = typeof(TestAdapterPathArgumentExecutor).GetTypeInfo().Assembly.Location;
var currentFolder = Path.GetDirectoryName(currentAssemblyPath);

var testadapterPaths = string.Concat("C:\\;", currentFolder);
executor.Initialize(testadapterPaths);
executor.Initialize(currentFolder);
var runConfiguration = XmlRunSettingsUtilities.GetRunConfigurationNode(RunSettingsManager.Instance.ActiveRunSettings.SettingsXml);
Assert.AreEqual(testadapterPaths, runConfiguration.TestAdaptersPaths);
}

[TestMethod]
public void InitializeShouldReportIfNoTestAdaptersFoundInPath()
{
var mockRunSettingsProvider = new Mock<IRunSettingsProvider>();
var mockFileHelper = new Mock<IFileHelper>();
mockFileHelper.Setup(x => x.DirectoryExists(It.IsAny<string>())).Returns(false);
var mockOutput = new Mock<IOutput>();
var executor = new TestAdapterPathArgumentExecutor(CommandLineOptions.Instance, mockRunSettingsProvider.Object, mockOutput.Object, mockFileHelper.Object);

var currentAssemblyPath = typeof(TestAdapterPathArgumentExecutor).GetTypeInfo().Assembly.Location;
var currentFolder = Path.GetDirectoryName(currentAssemblyPath);

executor.Initialize(";");

mockOutput.Verify(
o =>
o.WriteLine(
string.Format(
"The path '{0}' specified in the 'TestAdapterPath' does not contain any test adapters, provide a valid path and try again.",
";"),
OutputLevel.Warning));
Assert.AreEqual(currentFolder, runConfiguration.TestAdaptersPaths);
}

[TestMethod]
public void InitializeShouldMergeTestAdapterPathsInRunSettings()
{
var runSettingsXml = "<RunSettings><RunConfiguration><TestAdaptersPaths>f:\\users</TestAdaptersPaths></RunConfiguration></RunSettings>";
var runSettingsXml = "<RunSettings><RunConfiguration><TestAdaptersPaths>d:\\users;f:\\users</TestAdaptersPaths></RunConfiguration></RunSettings>";
var runSettings = new RunSettings();
runSettings.LoadSettingsXml(runSettingsXml);
RunSettingsManager.Instance.SetActiveRunSettings(runSettings);
Expand All @@ -210,15 +186,15 @@ public void InitializeShouldMergeTestAdapterPathsInRunSettings()
mockFileHelper.Setup(x => x.DirectoryExists(It.IsAny<string>())).Returns(true);
var executor = new TestAdapterPathArgumentExecutor(CommandLineOptions.Instance, RunSettingsManager.Instance, mockOutput.Object, mockFileHelper.Object);

executor.Initialize("c:\\users;d:\\users");
executor.Initialize("c:\\users");
var runConfiguration = XmlRunSettingsUtilities.GetRunConfigurationNode(RunSettingsManager.Instance.ActiveRunSettings.SettingsXml);
Assert.AreEqual("c:\\users;d:\\users;f:\\users", runConfiguration.TestAdaptersPaths);
Assert.AreEqual("d:\\users;f:\\users;c:\\users", runConfiguration.TestAdaptersPaths);
}

[TestMethod]
public void InitializeShouldMergeTestAdapterPathsInRunSettingsIgnoringDuplicatePaths()
{
var runSettingsXml = "<RunSettings><RunConfiguration><TestAdaptersPaths>c:\\users</TestAdaptersPaths></RunConfiguration></RunSettings>";
var runSettingsXml = "<RunSettings><RunConfiguration><TestAdaptersPaths>d:\\users;c:\\users</TestAdaptersPaths></RunConfiguration></RunSettings>";
var runSettings = new RunSettings();
runSettings.LoadSettingsXml(runSettingsXml);
RunSettingsManager.Instance.SetActiveRunSettings(runSettings);
Expand All @@ -228,9 +204,9 @@ public void InitializeShouldMergeTestAdapterPathsInRunSettingsIgnoringDuplicateP
mockFileHelper.Setup(x => x.DirectoryExists(It.IsAny<string>())).Returns(true);
var executor = new TestAdapterPathArgumentExecutor(CommandLineOptions.Instance, RunSettingsManager.Instance, mockOutput.Object, mockFileHelper.Object);

executor.Initialize("c:\\users;d:\\users");
executor.Initialize("c:\\users");
var runConfiguration = XmlRunSettingsUtilities.GetRunConfigurationNode(RunSettingsManager.Instance.ActiveRunSettings.SettingsXml);
Assert.AreEqual("c:\\users;d:\\users", runConfiguration.TestAdaptersPaths);
Assert.AreEqual("d:\\users;c:\\users", runConfiguration.TestAdaptersPaths);
}

#endregion
Expand Down