diff --git a/src/vstest.console/CommandLine/Executor.cs b/src/vstest.console/CommandLine/Executor.cs index b4642db4fc..52beddf73e 100644 --- a/src/vstest.console/CommandLine/Executor.cs +++ b/src/vstest.console/CommandLine/Executor.cs @@ -183,6 +183,7 @@ private int GetArgumentProcessors(string[] args, out List pr processors.Add(cliRunSettingsProcessor); break; } + var processor = processorFactory.CreateArgumentProcessor(arg); if (processor != null) diff --git a/src/vstest.console/Processors/CLIRunSettingsArgumentProcessor.cs b/src/vstest.console/Processors/CLIRunSettingsArgumentProcessor.cs index c27853c619..8b1b88733b 100644 --- a/src/vstest.console/Processors/CLIRunSettingsArgumentProcessor.cs +++ b/src/vstest.console/Processors/CLIRunSettingsArgumentProcessor.cs @@ -6,14 +6,14 @@ namespace Microsoft.VisualStudio.TestPlatform.CommandLine.Processors using System; using System.Diagnostics.Contracts; using System.Xml.XPath; + using System.Collections.Generic; using Microsoft.VisualStudio.TestPlatform.Common; using Microsoft.VisualStudio.TestPlatform.Common.Interfaces; using Microsoft.VisualStudio.TestPlatform.ObjectModel; using Microsoft.VisualStudio.TestPlatform.Common.Utilities; - using CommandLineResources = Microsoft.VisualStudio.TestPlatform.CommandLine.Resources.Resources; - using System.Text.RegularExpressions; + using CommandLineResources = Microsoft.VisualStudio.TestPlatform.CommandLine.Resources.Resources; /// /// The argument processor for runsettings passed as argument through cli @@ -136,11 +136,60 @@ public ArgumentProcessorResult Execute() private void CreateOrOverwriteRunSettings(IRunSettingsProvider runSettingsProvider, string[] args) { - var length = args.Length; + var mergedArgs = new List(); + var mergedArg = string.Empty; + var merge = false; + + foreach (var arg in args) + { + // when we see that the parameter begins with TestRunParameters + // but does not end with ") we start merging the params + if (arg.StartsWith("TestRunParameters", StringComparison.OrdinalIgnoreCase)) + { + if (arg.EndsWith("\")")) { + // this parameter is complete + mergedArgs.Add(arg); + } + else + { + // this parameter needs merging + merge = true; + } + } + + // we merge as long as the flag is set + // hoping that we find the end of the parameter + if (merge) + { + mergedArg += string.IsNullOrWhiteSpace(mergedArg) ? arg : $" {arg}"; + } + else + { + // if we are not merging just pass the param as is + mergedArgs.Add(arg); + } + + // once we detect the end we add the whole parameter to the args + if (merge && arg.EndsWith("\")")) { + mergedArgs.Add(mergedArg); + mergedArg = string.Empty; + merge = false; + } + } + + if (merge) + { + // we tried to merge but never found the end of that + // test paramter, 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)) { diff --git a/test/vstest.console.UnitTests/Processors/CLIRunSettingsArgumentProcessorTests.cs b/test/vstest.console.UnitTests/Processors/CLIRunSettingsArgumentProcessorTests.cs index 48ec148c25..9db1d8b408 100644 --- a/test/vstest.console.UnitTests/Processors/CLIRunSettingsArgumentProcessorTests.cs +++ b/test/vstest.console.UnitTests/Processors/CLIRunSettingsArgumentProcessorTests.cs @@ -347,5 +347,57 @@ public static IEnumerable 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 = string.Join(Environment.NewLine, new[]{ + "", + "", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + ""}); + + this.executor.Initialize(args); + + Assert.IsNotNull(this.settingsProvider.ActiveRunSettings); + Assert.AreEqual(runsettings, settingsProvider.ActiveRunSettings.SettingsXml); + } } }