diff --git a/build/Microsoft.DotNet.Cli.Compile.targets b/build/Microsoft.DotNet.Cli.Compile.targets index bdba43bc0..2029fa416 100644 --- a/build/Microsoft.DotNet.Cli.Compile.targets +++ b/build/Microsoft.DotNet.Cli.Compile.targets @@ -98,7 +98,7 @@ - + diff --git a/src/dotnet/commands/dotnet-test/LocalizableStrings.cs b/src/dotnet/commands/dotnet-test/LocalizableStrings.cs index d6fea1f23..71b08ef6f 100644 --- a/src/dotnet/commands/dotnet-test/LocalizableStrings.cs +++ b/src/dotnet/commands/dotnet-test/LocalizableStrings.cs @@ -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=]"""; public const string CmdConfiguration = "CONFIGURATION"; diff --git a/src/dotnet/commands/dotnet-test/Program.cs b/src/dotnet/commands/dotnet-test/Program.cs index cfe30728c..2d4e1c36c 100644 --- a/src/dotnet/commands/dotnet-test/Program.cs +++ b/src/dotnet/commands/dotnet-test/Program.cs @@ -23,7 +23,7 @@ namespace Microsoft.DotNet.Tools.Test FullName = LocalizableStrings.AppFullName, Description = LocalizableStrings.AppDescription, HandleRemainingArguments = true, - ArgumentSeparatorHelpText = HelpMessageStrings.MSBuildAdditionalArgsHelpText + ArgumentSeparatorHelpText = HelpMessageStrings.MSBuildAdditionalArgsHelpText }; 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); } @@ -166,7 +166,11 @@ namespace Microsoft.DotNet.Tools.Test } // Add remaining arguments that the parser did not understand, - msbuildArgs.AddRange(cmd.RemainingArguments); + if (cmd.RemainingArguments != null && cmd.RemainingArguments.Count > 0) + { + var arr = GetSemiColonEscapedArgs(cmd.RemainingArguments); + msbuildArgs.Add(string.Format("/p:VSTestCLIRunSettings=\"{0}\"", string.Join(";", arr))); + } return new MSBuildForwardingApp(msbuildArgs).Execute(); }); @@ -242,5 +246,27 @@ namespace Microsoft.DotNet.Tools.Test return projectFiles[0]; } + + private static string[] GetSemiColonEscapedArgs(List args) + { + int counter = 0; + string[] array = new string[args.Count]; + + foreach (string arg in args) + { + if (arg.IndexOf(";") != -1) + { + array[counter] = arg.Replace(";", "%3b"); + } + else + { + array[counter] = arg; + } + + counter++; + } + + return array; + } } } diff --git a/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigratePackageDependencies.cs b/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigratePackageDependencies.cs index 738222a81..a8f9b5135 100644 --- a/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigratePackageDependencies.cs +++ b/test/Microsoft.DotNet.ProjectJsonMigration.Tests/Rules/GivenThatIWantToMigratePackageDependencies.cs @@ -250,7 +250,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests mockProj.Items.Should().ContainSingle( i => (i.Include == "Microsoft.NET.Test.Sdk" && i.ItemType == "PackageReference" && - i.GetMetadataWithName("Version").Value == "15.0.0-preview-20161024-02" && + i.GetMetadataWithName("Version").Value == "15.0.0-preview-20161227-02" && i.GetMetadataWithName("Version").ExpressedAsAttribute)); mockProj.Items.Should().NotContain( @@ -283,7 +283,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests mockProj.Items.Should().ContainSingle( i => (i.Include == "Microsoft.NET.Test.Sdk" && i.ItemType == "PackageReference" && - i.GetMetadataWithName("Version").Value == "15.0.0-preview-20161024-02") && + i.GetMetadataWithName("Version").Value == "15.0.0-preview-20161227-02") && i.GetMetadataWithName("Version").ExpressedAsAttribute); mockProj.Items.Should().ContainSingle( @@ -325,7 +325,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests mockProj.Items.Should().ContainSingle( i => (i.Include == "Microsoft.NET.Test.Sdk" && i.ItemType == "PackageReference" && - i.GetMetadataWithName("Version").Value == "15.0.0-preview-20161024-02" && + i.GetMetadataWithName("Version").Value == "15.0.0-preview-20161227-02" && i.GetMetadataWithName("Version").ExpressedAsAttribute)); mockProj.Items.Should().ContainSingle( @@ -364,7 +364,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests mockProj.Items.Should().ContainSingle( i => (i.Include == "Microsoft.NET.Test.Sdk" && i.ItemType == "PackageReference" && - i.GetMetadataWithName("Version").Value == "15.0.0-preview-20161024-02" && + i.GetMetadataWithName("Version").Value == "15.0.0-preview-20161227-02" && i.GetMetadataWithName("Version").ExpressedAsAttribute)); mockProj.Items.Should().ContainSingle( diff --git a/test/dotnet-test.Tests/GivenDotnetTestBuildsAndRunsTestfromCsproj.cs b/test/dotnet-test.Tests/GivenDotnetTestBuildsAndRunsTestfromCsproj.cs index 9a06b5d4f..4a41e4819 100644 --- a/test/dotnet-test.Tests/GivenDotnetTestBuildsAndRunsTestfromCsproj.cs +++ b/test/dotnet-test.Tests/GivenDotnetTestBuildsAndRunsTestfromCsproj.cs @@ -101,7 +101,7 @@ namespace Microsoft.DotNet.Cli.Test.Tests [Fact] public void TestWillCreateTrxLogger() - { + { // Copy VSTestDotNetCore project in output directory of project dotnet-vstest.Tests string testAppName = "VSTestDotNetCore"; TestInstance testInstance = TestAssetsManager.CreateTestInstance(testAppName); @@ -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, "*.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() {