Console.Write() doesn't show output until a newline
When running an app with `dotnet run`, we are redirecting the standard out and error just to print it out to our standard out and error. However, we are batching the output until we hit a newline, which isn't ideal for console apps. To fix this, `dotnet run` no longer redirects the standard out and error. Fix #2777
This commit is contained in:
parent
6482aa0221
commit
6bf59ffde6
7 changed files with 241 additions and 20 deletions
122
test/dotnet-run.UnitTests/GivenARunCommand.cs
Normal file
122
test/dotnet-run.UnitTests/GivenARunCommand.cs
Normal file
|
@ -0,0 +1,122 @@
|
|||
// Copyright (c) .NET Foundation and contributors. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using FluentAssertions;
|
||||
using Microsoft.DotNet.Cli.Utils;
|
||||
using Microsoft.DotNet.TestFramework;
|
||||
using Microsoft.DotNet.Tools.Test.Utilities;
|
||||
using NuGet.Frameworks;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.DotNet.Tools.Run.Tests
|
||||
{
|
||||
public class GivenARunCommand : TestBase
|
||||
{
|
||||
private const int RunExitCode = 29;
|
||||
|
||||
[Fact]
|
||||
public void ItDoesntRedirectStandardOutAndError()
|
||||
{
|
||||
TestInstance instance = TestAssetsManager.CreateTestInstance("TestAppSimple")
|
||||
.WithLockFiles();
|
||||
|
||||
new BuildCommand(instance.TestRoot)
|
||||
.Execute()
|
||||
.Should()
|
||||
.Pass();
|
||||
|
||||
RunCommand runCommand = new RunCommand(new FailOnRedirectOutputCommandFactory());
|
||||
runCommand.Project = instance.TestRoot;
|
||||
|
||||
runCommand.Start()
|
||||
.Should()
|
||||
.Be(RunExitCode);
|
||||
}
|
||||
|
||||
private class FailOnRedirectOutputCommandFactory : ICommandFactory
|
||||
{
|
||||
public ICommand Create(string commandName, IEnumerable<string> args, NuGetFramework framework = null, string configuration = "Debug")
|
||||
{
|
||||
return new FailOnRedirectOutputCommand();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A Command that will fail if a caller tries redirecting StdOut or StdErr.
|
||||
/// </summary>
|
||||
private class FailOnRedirectOutputCommand : ICommand
|
||||
{
|
||||
public CommandResult Execute()
|
||||
{
|
||||
return new CommandResult(null, RunExitCode, null, null);
|
||||
}
|
||||
|
||||
public ICommand CaptureStdErr()
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
public ICommand CaptureStdOut()
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
public ICommand ForwardStdErr(TextWriter to = null, bool onlyIfVerbose = false, bool ansiPassThrough = true)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
public ICommand ForwardStdOut(TextWriter to = null, bool onlyIfVerbose = false, bool ansiPassThrough = true)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
public ICommand OnErrorLine(Action<string> handler)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
public ICommand OnOutputLine(Action<string> handler)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
public string CommandArgs
|
||||
{
|
||||
get
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
public string CommandName
|
||||
{
|
||||
get
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
public CommandResolutionStrategy ResolutionStrategy
|
||||
{
|
||||
get
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
public ICommand EnvironmentVariable(string name, string value)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public ICommand WorkingDirectory(string projectDirectory)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue