-
Notifications
You must be signed in to change notification settings - Fork 325
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
Changes from 11 commits
c0a0705
dcc12e8
437c527
da0b940
14538c8
990c114
41c4aeb
88ed8da
1b7279f
c341a56
6e6014c
18e6683
7b31bd5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
namespace Microsoft.VisualStudio.TestPlatform.Utilities | ||
{ | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
public static class StringExtensions | ||
{ | ||
public static IEnumerable<string> Tokenize(this string input, char separator, char escape) | ||
{ | ||
if (string.IsNullOrEmpty(input)) yield break; | ||
|
||
var buffer = new StringBuilder(); | ||
var escaping = false; | ||
foreach (var c in input) | ||
{ | ||
if (escaping) | ||
{ | ||
buffer.Append(c); | ||
escaping = false; | ||
} | ||
else if (c == escape) | ||
{ | ||
escaping = true; | ||
} | ||
else if (c == separator) | ||
{ | ||
yield return buffer.Flush(); | ||
} | ||
else | ||
{ | ||
buffer.Append(c); | ||
} | ||
} | ||
if (buffer.Length > 0 || input[input.Length - 1] == separator) yield return buffer.Flush(); | ||
} | ||
|
||
private static string Flush(this StringBuilder stringBuilder) | ||
{ | ||
var result = stringBuilder.ToString(); | ||
stringBuilder.Clear(); | ||
return result; | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,13 +12,13 @@ namespace Microsoft.VisualStudio.TestPlatform.CommandLine.Processors | |
|
||
using Microsoft.VisualStudio.TestPlatform.Client.RequestHelper; | ||
using Microsoft.VisualStudio.TestPlatform.CommandLine.TestPlatformHelpers; | ||
using Microsoft.VisualStudio.TestPlatform.CommandLine.Processors.Utilities; | ||
using Microsoft.VisualStudio.TestPlatform.CommandLineUtilities; | ||
using Microsoft.VisualStudio.TestPlatform.Common; | ||
using Microsoft.VisualStudio.TestPlatform.Common.Interfaces; | ||
using Microsoft.VisualStudio.TestPlatform.ObjectModel; | ||
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client; | ||
using Microsoft.VisualStudio.TestPlatform.Utilities; | ||
|
||
using CommandLineResources = Microsoft.VisualStudio.TestPlatform.CommandLine.Resources.Resources; | ||
|
||
internal class RunSpecificTestsArgumentProcessor : IArgumentProcessor | ||
|
@@ -83,6 +83,9 @@ internal class RunSpecificTestsArgumentProcessorCapabilities : BaseArgumentProce | |
|
||
internal class RunSpecificTestsArgumentExecutor : IArgumentExecutor | ||
{ | ||
public const char SplitDelimeter = ','; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. s/Delimeter/Delimiter : everywhere There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed |
||
public const char EscapeDelimeter = '\\'; | ||
|
||
#region Fields | ||
|
||
/// <summary> | ||
|
@@ -171,7 +174,10 @@ public void Initialize(string argument) | |
{ | ||
if (!string.IsNullOrWhiteSpace(argument)) | ||
{ | ||
this.selectedTestNames = new Collection<string>(argument.Split(new[] { CommandLineResources.SearchStringDelimiter }, StringSplitOptions.RemoveEmptyEntries)); | ||
this.selectedTestNames = new Collection<string>( | ||
argument.Tokenize(SplitDelimeter, EscapeDelimeter) | ||
.Where(x => !string.IsNullOrWhiteSpace(x)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove , from resources There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
.Select(s => s.Trim()).ToList()); | ||
} | ||
|
||
if (this.selectedTestNames == null || this.selectedTestNames.Count <= 0) | ||
|
@@ -194,7 +200,7 @@ public ArgumentProcessorResult Execute() | |
Contract.Assert(this.testRequestManager != null); | ||
Contract.Assert(!string.IsNullOrWhiteSpace(this.runSettingsManager.ActiveRunSettings.SettingsXml)); | ||
|
||
if (this.commandLineOptions.Sources.Count() <= 0) | ||
if (!this.commandLineOptions.Sources.Any()) | ||
{ | ||
throw new CommandLineException(string.Format(CultureInfo.CurrentUICulture, CommandLineResources.MissingTestSourceFile)); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we need this? Revert this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Without this VS is not recognizing tests |
||
<AssemblyName>Microsoft.TestPlatform.Utilities.UnitTests</AssemblyName> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
using System.Linq; | ||
|
||
namespace Microsoft.TestPlatform.Utilities.UnitTests | ||
{ | ||
using Castle.Core.Internal; | ||
using Microsoft.VisualStudio.TestPlatform.Utilities; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
||
[TestClass] | ||
public class StringUtilitiesTests | ||
{ | ||
[TestMethod] | ||
public void SplitShouldReturnWhenStringisNullOrEmpty() | ||
{ | ||
var argsList = string.Empty.Tokenize(SplitChar, EscapeChar); | ||
|
||
Assert.IsTrue(argsList.IsNullOrEmpty()); | ||
} | ||
|
||
[TestMethod] | ||
public void SplitShouldReturnWhenStringDoesntContainSplitChar() | ||
{ | ||
var data = "foobar"; | ||
var argsList = data.Tokenize(SplitChar, EscapeChar); | ||
var enumerable = argsList as string[] ?? argsList.ToArray(); | ||
|
||
Assert.IsTrue(enumerable.Length == 1); | ||
Assert.IsTrue(enumerable.First().Equals(data)); | ||
} | ||
|
||
[TestMethod] | ||
public void SplitShouldSplitWhenStringContainsSplitChar() | ||
{ | ||
var data = "foo,bar"; | ||
var argsList = data.Tokenize(SplitChar, EscapeChar); | ||
var enumerable = argsList as string[] ?? argsList.ToArray(); | ||
|
||
Assert.IsTrue(enumerable.Length == 2); | ||
} | ||
|
||
[TestMethod] | ||
public void SplitShouldSplitWhenStringWithSplitCharStartEnd() | ||
{ | ||
var data = ",foo,bar,"; | ||
var argsList = data.Tokenize(SplitChar, EscapeChar); | ||
var enumerable = argsList as string[] ?? argsList.ToArray(); | ||
|
||
Assert.IsTrue(enumerable.Length == 4); | ||
} | ||
|
||
[TestMethod] | ||
public void SplitShouldEscapeSplitCharWhenEscapedCharPresent() | ||
{ | ||
var data = "foo\\,bar"; | ||
var argsList = data.Tokenize(SplitChar, EscapeChar); | ||
var enumerable = argsList as string[] ?? argsList.ToArray(); | ||
|
||
Assert.IsTrue(enumerable.Length == 1); | ||
Assert.IsTrue(enumerable.First().Equals("foo,bar")); | ||
} | ||
|
||
[TestMethod] | ||
public void SplitShouldEscapeSplitCharWhenEscapedNonEscapedCharPresent() | ||
{ | ||
var data = "foo\\,,bar"; | ||
var argsList = data.Tokenize(SplitChar, EscapeChar); | ||
var enumerable = argsList as string[] ?? argsList.ToArray(); | ||
Assert.IsTrue(enumerable.Length == 2); | ||
Assert.IsTrue(enumerable.First().Equals("foo,")); | ||
} | ||
|
||
[TestMethod] | ||
public void SplitShouldSplitWhenOnlySplitCharPresent() | ||
{ | ||
var data = ","; | ||
var argsList = data.Tokenize(SplitChar, EscapeChar); | ||
var enumerable = argsList as string[] ?? argsList.ToArray(); | ||
|
||
Assert.IsTrue(enumerable.Length == 2); | ||
} | ||
|
||
[TestMethod] | ||
public void SplitShouldNotSplitWhenNoSplitCharPresent() | ||
{ | ||
var data = "foo\\bar"; | ||
var argsList = data.Tokenize(SplitChar, EscapeChar); | ||
var enumerable = argsList as string[] ?? argsList.ToArray(); | ||
|
||
Assert.IsTrue(enumerable.Length == 1); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added in the cases where we required. |
||
} | ||
|
||
private const char SplitChar = ','; | ||
private const char EscapeChar = '\\'; | ||
} | ||
} |
There was a problem hiding this comment.
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 ?