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

Always look for adapters in Test Source directory #1574

Merged
merged 6 commits into from
May 7, 2018
Merged
Show file tree
Hide file tree
Changes from 4 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
32 changes: 18 additions & 14 deletions src/Microsoft.TestPlatform.Build/Tasks/VSTestTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public string VSTestSetting
set;
}

public string VSTestTestAdapterPath
public string[] VSTestTestAdapterPath
Copy link
Contributor

Choose a reason for hiding this comment

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

string[] [](start = 15, length = 8)

nitpick: IEnumerable over string[]

{
get;
set;
Expand All @@ -54,7 +54,7 @@ public string VSTestTestCaseFilter
get;
set;
}
public string VSTestLogger
public string[] VSTestLogger
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Should we rename these to reflect the change, VSTestLoggers ?

{
get;
set;
Expand Down Expand Up @@ -131,6 +131,7 @@ public void Cancel()

internal IEnumerable<string> CreateArgument()
{
var isConsoleLoggerEnabled = true;
var allArgs = new List<string>();

// TODO log arguments in task
Expand All @@ -139,16 +140,11 @@ internal IEnumerable<string> CreateArgument()
allArgs.Add("--settings:" + ArgumentEscaper.HandleEscapeSequenceInArgForProcessStart(this.VSTestSetting));
}

if (!string.IsNullOrEmpty(this.VSTestTestAdapterPath))
if (this.VSTestTestAdapterPath != null && this.VSTestTestAdapterPath.Length > 0)
{
allArgs.Add("--testAdapterPath:" + ArgumentEscaper.HandleEscapeSequenceInArgForProcessStart(this.VSTestTestAdapterPath));
}
else
{
// For Full CLR, add source directory as test adapter path.
if (this.VSTestFramework.StartsWith(".NETFramework", StringComparison.OrdinalIgnoreCase))
foreach (var arg in this.VSTestTestAdapterPath)
{
allArgs.Add("--testAdapterPath:" + ArgumentEscaper.HandleEscapeSequenceInArgForProcessStart(Path.GetDirectoryName(this.TestFileFullPath)));
allArgs.Add("--testAdapterPath:" + ArgumentEscaper.HandleEscapeSequenceInArgForProcessStart(arg));
}
}

Expand All @@ -168,9 +164,17 @@ internal IEnumerable<string> CreateArgument()
allArgs.Add("--testCaseFilter:" + ArgumentEscaper.HandleEscapeSequenceInArgForProcessStart(this.VSTestTestCaseFilter));
}

if (!string.IsNullOrEmpty(this.VSTestLogger))
if (this.VSTestLogger != null && this.VSTestLogger.Length > 0)
{
allArgs.Add("--logger:" + ArgumentEscaper.HandleEscapeSequenceInArgForProcessStart(this.VSTestLogger));
foreach (var arg in this.VSTestLogger)
{
allArgs.Add("--logger:" + ArgumentEscaper.HandleEscapeSequenceInArgForProcessStart(arg));

if (arg.StartsWith("console", StringComparison.OrdinalIgnoreCase))
{
isConsoleLoggerEnabled = false;
}
}
}

if (!string.IsNullOrEmpty(this.VSTestResultsDirectory))
Expand All @@ -197,8 +201,8 @@ internal IEnumerable<string> CreateArgument()
allArgs.Add(ArgumentEscaper.HandleEscapeSequenceInArgForProcessStart(this.TestFileFullPath));
}

