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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
18
test/dotnet-run.UnitTests/dotnet-run.UnitTests.xproj
Normal file
18
test/dotnet-run.UnitTests/dotnet-run.UnitTests.xproj
Normal file
|
@ -0,0 +1,18 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0.24720" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0.24720</VisualStudioVersion>
|
||||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.Props" Condition="'$(VSToolsPath)' != ''" />
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>2a5eec38-3030-44ef-9e58-6771e7bab01d</ProjectGuid>
|
||||
<RootNamespace>Microsoft.DotNet.Tools.Run.UnitTests</RootNamespace>
|
||||
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
|
||||
<OutputPath Condition="'$(OutputPath)'=='' ">..\..\artifacts\bin</OutputPath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.targets" Condition="'$(VSToolsPath)' != ''" />
|
||||
</Project>
|
27
test/dotnet-run.UnitTests/project.json
Normal file
27
test/dotnet-run.UnitTests/project.json
Normal file
|
@ -0,0 +1,27 @@
|
|||
{
|
||||
"version": "1.0.0-*",
|
||||
"dependencies": {
|
||||
"Microsoft.NETCore.App": {
|
||||
"type": "platform",
|
||||
"version": "1.0.0-rc3-*"
|
||||
},
|
||||
"System.Runtime.Serialization.Primitives": "4.1.1-rc2-24027",
|
||||
"dotnet": {
|
||||
"target": "project"
|
||||
},
|
||||
"Microsoft.DotNet.Tools.Tests.Utilities": {
|
||||
"target": "project"
|
||||
},
|
||||
"xunit": "2.1.0",
|
||||
"dotnet-test-xunit": "1.0.0-rc2-173361-36"
|
||||
},
|
||||
"frameworks": {
|
||||
"netcoreapp1.0": {
|
||||
"imports": [
|
||||
"dotnet5.4",
|
||||
"portable-net451+win8"
|
||||
]
|
||||
}
|
||||
},
|
||||
"testRunner": "xunit"
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue