Merge pull request #5181 from harshjain2/clirunsettings
Added ability to pass runsettings as commandline parameters after --
This commit is contained in:
commit
80f2ef6533
5 changed files with 117 additions and 12 deletions
|
@ -32,7 +32,7 @@
|
|||
public const string CmdLoggerOption = "LoggerUri/FriendlyName";
|
||||
|
||||
public const string CmdLoggerDescription = @"Specify a logger for test results.
|
||||
Example: --logger:trx";
|
||||
Example: --logger ""trx[;LogFileName=<Defaults to unique file name>]""";
|
||||
|
||||
public const string CmdConfiguration = "CONFIGURATION";
|
||||
|
||||
|
@ -52,5 +52,8 @@
|
|||
Logs are written to the provided file.";
|
||||
|
||||
public const string CmdNoBuildDescription = @"Do not build project before testing.";
|
||||
|
||||
public const string RunSettingsArgsHelpText = @"Any extra commandline runsettings arguments that should be passed to vstest. See 'dotnet vstest --help' for available options.
|
||||
Example: -- RunConfiguration.ResultsDirectory=""C:\users\user\desktop\Results Directory"" MSTest.DeploymentEnabled=false";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ namespace Microsoft.DotNet.Tools.Test
|
|||
FullName = LocalizableStrings.AppFullName,
|
||||
Description = LocalizableStrings.AppDescription,
|
||||
HandleRemainingArguments = true,
|
||||
ArgumentSeparatorHelpText = HelpMessageStrings.MSBuildAdditionalArgsHelpText
|
||||
ArgumentSeparatorHelpText = LocalizableStrings.RunSettingsArgsHelpText
|
||||
};
|
||||
|
||||
cmd.HelpOption("-h|--help");
|
||||
|
@ -116,7 +116,7 @@ namespace Microsoft.DotNet.Tools.Test
|
|||
|
||||
if (loggerOption.HasValue())
|
||||
{
|
||||
msbuildArgs.Add($"/p:VSTestLogger={string.Join(";", loggerOption.Values)}");
|
||||
msbuildArgs.Add($"/p:VSTestLogger={string.Join(";", GetSemiColonEscapedArgs(loggerOption.Values))}");
|
||||
}
|
||||
|
||||
if (configurationOption.HasValue())
|
||||
|
@ -165,6 +165,13 @@ namespace Microsoft.DotNet.Tools.Test
|
|||
msbuildArgs.Add(argRoot.Value);
|
||||
}
|
||||
|
||||
// Get runsetings options specified after --
|
||||
if (cmd.RemainingArguments != null && cmd.RemainingArguments.Count > 0)
|
||||
{
|
||||
var runSettingsOptions = GetRunSettingsOptions(cmd.RemainingArguments);
|
||||
msbuildArgs.Add(string.Format("/p:VSTestCLIRunSettings=\"{0}\"", string.Join(";", runSettingsOptions)));
|
||||
}
|
||||
|
||||
// Add remaining arguments that the parser did not understand,
|
||||
msbuildArgs.AddRange(cmd.RemainingArguments);
|
||||
|
||||
|
@ -242,5 +249,59 @@ namespace Microsoft.DotNet.Tools.Test
|
|||
|
||||
return projectFiles[0];
|
||||
}
|
||||
|
||||
private static string[] GetRunSettingsOptions(List<string> remainingArgs)
|
||||
{
|
||||
List<string> runsettingsArgs = new List<string>();
|
||||
List<string> argsToRemove = new List<string>();
|
||||
|
||||
bool readRunSettings = false;
|
||||
foreach (string arg in remainingArgs)
|
||||
{
|
||||
if (!readRunSettings)
|
||||
{
|
||||
if (arg.Equals("--"))
|
||||
{
|
||||
readRunSettings = true;
|
||||
argsToRemove.Add(arg);
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
runsettingsArgs.Add(GetSemiColonEsacpedstring(arg));
|
||||
argsToRemove.Add(arg);
|
||||
}
|
||||
|
||||
foreach (string arg in argsToRemove)
|
||||
{
|
||||
remainingArgs.Remove(arg);
|
||||
}
|
||||
|
||||
return runsettingsArgs.ToArray();
|
||||
}
|
||||
|
||||
private static string GetSemiColonEsacpedstring(string arg)
|
||||
{
|
||||
if (arg.IndexOf(";") != -1)
|
||||
{
|
||||
return arg.Replace(";", "%3b");
|
||||
}
|
||||
|
||||
return arg;
|
||||
}
|
||||
|
||||
private static string[] GetSemiColonEscapedArgs(List<string> args)
|
||||
{
|
||||
int counter = 0;
|
||||
string[] array = new string[args.Count];
|
||||
|
||||
foreach (string arg in args)
|
||||
{
|
||||
array[counter++] = GetSemiColonEsacpedstring(arg);
|
||||
}
|
||||
|
||||
return array;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -140,6 +140,47 @@ namespace Microsoft.DotNet.Cli.Test.Tests
|
|||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ItCreatesTrxReportInTheSpecifiedResultsDirectory()
|
||||
{
|
||||
// Copy VSTestDotNetCore project in output directory of project dotnet-vstest.Tests
|
||||
string testAppName = "VSTestDotNetCore";
|
||||
TestInstance testInstance = TestAssetsManager.CreateTestInstance(testAppName);
|
||||
|
||||
string testProjectDirectory = testInstance.TestRoot;
|
||||
|
||||
// Restore project VSTestDotNetCore
|
||||
new RestoreCommand()
|
||||
.WithWorkingDirectory(testProjectDirectory)
|
||||
.Execute()
|
||||
.Should()
|
||||
.Pass();
|
||||
|
||||
string trxLoggerDirectory = Path.Combine(testProjectDirectory, "ResultsDirectory");
|
||||
|
||||
// Delete trxLoggerDirectory if it exist
|
||||
if (Directory.Exists(trxLoggerDirectory))
|
||||
{
|
||||
Directory.Delete(trxLoggerDirectory, true);
|
||||
}
|
||||
|
||||
// Call test with logger enable
|
||||
CommandResult result = new DotnetTestCommand()
|
||||
.WithWorkingDirectory(testProjectDirectory)
|
||||
.ExecuteWithCapturedOutput("--logger \"trx;logfilename=custom.trx\" -- RunConfiguration.ResultsDirectory=" + trxLoggerDirectory);
|
||||
|
||||
// Verify
|
||||
String[] trxFiles = Directory.GetFiles(trxLoggerDirectory, "custom.trx");
|
||||
Assert.Equal(1, trxFiles.Length);
|
||||
result.StdOut.Should().Contain(trxFiles[0]);
|
||||
|
||||
// Cleanup trxLoggerDirectory if it exist
|
||||
if (Directory.Exists(trxLoggerDirectory))
|
||||
{
|
||||
Directory.Delete(trxLoggerDirectory, true);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact(Skip = "https://github.com/dotnet/cli/issues/5035")]
|
||||
public void ItBuildsAndTestsAppWhenRestoringToSpecificDirectory()
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue