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

Merge test run parameters that have spaces #2409

Merged
merged 2 commits into from
Apr 27, 2020
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
Next Next commit
Merge test run parameters that have spaces
  • Loading branch information
nohwnd committed Apr 21, 2020
commit dbb511c86a83827b4da36d0847aed9800fd3a83c
1 change: 1 addition & 0 deletions src/vstest.console/CommandLine/Executor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ private int GetArgumentProcessors(string[] args, out List<IArgumentProcessor> pr
processors.Add(cliRunSettingsProcessor);
break;
}

var processor = processorFactory.CreateArgumentProcessor(arg);

if (processor != null)
Expand Down
50 changes: 48 additions & 2 deletions src/vstest.console/Processors/CLIRunSettingsArgumentProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ namespace Microsoft.VisualStudio.TestPlatform.CommandLine.Processors

using CommandLineResources = Microsoft.VisualStudio.TestPlatform.CommandLine.Resources.Resources;
using System.Text.RegularExpressions;
using System.Collections.Generic;
nohwnd marked this conversation as resolved.
Show resolved Hide resolved
using System.Linq;
using System.Reflection.Metadata;
using System.Runtime.ExceptionServices;

/// <summary>
/// The argument processor for runsettings passed as argument through cli
Expand Down Expand Up @@ -136,11 +140,53 @@ public ArgumentProcessorResult Execute()

private void CreateOrOverwriteRunSettings(IRunSettingsProvider runSettingsProvider, string[] args)
{
var length = args.Length;
var mergedArgs = new List<string>();
var mergedArg = string.Empty;
var merge = false;

foreach (var arg in args)
{
if (arg.StartsWith("TestRunParameters", StringComparison.OrdinalIgnoreCase))
{
if (arg.EndsWith("\")")) {
// this parameter is complete
mergedArgs.Add(arg);
}
else
{
// this parameter needs merging
merge = true;
}
}

if (merge)
{
mergedArg += string.IsNullOrWhiteSpace(mergedArg) ? arg : $" {arg}";
}
else
{
mergedArgs.Add(arg);
}

if (merge && arg.EndsWith("\")")) {
nohwnd marked this conversation as resolved.
Show resolved Hide resolved
mergedArgs.Add(mergedArg);
mergedArg = string.Empty;
merge = false;
}
}

if (merge == true)
nohwnd marked this conversation as resolved.
Show resolved Hide resolved
{
// we tried to merge but never finished, add what we merged up until now
mergedArgs.Add(mergedArg);
}


var length = mergedArgs.Count;

for (int index = 0; index < length; index++)
{
var arg = args[index];
var arg = mergedArgs[index];

if (UpdateTestRunParameterNode(runSettingsProvider, arg))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,5 +347,46 @@ public static IEnumerable<object[]> TestRunParameterArgValidTestCases()
},
};
#endregion

[TestMethod]
public void InitializeShouldMergeTestRunParametersWithSpaces()
{
// in powershell call: ConsoleApp1.exe --% --TestRunParameters.Parameter(name =\"myParam\", value=\"myValue\")
// args:
//--
//TestRunParameters.Parameter(name = "myParam",
//value = "myValue")

// in cmd: ConsoleApp1.exe -- TestRunParameters.Parameter(name=\"myParam\", value=\"myValue\")
// args:
//--
//TestRunParameters.Parameter(name = "myParam",
//value = "myValue")

// in ubuntu wsl without escaping the space: ConsoleApp1.exe-- TestRunParameters.Parameter\(name =\"myParam\", value=\"myValue\"\)
// args:
//--
//TestRunParameters.Parameter(name = "myParam",
//value = "myValue")

// in ubuntu wsl with escaping the space: ConsoleApp1.exe-- TestRunParameters.Parameter\(name =\"myParam\",\ value=\"myValue\"\)
// args:
//--
//TestRunParameters.Parameter(name = "myParam", value = "myValue")

var args = new string[] {
"--",
"TestRunParameters.Parameter(name=\"myParam\",",
"value=\"myValue\")",
"TestRunParameters.Parameter(name=\"myParam2\",",
"value=\"myValue 2\")",
};

var runsettings = "<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n<RunSettings>\r\n <DataCollectionRunSettings>\r\n <DataCollectors />\r\n </DataCollectionRunSettings>\r\n <TestRunParameters>\r\n <Parameter name=\"myParam\" value=\"myValue\" />\r\n <Parameter name=\"myParam2\" value=\"myValue 2\" />\r\n </TestRunParameters>\r\n</RunSettings>";
nohwnd marked this conversation as resolved.
Show resolved Hide resolved
this.executor.Initialize(args);

Assert.IsNotNull(this.settingsProvider.ActiveRunSettings);
Assert.AreEqual(runsettings, settingsProvider.ActiveRunSettings.SettingsXml);
}
}
}