if (!string.IsNullOrWhiteSpace(this.VSTestVerbosity) &&
(string.IsNullOrEmpty(this.VSTestLogger) || !this.VSTestLogger.StartsWith("console", StringComparison.OrdinalIgnoreCase)))
// Console logger was not specified by user, but verbosity was, hence add default console logger with verbosity as specified
if (!string.IsNullOrWhiteSpace(this.VSTestVerbosity) && isConsoleLoggerEnabled)
{
var normalTestLogging = new List<string>() { "n", "normal", "d", "detailed", "diag", "diagnostic" };
var quietTestLogging = new List<string>() { "q", "quiet" };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ public class DefaultTestHostManager : ITestRuntimeProvider
private StringBuilder testHostProcessStdError;
private IMessageLogger messageLogger;
private bool hostExitedEventRaised;
private bool projectOutputExtensionsRequired;

/// <summary>
/// Initializes a new instance of the <see cref="DefaultTestHostManager"/> class.
Expand Down Expand Up @@ -192,7 +191,7 @@ public virtual TestProcessStartInfo GetTestHostProcessStartInfo(
/// <inheritdoc/>
public IEnumerable<string> GetTestPlatformExtensions(IEnumerable<string> sources, IEnumerable<string> extensions)
{
if (sources != null && sources.Any() && this.projectOutputExtensionsRequired)
if (sources != null && sources.Any())
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove explicitly testadapterpath from acceptance tests. Example.

{
extensions = extensions.Concat(sources.SelectMany(s => this.fileHelper.EnumerateFiles(Path.GetDirectoryName(s), SearchOption.TopDirectoryOnly, TestAdapterEndsWithPattern)));
}
Expand Down Expand Up @@ -248,7 +247,6 @@ public void Initialize(IMessageLogger logger, string runsettingsXml)
this.testHostProcess = null;

this.Shared = !runConfiguration.DisableAppDomain;
this.projectOutputExtensionsRequired = !(runConfiguration.TestAdaptersPaths?.Length > 0);
this.hostExitedEventRaised = false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public void ExecuteTestsWithDataCollection(RunnerInfo runnerInfo)
IntegrationTestEnvironment.BuildConfiguration,
this.testEnvironment.RunnerFramework);
var arguments = PrepareArguments(assemblyPaths, this.GetTestAdapterPath(), runSettings, this.FrameworkArgValue, runnerInfo.InIsolationValue);
arguments = string.Concat(arguments, $" /ResultsDirectory:{resultsDir}", $" /Diag:{diagFileName}", $" /TestAdapterPath:{extensionsPath}");
arguments = string.Concat(arguments, $" /ResultsDirectory:{resultsDir}", $" /Diag:{diagFileName}");

this.InvokeVsTest(arguments);

Expand All @@ -74,7 +74,7 @@ public void ExecuteTestsWithDataCollectionUsingCollectArgument(RunnerInfo runner
this.testEnvironment.RunnerFramework);

var arguments = PrepareArguments(assemblyPaths, this.GetTestAdapterPath(), null, this.FrameworkArgValue, runnerInfo.InIsolationValue);
arguments = string.Concat(arguments, $" /ResultsDirectory:{resultsDir}", $" /Diag:{diagFileName}", $" /Collect:SampleDataCollector", $" /TestAdapterPath:{extensionsPath}");
arguments = string.Concat(arguments, $" /ResultsDirectory:{resultsDir}", $" /Diag:{diagFileName}", $" /Collect:SampleDataCollector");

this.InvokeVsTest(arguments);

Expand Down
39 changes: 37 additions & 2 deletions test/Microsoft.TestPlatform.Build.UnitTests/VsTestTaskTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public void CreateArgumentShouldNotSetConsoleLoggerVerbosityIfConsoleLoggerIsGiv
// Add values for required properties.
vstestTask.TestFileFullPath = "abc";
vstestTask.VSTestFramework = "abc";
vstestTask.VSTestLogger = "Console;Verbosity=quiet";
vstestTask.VSTestLogger = new string[] { "Console;Verbosity=quiet" };

var allArguments = vstestTask.CreateArgument().ToArray();

Expand Down Expand Up @@ -209,7 +209,7 @@ public void CreateArgumentShouldPreserveWhiteSpaceInLogger()
// Add values for required properties.
vstestTask.TestFileFullPath = "abc";
vstestTask.VSTestFramework = "abc";
vstestTask.VSTestLogger = "trx;LogFileName=foo bar.trx";
vstestTask.VSTestLogger = new string[] { "trx;LogFileName=foo bar.trx" };


var allArguments = vstestTask.CreateArgument().ToArray();
Expand All @@ -234,5 +234,40 @@ public void CreateArgumentShouldAddOneCollectArgumentForEachCollect()
Assert.IsNotNull(allArguments.FirstOrDefault(arg => arg.Contains("--collect:name1")));
Assert.IsNotNull(allArguments.FirstOrDefault(arg => arg.Contains("--collect:\"name 2\"")));
}

[TestMethod]
public void CreateArgumentShouldAddMultipleTestAdapterPaths()
{
var vstestTask = new VSTestTask();

// Add values for required properties.
vstestTask.TestFileFullPath = "abc";
vstestTask.VSTestFramework = "abc";

vstestTask.VSTestTestAdapterPath = new string[] { "path1", "path2" };

var allArguments = vstestTask.CreateArgument().ToArray();

Assert.IsNotNull(allArguments.FirstOrDefault(arg => arg.Contains("--testAdapterPath:path1")));
Assert.IsNotNull(allArguments.FirstOrDefault(arg => arg.Contains("--testAdapterPath:path2")));
}

[TestMethod]
public void CreateArgumentShouldAddMultipleLoggers()
{
var vstestTask = new VSTestTask();

// Add values for required properties.
vstestTask.TestFileFullPath = "abc";
vstestTask.VSTestFramework = "abc";

vstestTask.VSTestLogger = new string[] { "trx;LogFileName=foo bar.trx", "console" };

Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: extra line
Also, better for required properties, use new VSTestTask { TestFileFullPath = "abc", VSTestFramework = "xyz"}


var allArguments = vstestTask.CreateArgument().ToArray();

Assert.IsNotNull(allArguments.FirstOrDefault(arg => arg.Contains("--logger:\"trx;LogFileName=foo bar.trx\"")));
Assert.IsNotNull(allArguments.FirstOrDefault(arg => arg.Contains("--logger:console")));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -211,16 +211,19 @@ public void GetTestPlatformExtensionsShouldReturnExtensionsListAsIsIfSourcesList
}

[TestMethod]
public void GetTestPlatformExtensionsShouldExcludeOutputDirectoryExtensionsIfTestAdapterPathIsSet()
public void GetTestPlatformExtensionsShouldNotExcludeOutputDirectoryExtensionsIfTestAdapterPathIsSet()
{
List<string> sourcesDir = new List<string> { @"C:\Source1" };
List<string> sources = new List<string> { @"C:\Source1\source1.dll" };

List<string> extensionsList1 = new List<string> { @"C:\Source1\ext1.TestAdapter.dll", @"C:\Source1\ext2.TestAdapter.dll" };
this.mockFileHelper.Setup(fh => fh.EnumerateFiles(sourcesDir[0], SearchOption.TopDirectoryOnly, "TestAdapter.dll")).Returns(extensionsList1);

this.mockFileHelper.Setup(fh => fh.GetFileVersion(extensionsList1[0])).Returns(new Version(2, 0));
this.mockFileHelper.Setup(fh => fh.GetFileVersion(extensionsList1[1])).Returns(new Version(5, 5));

this.testHostManager.Initialize(this.mockMessageLogger.Object, $"<?xml version=\"1.0\" encoding=\"utf-8\"?><RunSettings> <RunConfiguration><TestAdaptersPaths>C:\\Foo</TestAdaptersPaths></RunConfiguration> </RunSettings>");
List<string> currentList = new List<string> { @"FooExtension.dll" };
List<string> currentList = new List<string> { @"FooExtension.dll", @"C:\Source1\ext1.TestAdapter.dll", @"C:\Source1\ext2.TestAdapter.dll" };
Copy link
Contributor

Choose a reason for hiding this comment

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

Change test name.


// Act
var resultExtensions = this.testHostManager.GetTestPlatformExtensions(sources, currentList).ToList();
Expand Down