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
|
@ -97,7 +97,7 @@
|
|||
|
||||
<!-- Workaround for https://github.com/dotnet/sdk/issues/115 -->
|
||||
<ItemGroup>
|
||||
<HackFilesToCopy Include="$(NuGetPackagesDir)\microsoft.build.runtime\$(CLI_MSBuild_Version)\contentFiles\any\netcoreapp1.0\**;$(NuGetPackagesDir)\microsoft.codeanalysis.build.tasks\2.0.0-beta6-60922-08\contentFiles\any\any\**;$(NuGetPackagesDir)\microsoft.testplatform.cli\$(CLI_TestPlatform_Version)\contentFiles\any\any\**" />
|
||||
<HackFilesToCopy Include="$(NuGetPackagesDir)\microsoft.build.runtime\$(CLI_MSBuild_Version)\contentFiles\any\netcoreapp1.0\**;$(NuGetPackagesDir)\microsoft.codeanalysis.build.tasks\2.0.0-beta6-60922-08\contentFiles\any\any\**;$(NuGetPackagesDir)\microsoft.testplatform.cli\$(CLI_TestPlatform_Version)\contentFiles\any\any\**" />
|
||||
</ItemGroup>
|
||||
<Copy SourceFiles="@(HackFilesToCopy)"
|
||||
DestinationFiles="@(HackFilesToCopy->'$(SdkOutputDirectory)/%(RecursiveDir)%(Filename)%(Extension)')" />
|
||||
|
|
|
@ -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())
|
||||
|
@ -155,7 +155,7 @@ namespace Microsoft.DotNet.Tools.Test
|
|||
|
||||
string defaultproject = GetSingleTestProjectToRunTestIfNotProvided(argRoot.Value, cmd.RemainingArguments);
|
||||
|
||||
if(!string.IsNullOrEmpty(defaultproject))
|
||||
if (!string.IsNullOrEmpty(defaultproject))
|
||||
{
|
||||
msbuildArgs.Add(defaultproject);
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,8 +24,8 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
|
|||
""BPackage"" : ""1.0.0""
|
||||
}
|
||||
}");
|
||||
|
||||
EmitsPackageReferences(mockProj, Tuple.Create("APackage", "1.0.0-preview", ""), Tuple.Create("BPackage", "1.0.0", ""));
|
||||
|
||||
EmitsPackageReferences(mockProj, Tuple.Create("APackage", "1.0.0-preview", ""), Tuple.Create("BPackage", "1.0.0", ""));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
@ -158,8 +158,8 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
|
|||
""BPackage"" : ""1.0.0""
|
||||
}
|
||||
}");
|
||||
|
||||
EmitsToolReferences(mockProj, Tuple.Create("APackage", "1.0.0-preview"), Tuple.Create("BPackage", "1.0.0"));
|
||||
|
||||
EmitsToolReferences(mockProj, Tuple.Create("APackage", "1.0.0-preview"), Tuple.Create("BPackage", "1.0.0"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
@ -301,19 +301,19 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
|
|||
}");
|
||||
|
||||
mockProj.Items.Should().ContainSingle(
|
||||
i => (i.Include == "Microsoft.NET.Test.Sdk" &&
|
||||
i => (i.Include == "Microsoft.NET.Test.Sdk" &&
|
||||
i.ItemType == "PackageReference" &&
|
||||
i.GetMetadataWithName("Version").Value == "15.0.0-preview-20161227-02") &&
|
||||
i.GetMetadataWithName("Version").ExpressedAsAttribute);
|
||||
|
||||
mockProj.Items.Should().ContainSingle(
|
||||
i => (i.Include == "xunit" &&
|
||||
i => (i.Include == "xunit" &&
|
||||
i.ItemType == "PackageReference" &&
|
||||
i.GetMetadataWithName("Version").Value == "2.2.0-beta4-build3444" &&
|
||||
i.GetMetadataWithName("Version").ExpressedAsAttribute));
|
||||
|
||||
mockProj.Items.Should().ContainSingle(
|
||||
i => (i.Include == "xunit.runner.visualstudio" &&
|
||||
i => (i.Include == "xunit.runner.visualstudio" &&
|
||||
i.ItemType == "PackageReference" &&
|
||||
i.GetMetadataWithName("Version").Value == "2.2.0-beta4-build1194" &&
|
||||
i.GetMetadataWithName("Version").ExpressedAsAttribute));
|
||||
|
|
|
@ -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