From 357fd3daf1e55df9d1c6522c88c0bddb485113d6 Mon Sep 17 00:00:00 2001 From: Livar Cunha Date: Thu, 18 May 2017 14:13:01 -0700 Subject: [PATCH] Fixing restore so that it respects the verbosity param. The problem was that ConsoleLoggerParameters was overwritting whatever was coming through the command line. --- src/dotnet/commands/dotnet-restore/Program.cs | 8 ++++-- .../GivenDotnetRestoreInvocation.cs | 25 +++++++++++++++---- .../GivenThatIWantToRestoreApp.cs | 25 +++++++++++++++++++ 3 files changed, 51 insertions(+), 7 deletions(-) diff --git a/src/dotnet/commands/dotnet-restore/Program.cs b/src/dotnet/commands/dotnet-restore/Program.cs index e06ddc42d..65a18e975 100644 --- a/src/dotnet/commands/dotnet-restore/Program.cs +++ b/src/dotnet/commands/dotnet-restore/Program.cs @@ -34,10 +34,14 @@ namespace Microsoft.DotNet.Tools.Restore var msbuildArgs = new List { "/NoLogo", - "/t:Restore", - "/ConsoleLoggerParameters:Verbosity=Minimal" + "/t:Restore" }; + if (!parsedRestore.HasOption("verbosity")) + { + msbuildArgs.Add("/ConsoleLoggerParameters:Verbosity=Minimal"); + } + msbuildArgs.AddRange(parsedRestore.OptionValuesToBeForwarded()); msbuildArgs.AddRange(parsedRestore.Arguments); diff --git a/test/dotnet-msbuild.Tests/GivenDotnetRestoreInvocation.cs b/test/dotnet-msbuild.Tests/GivenDotnetRestoreInvocation.cs index c900a6d48..dd55e2abd 100644 --- a/test/dotnet-msbuild.Tests/GivenDotnetRestoreInvocation.cs +++ b/test/dotnet-msbuild.Tests/GivenDotnetRestoreInvocation.cs @@ -10,7 +10,11 @@ namespace Microsoft.DotNet.Cli.MSBuild.Tests { public class GivenDotnetRestoreInvocation { - const string ExpectedPrefix = "exec /m /v:m /NoLogo /t:Restore /ConsoleLoggerParameters:Verbosity=Minimal"; + private const string ExpectedPrefix = + "exec /m /v:m /NoLogo /t:Restore"; + + private string ExpectedPrefixWithConsoleLoggerParamaters = + $"{ExpectedPrefix} /ConsoleLoggerParameters:Verbosity=Minimal"; [Theory] [InlineData(new string[] { }, "")] @@ -26,15 +30,26 @@ namespace Microsoft.DotNet.Cli.MSBuild.Tests [InlineData(new string[] { "--no-cache" }, "/p:RestoreNoCache=true")] [InlineData(new string[] { "--ignore-failed-sources" }, "/p:RestoreIgnoreFailedSources=true")] [InlineData(new string[] { "--no-dependencies" }, "/p:RestoreRecursive=false")] - [InlineData(new string[] { "-v", "minimal" }, @"/verbosity:minimal")] - [InlineData(new string[] { "--verbosity", "minimal" }, @"/verbosity:minimal")] - public void MsbuildInvocationIsCorrect(string[] args, string expectedAdditionalArgs) + public void MsbuildInvocationWithConsoleLoggerParametersIsCorrect(string[] args, string expectedAdditionalArgs) { expectedAdditionalArgs = (string.IsNullOrEmpty(expectedAdditionalArgs) ? "" : $" {expectedAdditionalArgs}"); var msbuildPath = ""; RestoreCommand.FromArgs(args, msbuildPath) - .GetProcessStartInfo().Arguments.Should().Be($"{ExpectedPrefix}{expectedAdditionalArgs}"); + .GetProcessStartInfo().Arguments + .Should().Be($"{ExpectedPrefixWithConsoleLoggerParamaters}{expectedAdditionalArgs}"); + } + + [InlineData(new string[] { "-v", "minimal" }, @"/verbosity:minimal")] + [InlineData(new string[] { "--verbosity", "minimal" }, @"/verbosity:minimal")] + public void MsbuildInvocationWithVerbosityIsCorrect(string[] args, string expectedAdditionalArgs) + { + expectedAdditionalArgs = (string.IsNullOrEmpty(expectedAdditionalArgs) ? "" : $" {expectedAdditionalArgs}"); + + var msbuildPath = ""; + RestoreCommand.FromArgs(args, msbuildPath) + .GetProcessStartInfo().Arguments + .Should().Be($"{ExpectedPrefix}{expectedAdditionalArgs}"); } } } diff --git a/test/dotnet-restore.Tests/GivenThatIWantToRestoreApp.cs b/test/dotnet-restore.Tests/GivenThatIWantToRestoreApp.cs index 3b5c44b42..40afaea2e 100644 --- a/test/dotnet-restore.Tests/GivenThatIWantToRestoreApp.cs +++ b/test/dotnet-restore.Tests/GivenThatIWantToRestoreApp.cs @@ -89,5 +89,30 @@ namespace Microsoft.DotNet.Restore.Tests Directory.Exists(fullPath).Should().BeTrue(); Directory.EnumerateFiles(fullPath, "*.dll", SearchOption.AllDirectories).Count().Should().BeGreaterThan(0); } + + [Fact] + public void ItRestoresWithTheSpecifiedVerbosity() + { + var rootPath = TestAssets.CreateTestDirectory().FullName; + + string dir = "pkgs"; + string fullPath = Path.GetFullPath(Path.Combine(rootPath, dir)); + + string newArgs = $"console -o \"{rootPath}\" --no-restore"; + new NewCommandShim() + .WithWorkingDirectory(rootPath) + .Execute(newArgs) + .Should() + .Pass(); + + string args = $"--configfile {RepoRootNuGetConfig} --packages \"{dir}\" --verbosity quiet"; + new RestoreCommand() + .WithWorkingDirectory(rootPath) + .ExecuteWithCapturedOutput(args) + .Should() + .Pass() + .And.NotHaveStdErr() + .And.NotHaveStdOut(); + } } }