Skip to content

Default to DefaultConsoleWidth when DotNet says WindowWidth is 0 - #7465

Merged
Travis Plunk (TravisEz13) merged 5 commits into
PowerShell:masterfrom
TravisEz13:fix_vsts_subprocess_issue
Aug 7, 2018
Merged

Default to DefaultConsoleWidth when DotNet says WindowWidth is 0#7465
Travis Plunk (TravisEz13) merged 5 commits into
PowerShell:masterfrom
TravisEz13:fix_vsts_subprocess_issue

Conversation

@TravisEz13

@TravisEz13 Travis Plunk (TravisEz13) commented Aug 6, 2018

Copy link
Copy Markdown
Member

PR Summary

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.

PR Checklist

@iSazonov

Copy link
Copy Markdown
Collaborator

Travis Plunk (@TravisEz13) Please look #6883 - could we move commits from #6883 to the PR?

@TravisEz13

Copy link
Copy Markdown
Member Author

Ilya (@iSazonov) I knew I saw this before, thanks

internal static bool StopwatchIsNotHighResolution;
internal static bool DisableGACLoading;
internal static bool SetConsoleWidthToZero;
<<<<<<< HEAD

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

merge headers are left here.

# 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 | Select-Object -Last 1 | Should -Be 120

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

use

Format-table -inputobject $testObject | Out-String -Stream | ForEach-Object{$_.length} | Sort-Object -Bottom 1

# 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 | Select-Object -Last 1 | Should -Be 120
Format-Table -inputobject $testObject | Should -Not -BeNullOrEmpty

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

No needed i guess

@adityapatwardhan

Copy link
Copy Markdown
Member

Travis Plunk (@TravisEz13) There seems to be a new CodeFactor issue. Can you have a look.

@TravisEz13

Copy link
Copy Markdown
Member Author

The CodeFactor issue is basically an existing design issue around the test hooks

@TravisEz13
Travis Plunk (TravisEz13) merged commit d29349b into PowerShell:master Aug 7, 2018
@TravisEz13
Travis Plunk (TravisEz13) deleted the fix_vsts_subprocess_issue branch August 7, 2018 22:27
@iSazonov

Copy link
Copy Markdown
Collaborator

We have test\tools\Modules\HelpersHostCS\ - can we use it or we need a test system console?

@TravisEz13

Copy link
Copy Markdown
Member Author

We would have to have something that allows us to mock System.Console

@iSazonov

Copy link
Copy Markdown
Collaborator

I found related discussion https://stackoverflow.com/questions/5852862/mocking-system-console-behaviour
There is a link to https://blogs.msdn.microsoft.com/ploeh/2006/10/21/console-unit-testing/

[console]::SetOut looks interesting.

Thatgfsj (Thatgfsj) pushed a commit to Thatgfsj-contribs/PowerShell that referenced this pull request Aug 6, 2026
…erShell#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 PowerShell#6883 by @kalgiz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants