Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix infinite loop on redirect to file #184

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/NuGet.Clients/NuGet.CommandLine/Common/Console.cs
Expand Up @@ -53,7 +53,17 @@ public int WindowWidth
{
try
{
return System.Console.WindowWidth;
var width = System.Console.WindowWidth;
if (width > 0)
{
return width;
}
else
{
// This happens when redirecting output to a file, on
// Linux and OS X (running with Mono).
return 80;
}
}
catch (IOException)
{
Expand Down Expand Up @@ -383,4 +393,4 @@ public void LogError(string data)
WriteError(data);
}
}
}
}
15 changes: 15 additions & 0 deletions test/NuGet.Clients.Tests/NuGet.CommandLine.Test/ConsoleTest.cs
@@ -0,0 +1,15 @@
using System;
using NuGet.Test.Utility;
using Xunit;

namespace NuGet.CommandLine.Test
{
public class ConsoleTest
{
[Fact]
public void TestConsoleWindowWidthNotZero()
{
Assert.NotEqual(0, new NuGet.Common.Console().WindowWidth);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test will only be relevant if someone runs the tests on Linux, with output redirect. I tried messing around with System.Console.SetOut() and the like at runtime, but Mono does some initialization before that, so it won't apply.

}
}
}
Expand Up @@ -57,6 +57,7 @@
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
</ItemGroup>
<ItemGroup>
<Compile Include="ConsoleTest.cs" />
<Compile Include="DefaultConfigurationFilePreserver.cs" />
<Compile Include="MockServer.cs" />
<Compile Include="MockServerResource.Designer.cs">
Expand Down