Merge pull request #9734 from peterhuene/fix-run-output

Suppress output from `dotnet run` when using quiet verbosity level.
This commit is contained in:
Peter Huene 2018-07-30 16:01:08 -07:00 committed by GitHub
commit fdfc1b668b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 1 deletions

View file

@ -26,6 +26,10 @@ namespace Microsoft.DotNet.Tools.Run
private List<string> _args; private List<string> _args;
private bool ShouldBuild => !NoBuild; private bool ShouldBuild => !NoBuild;
private bool HasQuietVerbosity =>
RestoreArgs.All(arg => !arg.StartsWith("-verbosity:", StringComparison.Ordinal) ||
arg.Equals("-verbosity:q", StringComparison.Ordinal) ||
arg.Equals("-verbosity:quiet", StringComparison.Ordinal));
public string LaunchProfile { get; private set; } public string LaunchProfile { get; private set; }
public bool NoLaunchProfile { get; private set; } public bool NoLaunchProfile { get; private set; }
@ -114,7 +118,10 @@ namespace Microsoft.DotNet.Tools.Run
var launchSettingsPath = Path.Combine(buildPathContainer, "Properties", "launchSettings.json"); var launchSettingsPath = Path.Combine(buildPathContainer, "Properties", "launchSettings.json");
if (File.Exists(launchSettingsPath)) if (File.Exists(launchSettingsPath))
{ {
if (!HasQuietVerbosity) {
Reporter.Output.WriteLine(string.Format(LocalizableStrings.UsingLaunchSettingsFromMessage, launchSettingsPath)); Reporter.Output.WriteLine(string.Format(LocalizableStrings.UsingLaunchSettingsFromMessage, launchSettingsPath));
}
string profileName = string.IsNullOrEmpty(LaunchProfile) ? LocalizableStrings.DefaultLaunchProfileDisplayName : LaunchProfile; string profileName = string.IsNullOrEmpty(LaunchProfile) ? LocalizableStrings.DefaultLaunchProfileDisplayName : LaunchProfile;
try try

View file

@ -343,6 +343,7 @@ namespace Microsoft.DotNet.Cli.Run.Tests
.WithSourceFiles(); .WithSourceFiles();
var testProjectDirectory = testInstance.Root.FullName; var testProjectDirectory = testInstance.Root.FullName;
var launchSettingsPath = Path.Combine(testProjectDirectory, "Properties", "launchSettings.json");
new RestoreCommand() new RestoreCommand()
.WithWorkingDirectory(testProjectDirectory) .WithWorkingDirectory(testProjectDirectory)
@ -359,6 +360,28 @@ namespace Microsoft.DotNet.Cli.Run.Tests
.ExecuteWithCapturedOutput(); .ExecuteWithCapturedOutput();
cmd.Should().Pass() cmd.Should().Pass()
.And.NotHaveStdOutContaining(string.Format(LocalizableStrings.UsingLaunchSettingsFromMessage, launchSettingsPath))
.And.HaveStdOutContaining("First");
cmd.StdErr.Should().BeEmpty();
}
[Fact]
public void ItPrintsUsingLaunchSettingsMessageWhenNotQuiet()
{
var testInstance = TestAssets.Get("AppWithLaunchSettings")
.CreateInstance()
.WithSourceFiles();
var testProjectDirectory = testInstance.Root.FullName;
var launchSettingsPath = Path.Combine(testProjectDirectory, "Properties", "launchSettings.json");
var cmd = new RunCommand()
.WithWorkingDirectory(testProjectDirectory)
.ExecuteWithCapturedOutput("-v:m");
cmd.Should().Pass()
.And.HaveStdOutContaining(string.Format(LocalizableStrings.UsingLaunchSettingsFromMessage, launchSettingsPath))
.And.HaveStdOutContaining("First"); .And.HaveStdOutContaining("First");
cmd.StdErr.Should().BeEmpty(); cmd.StdErr.Should().BeEmpty();