Skip to content
Merged
Show file tree
Hide file tree
Changes from 13 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
18 changes: 9 additions & 9 deletions scripts/build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -187,15 +187,15 @@ function Install-DotNetCli
"---- dotnet environment variables"
Get-ChildItem "Env:\dotnet_*"

"`n`n---- x64 dotnet"
& "$env:DOTNET_ROOT\dotnet.exe" --info

"`n`n---- x86 dotnet"
# avoid erroring out because we don't have the sdk for x86 that global.json requires
try {
& "${env:DOTNET_ROOT(x86)}\dotnet.exe" --info 2> $null
} catch {}
Write-Log "Install-DotNetCli: Complete. {$(Get-ElapsedTime($timer))}"
# "`n`n---- x64 dotnet"
# & "$env:DOTNET_ROOT\dotnet.exe" --info

# "`n`n---- x86 dotnet"
# # avoid erroring out because we don't have the sdk for x86 that global.json requires
# try {
# & "${env:DOTNET_ROOT(x86)}\dotnet.exe" --info 2> $null
# } catch {}
# Write-Log "Install-DotNetCli: Complete. {$(Get-ElapsedTime($timer))}"
}

function Clear-Package {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,10 @@ public bool ResultsDirectorySet
public bool CollectSourceInformationSet { get; private set; } = false;

/// <summary>
/// Default filter to use to filter tests
/// </summary>
public string TestCaseFilter { get; private set; }

/// Path to dotnet executable to be used to invoke testhost.dll. Specifying this will skip looking up testhost.exe and will force usage of the testhost.dll.
/// </summary>
public string DotnetHostPath { get; private set; }
Expand Down Expand Up @@ -576,6 +580,13 @@ public override XmlElement ToXml()
root.AppendChild(targetDevice);
}

if (!string.IsNullOrEmpty(this.TestCaseFilter))
{
XmlElement testCaseFilter = doc.CreateElement(nameof(TestCaseFilter));
testCaseFilter.InnerXml = this.TestCaseFilter;
root.AppendChild(testCaseFilter);
}

if (!string.IsNullOrEmpty(this.DotnetHostPath))
{
XmlElement dotnetHostPath = doc.CreateElement(nameof(DotnetHostPath));
Expand Down Expand Up @@ -879,6 +890,11 @@ public static RunConfiguration FromXml(XmlReader reader)
runConfiguration.TargetDevice = reader.ReadElementContentAsString();
break;

case "TestCaseFilter":
XmlRunSettingsUtilities.ThrowOnHasAttributes(reader);
runConfiguration.TestCaseFilter = reader.ReadElementContentAsString();
break;

case "DotNetHostPath":
XmlRunSettingsUtilities.ThrowOnHasAttributes(reader);
runConfiguration.DotnetHostPath = reader.ReadElementContentAsString();
Expand Down
6 changes: 6 additions & 0 deletions src/vstest.console/Processors/RunSettingsArgumentProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,12 @@ public void Initialize(string argument)
this.commandLineOptions.InIsolation = true;
this.runSettingsManager.UpdateRunSettingsNode(InIsolationArgumentExecutor.RunSettingsPath, "true");
}

