Default to DefaultConsoleWidth when DotNet says WindowWidth is 0 (#7465)

Default to DefaultConsoleWidth when DotNet says WindowWidth is 0

This resolves an issue in an environment like VSTS when pwsh is spawned and DotNet is not able to determine the Console Width.
* Port changes from #6883 by @kalgiz
This commit is contained in:
Travis Plunk
2018-08-07 15:27:42 -07:00
committed by GitHub
parent 1523c218a6
commit d29349bb4d
3 changed files with 23 additions and 1 deletions
@@ -800,4 +800,18 @@ A Name B
$output = $obj | Format-Table -Wrap | Out-String
$output.Replace("`r","").Replace(" ",".").Replace("`n","^") | Should -BeExactly $expectedTable.Replace("`r","").Replace(" ",".").Replace("`n","^")
}
It "Should not return null when the Console width is equal to 0" {
[system.management.automation.internal.internaltesthooks]::SetTestHook('SetConsoleWidthToZero', $true)
try
{
# Fill the console window with the string, so that it reaches its max width.
# Check if the max width is equal to default value (120), to test test hook set.
$testObject = @{ test = '1' * 200}
Format-table -inputobject $testObject | Out-String -Stream | ForEach-Object{$_.length} | Sort-Object -Bottom 1 | Should -Be 120
}
finally {
[system.management.automation.internal.internaltesthooks]::SetTestHook('SetConsoleWidthToZero', $false)
}
}
}