diff --git a/src/Cli/dotnet/commands/dotnet-test/Program.cs b/src/Cli/dotnet/commands/dotnet-test/Program.cs index ca8a68eeb0fd..4cce5cee57cf 100644 --- a/src/Cli/dotnet/commands/dotnet-test/Program.cs +++ b/src/Cli/dotnet/commands/dotnet-test/Program.cs @@ -68,7 +68,7 @@ private static int ForwardToMsbuild(ParseResult parseResult, string[] args, stri try { Environment.SetEnvironmentVariable(NodeWindowEnvironmentName, "1"); - int exitCode = FromParseResult(parseResult, args, settings, testSessionCorrelationId).Execute(); + int exitCode = FromParseResult(parseResult, settings, testSessionCorrelationId).Execute(); // We run post processing also if execution is failed for possible partial successful result to post process. exitCode |= RunArtifactPostProcessingIfNeeded(testSessionCorrelationId, parseResult, FeatureFlag.Instance); @@ -108,7 +108,7 @@ private static int ForwardToVSTestConsole(ParseResult parseResult, string[] args return exitCode; } - private static TestCommand FromParseResult(ParseResult result, string[] args, string[] settings, string testSessionCorrelationId, string msbuildPath = null) + private static TestCommand FromParseResult(ParseResult result, string[] settings, string testSessionCorrelationId, string msbuildPath = null) { result.ShowHelpOrErrorIfAppropriate(); @@ -119,6 +119,9 @@ private static TestCommand FromParseResult(ParseResult result, string[] args, st "-nologo" }; + // Extra msbuild properties won't be parsed and so end up in the UnmatchedTokens list. In addition to those + // properties, all the test settings properties are also considered as unmatched but we don't want to forward + // these as-is to msbuild. So we filter out the test settings properties from the unmatched tokens. var unMatchedNonSettingsArgs = settings.Length > 1 ? result.UnmatchedTokens.TakeWhile(x => x != settings[1]) : result.UnmatchedTokens; @@ -132,30 +135,12 @@ private static TestCommand FromParseResult(ParseResult result, string[] args, st if (settings.Any()) { - //workaround for correct -- logic - //var commandArgument = result.GetValueForArgument(TestCommandParser.SlnOrProjectArgument); - //// TODO: @baronfel, @Evangelink - //// If the project or solution is not specified we would expect null here but we actually - //// get some of the parameter (last one before --) instead. - //if (!string.IsNullOrWhiteSpace(commandArgument) && !settings.Contains(commandArgument)) - //{ - // msbuildArgs.Add(commandArgument); - //} - // skip '--' and escape every \ to be \\ and every " to be \" to survive the next hop string[] escaped = settings.Skip(1).Select(s => s.Replace("\\", "\\\\").Replace("\"", "\\\"")).ToArray(); string runSettingsArg = string.Join(";", escaped); msbuildArgs.Add($"-property:VSTestCLIRunSettings=\"{runSettingsArg}\""); } - else - { - //var argument = result.GetValueForArgument(TestCommandParser.SlnOrProjectArgument); - //if (!string.IsNullOrWhiteSpace(argument)) - //{ - // msbuildArgs.Add(argument); - //} - } string verbosityArg = result.ForwardedOptionValues>(TestCommandParser.GetCommand(), "verbosity")?.SingleOrDefault() ?? null; if (verbosityArg != null) diff --git a/src/Cli/dotnet/commands/dotnet-test/TestCommandParser.cs b/src/Cli/dotnet/commands/dotnet-test/TestCommandParser.cs index ca15d1b406f6..30bb60e16c9d 100644 --- a/src/Cli/dotnet/commands/dotnet-test/TestCommandParser.cs +++ b/src/Cli/dotnet/commands/dotnet-test/TestCommandParser.cs @@ -15,13 +15,7 @@ namespace Microsoft.DotNet.Cli { internal static class TestCommandParser { - public static readonly string DocsLink = "https://aka.ms/dotnet-test"; - - //public static readonly Argument SlnOrProjectArgument = new Argument(CommonLocalizableStrings.SolutionOrProjectArgumentName) - //{ - // Description = CommonLocalizableStrings.SolutionOrProjectArgumentDescription, - // Arity = ArgumentArity.ZeroOrOne - //}; + public static readonly string DocsLink = "https://aka.ms/dotnet-test"; public static readonly Option SettingsOption = new ForwardedOption(new string[] { "-s", "--settings" }, LocalizableStrings.CmdSettingsDescription) { @@ -130,7 +124,9 @@ private static Command ConstructCommand() { var command = new DocumentedCommand("test", DocsLink, LocalizableStrings.AppFullName); command.TreatUnmatchedTokensAsErrors = false; - //command.AddArgument(SlnOrProjectArgument); + + // We are on purpose not capturing the solution, project or directory here. We want to pass it to the + // MSBuild command so we are letting it flow. command.AddOption(SettingsOption); command.AddOption(ListTestsOption);