Skip to content

Commit

Permalink
Cleanup change
Browse files Browse the repository at this point in the history
  • Loading branch information
Evangelink authored and baronfel committed Nov 10, 2022
1 parent 0368dff commit cdd5f3b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 28 deletions.
25 changes: 5 additions & 20 deletions src/Cli/dotnet/commands/dotnet-test/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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();

Expand All @@ -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;
Expand All @@ -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<IReadOnlyCollection<string>>(TestCommandParser.GetCommand(), "verbosity")?.SingleOrDefault() ?? null;
if (verbosityArg != null)
Expand Down
12 changes: 4 additions & 8 deletions src/Cli/dotnet/commands/dotnet-test/TestCommandParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> SlnOrProjectArgument = new Argument<string>(CommonLocalizableStrings.SolutionOrProjectArgumentName)
//{
// Description = CommonLocalizableStrings.SolutionOrProjectArgumentDescription,
// Arity = ArgumentArity.ZeroOrOne
//};
public static readonly string DocsLink = "https://aka.ms/dotnet-test";

public static readonly Option<string> SettingsOption = new ForwardedOption<string>(new string[] { "-s", "--settings" }, LocalizableStrings.CmdSettingsDescription)
{
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit cdd5f3b

Please # to comment.