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

Support escaping , in Test filter #1374

Merged
merged 13 commits into from
Jan 17, 2018
Merged

Support escaping , in Test filter #1374

merged 13 commits into from
Jan 17, 2018

Conversation

nigurr
Copy link

@nigurr nigurr commented Jan 15, 2018

Currently vstest console runner doesn't support escaping of , in test filter.
This PR adds support of escaping this by adding \.

//todo fix the resource file
this.selectedTestNames = new Collection<string>(
argument.Tokenize(CommandLineResources.SearchStringDelimiter.ToCharArray()[0], '\\')
.Where(x => !string.IsNullOrWhiteSpace(x))
Copy link
Contributor

Choose a reason for hiding this comment

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

remove , from resources

Copy link
Author

Choose a reason for hiding this comment

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

done

@mayankbansal018
Copy link
Contributor

We support "," delimiter, are we now supporting "," & "," delimiter? Why do we need to do so?


internal static class StringExtensions
{
public static IEnumerable<string> Tokenize(this string input, char separator, char escape)
Copy link
Contributor

@mayankbansal018 mayankbansal018 Jan 16, 2018

Choose a reason for hiding this comment

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

Please add test cases for this class.

Check if input = "\" or "\\" or "\,"

Copy link
Contributor

Choose a reason for hiding this comment

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

Or make this a private static method until we need another consumer for this.

Copy link
Contributor

Choose a reason for hiding this comment

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

Please do not make it private, once you do it, it will forever remain in this dll :(. Please move it to Utilities dll, under String Utilities class

Copy link
Author

Choose a reason for hiding this comment

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

Done

buffer.Append(c);
}
}
if (buffer.Length > 0 || input[input.Length - 1] == separator) yield return buffer.Flush();
Copy link
Contributor

Choose a reason for hiding this comment

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

What happens if buffer length is 0?

Copy link
Author

Choose a reason for hiding this comment

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

it will not flush. that's an empty stringbuilder

Copy link
Contributor

Choose a reason for hiding this comment

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

You are returning something back if buffer length > 0, what will it return if it is 0? An empty string, null string? If it returns null will the method invoking it crash?

Copy link
Author

Choose a reason for hiding this comment

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

Please check the UTs.

@@ -0,0 +1,46 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
Copy link
Contributor

@mayankbansal018 mayankbansal018 Jan 16, 2018

Choose a reason for hiding this comment

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

Copy link
Author

Choose a reason for hiding this comment

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

Done

@@ -101,6 +101,51 @@ public void CapabilitiesShouldReturnAppropriateProperties()

#region RunSpecificTestsArgumentExecutorTests

[TestMethod]
public void InitializeShouldThrowIfArguemntIsNull()
Copy link
Contributor

Choose a reason for hiding this comment

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

s/Arguemnt/Argument/g

{
CommandLineOptions.Instance.Reset();
var testRequestManager = new TestRequestManager(CommandLineOptions.Instance, new TestPlatform(), TestLoggerManager.Instance, TestRunResultAggregator.Instance, this.mockTestPlatformEventSource.Object, this.inferHelper, this.mockMetricsPublisherTask);
var executor = GetExecutor(testRequestManager);
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: single blank line between arrange, act and assert == awesome readability :)

Copy link
Author

Choose a reason for hiding this comment

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

noted :)

@@ -328,6 +371,113 @@ public void ExecutorExecuteShouldForValidSourcesAndValidSelectedTestsRunsTestsAn
Assert.AreEqual(ArgumentProcessorResult.Success, argumentProcessorResult);
}

[TestMethod]
public void RunTestsWithCommaSeperatedTests()
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: naming should follow <UnitOfWork>Should<Behavior>When<Condition>
nit: every test should have only one reason to fail

These two statements will help understand what feature is broken by just looking at the failed test case, adds to productivity.

Copy link
Author

Choose a reason for hiding this comment

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

done

[TestMethod]
public void RunTestsWithFilteredTest()
{
var mockTestPlatform = new Mock<ITestPlatform>();
Copy link
Contributor

Choose a reason for hiding this comment

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

How do we remove the DRY violations in these tests?

{
public static IEnumerable<string> Tokenize(this string input, char separator, char escape)
{
if (input == null) yield break;
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: logic should be in separate line within { } for conditionals. R# with stylecop extension helps catch some of these.

@@ -7,7 +7,7 @@
<Import Project="$(TestPlatformRoot)scripts/build/TestPlatform.Settings.targets" />
<PropertyGroup>
<OutputType Condition=" '$(TargetFramework)' == 'netcoreapp1.0' ">Exe</OutputType>
<TargetFrameworks>netcoreapp1.0;net451</TargetFrameworks>
<TargetFrameworks>net451;netcoreapp1.0</TargetFrameworks>
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need this? Revert this

Copy link
Author

Choose a reason for hiding this comment

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

Without this VS is not recognizing tests

}

[TestMethod]
public void ExecutorShouldSplitTestsSeperatedByComma()
Copy link
Contributor

Choose a reason for hiding this comment

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

s/Seperate/Separate : everywhere

Copy link
Author

Choose a reason for hiding this comment

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

fixed

executor.Initialize("Test1, Test2");
ArgumentProcessorResult argumentProcessorResult = executor.Execute();

mockOutput.Verify(o => o.WriteLine(It.IsAny<string>(), OutputLevel.Warning), Times.Never);
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to check for error as well ?

Copy link
Author

Choose a reason for hiding this comment

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

not required unless we are expecting an error

@@ -83,6 +83,9 @@ internal class RunSpecificTestsArgumentProcessorCapabilities : BaseArgumentProce

internal class RunSpecificTestsArgumentExecutor : IArgumentExecutor
{
public const char SplitDelimeter = ',';
Copy link
Contributor

Choose a reason for hiding this comment

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

s/Delimeter/Delimiter : everywhere

Copy link
Author

Choose a reason for hiding this comment

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

Fixed

var argsList = data.Tokenize(SplitChar, EscapeChar);
var enumerable = argsList as string[] ?? argsList.ToArray();

Assert.IsTrue(enumerable.Length == 1);
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we use SequenceEqual instead or have another assert? just length check isn't good.

Copy link
Author

Choose a reason for hiding this comment

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

Added in the cases where we required.

using System.Collections.Generic;
using System.Text;

public static class StringExtensions
Copy link
Contributor

Choose a reason for hiding this comment

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

There is already vstest/src/Microsoft.TestPlatform.CoreUtilities/Utilities/StringExtensions.cs
Can we move this there ?

@nigurr nigurr merged commit 46f1cae into microsoft:master Jan 17, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants