From b584750620781162ff1db8968d7529984ce17e4b Mon Sep 17 00:00:00 2001 From: Mayank Bansal Date: Thu, 17 May 2018 12:54:39 +0530 Subject: [PATCH] Multiple Logger/TestAdapter inputs from dotnet CLI --- .../commands/dotnet-test/TestCommandParser.cs | 10 +++--- ...enDotnetTestBuildsAndRunsTestfromCsproj.cs | 33 +++++++++++++++++++ 2 files changed, 38 insertions(+), 5 deletions(-) diff --git a/src/dotnet/commands/dotnet-test/TestCommandParser.cs b/src/dotnet/commands/dotnet-test/TestCommandParser.cs index 4568e402d..7236a1545 100644 --- a/src/dotnet/commands/dotnet-test/TestCommandParser.cs +++ b/src/dotnet/commands/dotnet-test/TestCommandParser.cs @@ -40,19 +40,19 @@ namespace Microsoft.DotNet.Cli Create.Option( "-a|--test-adapter-path", LocalizableStrings.CmdTestAdapterPathDescription, - Accept.ExactlyOneArgument() + Accept.OneOrMoreArguments() .With(name: LocalizableStrings.CmdTestAdapterPath) - .ForwardAsSingle(o => $"-property:VSTestTestAdapterPath={o.Arguments.Single()}")), + .ForwardAsSingle(o => $"-property:VSTestTestAdapterPath=\"{string.Join(";", o.Arguments)}\"")), Create.Option( "-l|--logger", LocalizableStrings.CmdLoggerDescription, - Accept.ExactlyOneArgument() + Accept.OneOrMoreArguments() .With(name: LocalizableStrings.CmdLoggerOption) .ForwardAsSingle(o => { var loggersString = string.Join(";", GetSemiColonEscapedArgs(o.Arguments)); - return $"-property:VSTestLogger={loggersString}"; + return $"-property:VSTestLogger=\"{loggersString}\""; })), CommonOptions.ConfigurationOption(), CommonOptions.FrameworkOption(), @@ -116,4 +116,4 @@ namespace Microsoft.DotNet.Cli return array; } } -} \ No newline at end of file +} diff --git a/test/dotnet-test.Tests/GivenDotnetTestBuildsAndRunsTestfromCsproj.cs b/test/dotnet-test.Tests/GivenDotnetTestBuildsAndRunsTestfromCsproj.cs index 8120df7c9..1a8dddf88 100644 --- a/test/dotnet-test.Tests/GivenDotnetTestBuildsAndRunsTestfromCsproj.cs +++ b/test/dotnet-test.Tests/GivenDotnetTestBuildsAndRunsTestfromCsproj.cs @@ -131,6 +131,39 @@ namespace Microsoft.DotNet.Cli.Test.Tests } } + [Fact] + public void ItAcceptsMultipleLoggersAsCliArguments() + { + // Copy and restore VSTestCore project in output directory of project dotnet-vstest.Tests + var testProjectDirectory = this.CopyAndRestoreVSTestDotNetCoreTestApp("10"); + + string trxLoggerDirectory = Path.Combine(testProjectDirectory, "RD"); + + // 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\" --logger console;verbosity=normal -- RunConfiguration.ResultsDirectory=" + trxLoggerDirectory); + + // Verify + var trxFilePath = Path.Combine(trxLoggerDirectory, "custom.trx"); + Assert.True(File.Exists(trxFilePath)); + result.StdOut.Should().Contain(trxFilePath); + result.StdOut.Should().Contain("Passed VSTestPassTest"); + result.StdOut.Should().Contain("Failed VSTestFailTest"); + + // Cleanup trxLoggerDirectory if it exist + if (Directory.Exists(trxLoggerDirectory)) + { + Directory.Delete(trxLoggerDirectory, true); + } + } + [Fact] public void TestWillNotBuildTheProjectIfNoBuildArgsIsGiven() {