2017-03-10 13:18:14 -08:00
|
|
|
using System.Collections.Generic;
|
2017-03-06 11:57:19 -08:00
|
|
|
using System.Linq;
|
|
|
|
using Microsoft.DotNet.Cli.CommandLine;
|
2017-03-10 13:18:14 -08:00
|
|
|
using LocalizableStrings = Microsoft.DotNet.Tools.Test.LocalizableStrings;
|
2017-03-06 11:57:19 -08:00
|
|
|
|
|
|
|
namespace Microsoft.DotNet.Cli
|
|
|
|
{
|
|
|
|
internal static class TestCommandParser
|
|
|
|
{
|
|
|
|
public static Command Test() =>
|
2017-03-10 13:18:14 -08:00
|
|
|
Create.Command(
|
|
|
|
"test",
|
2017-03-10 13:49:49 -08:00
|
|
|
LocalizableStrings.AppFullName,
|
2017-03-14 10:33:58 -07:00
|
|
|
Accept.ZeroOrMoreArguments()
|
|
|
|
.With(name: LocalizableStrings.CmdArgProject,
|
|
|
|
description: LocalizableStrings.CmdArgDescription),
|
2017-03-10 13:18:14 -08:00
|
|
|
CommonOptions.HelpOption(),
|
|
|
|
Create.Option(
|
|
|
|
"-s|--settings",
|
|
|
|
LocalizableStrings.CmdSettingsDescription,
|
2017-03-10 17:52:40 -08:00
|
|
|
Accept.ExactlyOneArgument()
|
2017-03-10 13:18:14 -08:00
|
|
|
.With(name: LocalizableStrings.CmdSettingsFile)
|
|
|
|
.ForwardAs(o => $"/p:VSTestSetting={o.Arguments.Single()}")),
|
|
|
|
Create.Option(
|
|
|
|
"-t|--list-tests",
|
|
|
|
LocalizableStrings.CmdListTestsDescription,
|
2017-03-10 17:52:40 -08:00
|
|
|
Accept.NoArguments()
|
2017-03-10 13:18:14 -08:00
|
|
|
.ForwardAs(o => "/p:VSTestListTests=true")),
|
|
|
|
Create.Option(
|
|
|
|
"--filter",
|
|
|
|
LocalizableStrings.CmdTestCaseFilterDescription,
|
2017-03-10 17:52:40 -08:00
|
|
|
Accept.ExactlyOneArgument()
|
2017-03-10 13:18:14 -08:00
|
|
|
.With(name: LocalizableStrings.CmdTestCaseFilterExpression)
|
|
|
|
.ForwardAs(o => $"/p:VSTestTestCaseFilter={o.Arguments.Single()}")),
|
|
|
|
Create.Option(
|
|
|
|
"-a|--test-adapter-path",
|
|
|
|
LocalizableStrings.CmdTestAdapterPathDescription,
|
2017-03-10 17:52:40 -08:00
|
|
|
Accept.ExactlyOneArgument()
|
2017-03-10 13:18:14 -08:00
|
|
|
.With(name: LocalizableStrings.CmdTestAdapterPath)
|
|
|
|
.ForwardAs(o => $"/p:VSTestTestAdapterPath={o.Arguments.Single()}")),
|
|
|
|
Create.Option(
|
|
|
|
"-l|--logger",
|
|
|
|
LocalizableStrings.CmdLoggerDescription,
|
2017-03-10 17:52:40 -08:00
|
|
|
Accept.ExactlyOneArgument()
|
2017-03-10 13:18:14 -08:00
|
|
|
.With(name: LocalizableStrings.CmdLoggerOption)
|
|
|
|
.ForwardAs(o =>
|
|
|
|
{
|
|
|
|
var loggersString = string.Join(";", GetSemiColonEscapedArgs(o.Arguments));
|
|
|
|
|
|
|
|
return $"/p:VSTestLogger={loggersString}";
|
|
|
|
})),
|
|
|
|
CommonOptions.ConfigurationOption(),
|
|
|
|
CommonOptions.FrameworkOption(),
|
|
|
|
Create.Option(
|
|
|
|
"-o|--output",
|
|
|
|
LocalizableStrings.CmdOutputDescription,
|
2017-03-10 17:52:40 -08:00
|
|
|
Accept.ExactlyOneArgument()
|
2017-03-10 13:18:14 -08:00
|
|
|
.With(name: LocalizableStrings.CmdOutputDir)
|
|
|
|
.ForwardAs(o => $"/p:OutputPath={o.Arguments.Single()}")),
|
|
|
|
Create.Option(
|
|
|
|
"-d|--diag",
|
|
|
|
LocalizableStrings.CmdPathTologFileDescription,
|
2017-03-10 17:52:40 -08:00
|
|
|
Accept.ExactlyOneArgument()
|
2017-03-10 13:18:14 -08:00
|
|
|
.With(name: LocalizableStrings.CmdPathToLogFile)
|
|
|
|
.ForwardAs(o => $"/p:VSTestDiag={o.Arguments.Single()}")),
|
|
|
|
Create.Option(
|
|
|
|
"--no-build",
|
|
|
|
LocalizableStrings.CmdNoBuildDescription,
|
2017-03-10 17:52:40 -08:00
|
|
|
Accept.NoArguments()
|
2017-03-10 13:18:14 -08:00
|
|
|
.ForwardAs(o => "/p:VSTestNoBuild=true")),
|
|
|
|
CommonOptions.VerbosityOption());
|
|
|
|
|
|
|
|
private static string GetSemiColonEsacpedstring(string arg)
|
|
|
|
{
|
|
|
|
if (arg.IndexOf(";") != -1)
|
|
|
|
{
|
|
|
|
return arg.Replace(";", "%3b");
|
|
|
|
}
|
|
|
|
|
|
|
|
return arg;
|
|
|
|
}
|
|
|
|
|
|
|
|
private static string[] GetSemiColonEscapedArgs(IReadOnlyCollection<string> args)
|
|
|
|
{
|
|
|
|
int counter = 0;
|
|
|
|
string[] array = new string[args.Count];
|
|
|
|
|
|
|
|
foreach (string arg in args)
|
|
|
|
{
|
|
|
|
array[counter++] = GetSemiColonEsacpedstring(arg);
|
|
|
|
}
|
|
|
|
|
|
|
|
return array;
|
|
|
|
}
|
2017-03-06 11:57:19 -08:00
|
|
|
}
|
|
|
|
}
|