var testCaseFilter = this.runSettingsManager.QueryRunSettingsNode("RunConfiguration.TestCaseFilter");
if (testCaseFilter != null)
{
this.commandLineOptions.TestCaseFilterValue = testCaseFilter;
}
}
catch (XmlException exception)
{
Expand Down
15 changes: 13 additions & 2 deletions src/vstest.console/Processors/TestCaseFilterArgumentProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,23 @@ public TestCaseFilterArgumentExecutor(CommandLineOptions options)
/// <param name="argument">Argument that was provided with the command.</param>
public void Initialize(string argument)
{
if (string.IsNullOrWhiteSpace(argument))
var defaultFilter = this.commandLineOptions.TestCaseFilterValue;
var hasDefaultFilter = !string.IsNullOrWhiteSpace(defaultFilter);

if (!hasDefaultFilter && string.IsNullOrWhiteSpace(argument))
{
throw new CommandLineException(string.Format(CultureInfo.CurrentUICulture, CommandLineResources.TestCaseFilterValueRequired));
}

this.commandLineOptions.TestCaseFilterValue = argument;
if (!hasDefaultFilter)
{
this.commandLineOptions.TestCaseFilterValue = argument;
}
else
{
// Merge default filter an provided filter by AND operator to have both the default filter and custom filter applied.
this.commandLineOptions.TestCaseFilterValue = $"({defaultFilter})&({argument})";
}
}

/// <summary>
Expand Down
5 changes: 4 additions & 1 deletion src/vstest.console/TestPlatformHelpers/TestRequestManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ public void DiscoverTests(DiscoveryRequestPayload discoveryPayload, ITestDiscove

var runConfiguration = XmlRunSettingsUtilities.GetRunConfigurationNode(runsettings);
var batchSize = runConfiguration.BatchSize;
var testCaseFilterFromRunsettings = runConfiguration.TestCaseFilter;

if (requestData.IsTelemetryOptedIn)
{
Expand All @@ -160,10 +161,12 @@ public void DiscoverTests(DiscoveryRequestPayload discoveryPayload, ITestDiscove
this.LogCommandsTelemetryPoints(requestData);
}



// create discovery request
var criteria = new DiscoveryCriteria(discoveryPayload.Sources, batchSize, this.commandLineOptions.TestStatsEventTimeout, runsettings)
{
TestCaseFilter = this.commandLineOptions.TestCaseFilterValue
TestCaseFilter = this.commandLineOptions.TestCaseFilterValue ?? testCaseFilterFromRunsettings
};

// Make sure to run the run request inside a lock as the below section is not thread-safe
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,30 @@ public void InitializeShouldNotSetInIsolataionToTrueIfEnvironmentVariablesNotSpe
Assert.IsNull(this.settingsProvider.QueryRunSettingsNode(InIsolationArgumentExecutor.RunSettingsPath));
}

[TestMethod]
public void InitializeShouldUpdateTestCaseFilterIfProvided()
{
// Arrange.
var fileName = "C:\\temp\\r.runsettings";
var filter = "TestCategory=Included";
var settingsXml = $"<RunSettings><RunConfiguration><TestCaseFilter>{filter}</TestCaseFilter></RunConfiguration></RunSettings>";

var executor = new TestableRunSettingsArgumentExecutor(
CommandLineOptions.Instance,
this.settingsProvider,
settingsXml);

// Setup mocks.
var mockFileHelper = new Mock<IFileHelper>();
mockFileHelper.Setup(fh => fh.Exists(It.IsAny<string>())).Returns(true);
executor.FileHelper = mockFileHelper.Object;

// Act.
executor.Initialize(fileName);

// Assert.
Assert.AreEqual(filter, CommandLineOptions.Instance.TestCaseFilterValue);
}
#endregion

#region Testable Implementations
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,29 @@ public void ExecutorInitializeWithNullOrEmptyTestCaseFilterShouldThrowCommandLin
}

[TestMethod]
public void ExecutorInitializeWithValidTestCaseFilterShouldAddTestCaseFilterToCommandLineOptions()
public void ExecutorInitializeWithNullOrEmptyTestCaseFilterShouldNotThrowWhenTestFilterWasSpecifiedByPreviousStep()
{
var options = CommandLineOptions.Instance;
options.TestCaseFilterValue = "Test=FilterFromPreviousStep";
TestCaseFilterArgumentExecutor executor = new TestCaseFilterArgumentExecutor(options);

executor.Initialize(null);
}

[TestMethod]
public void ExecutorInitializeWithTestCaseFilterShouldMergeWithTheValueProvidedByPreviousStep()
{
var options = CommandLineOptions.Instance;
var defaultValue = "Test=FilterFromPreviousStep";
options.TestCaseFilterValue = defaultValue;
Assert.AreEqual(defaultValue, options.TestCaseFilterValue);
TestCaseFilterArgumentExecutor executor = new TestCaseFilterArgumentExecutor(options);

executor.Initialize("Debug");
Assert.AreEqual("Debug", options.TestCaseFilterValue);
var value = "Test=NewFilter";
executor.Initialize(value);

var expectedValue = $"({defaultValue})&({value})";
Assert.AreEqual(expectedValue, options.TestCaseFilterValue);
}

[TestMethod]
Expand Down