Remove extra newlines from formatting which resulted in necessary double newlines (#8247)

This commit is contained in:
Steve Lee 2018-11-13 19:28:05 -08:00 committed by Ilya
parent 79f21b41de
commit 43e0394d51
7 changed files with 15 additions and 51 deletions

View file

@ -476,8 +476,6 @@ namespace Microsoft.PowerShell.Commands.Internal.Format
ComplexWriter writer = new ComplexWriter(); ComplexWriter writer = new ComplexWriter();
writer.Initialize(_lo, _lo.ColumnNumber); writer.Initialize(_lo, _lo.ColumnNumber);
writer.WriteObject(goc.Data.groupingEntry.formatValueList); writer.WriteObject(goc.Data.groupingEntry.formatValueList);
this.LineOutput.WriteLine(string.Empty);
} }
goc.GroupStart(); goc.GroupStart();
} }
@ -493,7 +491,6 @@ namespace Microsoft.PowerShell.Commands.Internal.Format
GroupOutputContext goc = (GroupOutputContext)c; GroupOutputContext goc = (GroupOutputContext)c;
goc.GroupEnd(); goc.GroupEnd();
this.LineOutput.WriteLine(string.Empty);
} }
/// <summary> /// <summary>
@ -761,7 +758,7 @@ namespace Microsoft.PowerShell.Commands.Internal.Format
/// </summary> /// </summary>
static private int GetConsoleWindowWidth(int columnNumber) static private int GetConsoleWindowWidth(int columnNumber)
{ {
if (InternalTestHooks.SetConsoleWidthToZero) if (InternalTestHooks.SetConsoleWidthToZero)
{ {
return DefaultConsoleWidth; return DefaultConsoleWidth;
} }
@ -1106,7 +1103,6 @@ namespace Microsoft.PowerShell.Commands.Internal.Format
/// </summary> /// </summary>
internal override void GroupStart() internal override void GroupStart()
{ {
this.InnerCommand._lo.WriteLine(string.Empty);
} }
/// <summary> /// <summary>
@ -1194,7 +1190,6 @@ namespace Microsoft.PowerShell.Commands.Internal.Format
/// </summary> /// </summary>
internal override void GroupStart() internal override void GroupStart()
{ {
this.InnerCommand._lo.WriteLine(string.Empty);
} }
/// <summary> /// <summary>

View file

@ -401,7 +401,7 @@ Describe 'ValidateSet support a dynamically generated set' -Tag "CI" {
Import-Module -Name $moduleFile -Force Import-Module -Name $moduleFile -Force
Test-ValidateSet 'Hello' | Should -BeExactly 'Hello' Test-ValidateSet 'Hello' | Should -BeExactly 'Hello'
} finally { } finally {
Remove-Module -Name $moduleFile -Force Remove-Module -Name $moduleFile -Force -ErrorAction SilentlyContinue
} }
} }
} }

View file

@ -589,7 +589,6 @@ visibleX visibleY
10 12 10 12
"@ "@
$tableOutput = $instance | Format-Table -AutoSize | Out-String $tableOutput = $instance | Format-Table -AutoSize | Out-String

View file

@ -399,16 +399,14 @@ Describe "Format-Custom with expression based EntrySelectedBy in a CustomControl
Entry selected by property Entry selected by property
Name Name
---- ----
testing testing
'@ -replace '\r?\n', "^"
'@ -replace '\r?\n', [Environment]::NewLine $ps.Invoke() -replace '\r?\n', "^" | Should -BeExactly $expectedOutput
$ps.Invoke() | Should -BeExactly $expectedOutput
$ps.Streams.Error | Should -BeNullOrEmpty $ps.Streams.Error | Should -BeNullOrEmpty
} }
@ -427,16 +425,14 @@ testing
Entry selected by ScriptBlock Entry selected by ScriptBlock
Name Name
---- ----
SelectScriptBlock SelectScriptBlock
'@ -replace '\r?\n', "^"
'@ -replace '\r?\n', [Environment]::NewLine $ps.Invoke() -replace '\r?\n', "^" | Should -BeExactly $expectedOutput
$ps.Invoke() | Should -BeExactly $expectedOutput
$ps.Streams.Error | Should -BeNullOrEmpty $ps.Streams.Error | Should -BeNullOrEmpty
} }
} }

View file

@ -23,7 +23,7 @@ Describe "Format-List" -Tags "CI" {
} }
It "Should produce the expected output" { It "Should produce the expected output" {
$expected = "${nl}${nl}testName : testValue${nl}${nl}${nl}${nl}" $expected = "${nl}testName : testValue${nl}${nl}${nl}"
$in = New-Object PSObject $in = New-Object PSObject
Add-Member -InputObject $in -MemberType NoteProperty -Name testName -Value testValue Add-Member -InputObject $in -MemberType NoteProperty -Name testName -Value testValue

View file

@ -338,7 +338,6 @@ gHeader
1 2 3 1 2 3
"@ }, "@ },
@{ view = "Default"; widths = 4,7,4; variation = "4 row, 1 row, 2 row"; expectedTable = @" @{ view = "Default"; widths = 4,7,4; variation = "4 row, 1 row, 2 row"; expectedTable = @"
@ -350,7 +349,6 @@ er
1 2 3 1 2 3
"@ }, "@ },
@{ view = "Default"; widths = 4,4,7; variation = "4 row, 2 row, 1 row"; expectedTable = @" @{ view = "Default"; widths = 4,4,7; variation = "4 row, 2 row, 1 row"; expectedTable = @"
@ -362,7 +360,6 @@ er
1 2 3 1 2 3
"@ }, "@ },
@{ view = "Default"; widths = 14,7,3; variation = "1 row, 1 row, 3 row"; expectedTable = @" @{ view = "Default"; widths = 14,7,3; variation = "1 row, 1 row, 3 row"; expectedTable = @"
@ -373,7 +370,6 @@ LongLongHeader Header2 Hea
1 2 3 1 2 3
"@ }, "@ },
@{ view = "One"; widths = 4,1,1; variation = "1 column"; expectedTable = @" @{ view = "One"; widths = 4,1,1; variation = "1 column"; expectedTable = @"
@ -385,7 +381,6 @@ er
1 1
"@ } "@ }
) { ) {
param($view, $widths, $expectedTable) param($view, $widths, $expectedTable)
@ -487,7 +482,6 @@ er
1**********2***3 1**********2***3
"@ }, "@ },
@{ view = "Default"; widths = 4,7,5; variation = "narrow values with wrap"; values = [PSCustomObject]@{First=1;Second=2;Third=3}; wrap = $true; expectedTable = @" @{ view = "Default"; widths = 4,7,5; variation = "narrow values with wrap"; values = [PSCustomObject]@{First=1;Second=2;Third=3}; wrap = $true; expectedTable = @"
@ -499,7 +493,6 @@ er
1**********2*3 1**********2*3
"@ }, "@ },
@{ view = "Default"; widths = 4,7,5; variation = "wide values"; values = [PSCustomObject]@{First="12345";Second="12345678";Third="123456"}; wrap = $false; expectedTable = @" @{ view = "Default"; widths = 4,7,5; variation = "wide values"; values = [PSCustomObject]@{First="12345";Second="12345678";Third="123456"}; wrap = $false; expectedTable = @"
@ -511,7 +504,6 @@ er
1...*...5678*12... 1...*...5678*12...
"@ }, "@ },
@{ view = "One"; widths = 3,1,1; variation = "wide values, 1 column"; values = [PSCustomObject]@{First="12345";Second="12345678";Third="123456"}; wrap = $false; expectedTable = @" @{ view = "One"; widths = 3,1,1; variation = "wide values, 1 column"; values = [PSCustomObject]@{First="12345";Second="12345678";Third="123456"}; wrap = $false; expectedTable = @"
@ -524,7 +516,6 @@ er
123 123
"@ }, "@ },
@{ view = "Default"; widths = 4,8,6; variation = "wide values with wrap, 1st column"; values = [PSCustomObject]@{First="12345";Second="12345678";Third="123456"}; wrap = $true; expectedTable = @" @{ view = "Default"; widths = 4,8,6; variation = "wide values with wrap, 1st column"; values = [PSCustomObject]@{First="12345";Second="12345678";Third="123456"}; wrap = $true; expectedTable = @"
@ -537,7 +528,6 @@ er
5 5
"@ }, "@ },
@{ view = "Default"; widths = 5,7,6; variation = "wide values with wrap, 2nd column"; values = [PSCustomObject]@{First="12345";Second="12345678";Third="123456"}; wrap = $true; expectedTable = @" @{ view = "Default"; widths = 5,7,6; variation = "wide values with wrap, 2nd column"; values = [PSCustomObject]@{First="12345";Second="12345678";Third="123456"}; wrap = $true; expectedTable = @"
@ -549,7 +539,6 @@ ader
************8 ************8
"@ }, "@ },
@{ view = "Default"; widths = 5,8,5; variation = "wide values with wrap, 3rd column"; values = [PSCustomObject]@{First="12345";Second="12345678";Third="123456"}; wrap = $true; expectedTable = @" @{ view = "Default"; widths = 5,8,5; variation = "wide values with wrap, 3rd column"; values = [PSCustomObject]@{First="12345";Second="12345678";Third="123456"}; wrap = $true; expectedTable = @"
@ -561,7 +550,6 @@ ader
***************6 ***************6
"@ }, "@ },
@{ view = "Default"; widths = 4,7,5; variation = "wide values with wrap, all 3 columns"; values = [PSCustomObject]@{First="12345";Second="12345678";Third="123456"}; wrap = $true; expectedTable = @" @{ view = "Default"; widths = 4,7,5; variation = "wide values with wrap, all 3 columns"; values = [PSCustomObject]@{First="12345";Second="12345678";Third="123456"}; wrap = $true; expectedTable = @"
@ -574,7 +562,6 @@ er
5**********8*6 5**********8*6
"@ }, "@ },
@{ view = "One"; widths = 3,1,1; variation = "wide values with wrap, with 1 column"; values = [PSCustomObject]@{First="12345";Second="12345678";Third="123456"}; wrap = $true; expectedTable = @" @{ view = "One"; widths = 3,1,1; variation = "wide values with wrap, with 1 column"; values = [PSCustomObject]@{First="12345";Second="12345678";Third="123456"}; wrap = $true; expectedTable = @"
@ -588,7 +575,6 @@ er
45 45
"@ } "@ }
) { ) {
param($view, $widths, $values, $wrap, $expectedTable) param($view, $widths, $values, $wrap, $expectedTable)
@ -690,7 +676,6 @@ abc bcd
1 1234 1 1234
"@ }, "@ },
@{ variation = "both columns"; obj = [pscustomobject]@{abc="1234";bcd="1234"},[pscustomobject]@{abc="1";bcd="1"}; expectedTable = @" @{ variation = "both columns"; obj = [pscustomobject]@{abc="1234";bcd="1234"},[pscustomobject]@{abc="1";bcd="1"}; expectedTable = @"
@ -700,7 +685,6 @@ abc bcd
1 1 1 1
"@ }, "@ },
@{ variation = "second column"; obj = [pscustomobject]@{abc="123";bcd="1234"},[pscustomobject]@{abc="1";bcd="123"}; expectedTable = @" @{ variation = "second column"; obj = [pscustomobject]@{abc="123";bcd="1234"},[pscustomobject]@{abc="1";bcd="123"}; expectedTable = @"
@ -710,7 +694,6 @@ abc bcd
1 123 1 123
"@ } "@ }
) { ) {
param($obj, $expectedTable) param($obj, $expectedTable)
@ -726,7 +709,6 @@ a b
abc 123 abc 123
"@ }, "@ },
@{ variation = "left/left"; obj = [PSCustomObject]@{a="abc";b="abc"}; expectedTable = @" @{ variation = "left/left"; obj = [PSCustomObject]@{a="abc";b="abc"}; expectedTable = @"
@ -735,7 +717,6 @@ a b
abc abc abc abc
"@ }, "@ },
@{ variation = "right/left"; obj = [PSCustomObject]@{a=123;b="abc"}; expectedTable = @" @{ variation = "right/left"; obj = [PSCustomObject]@{a=123;b="abc"}; expectedTable = @"
@ -744,7 +725,6 @@ abc abc
123 abc 123 abc
"@ }, "@ },
@{ variation = "right/right"; obj = [PSCustomObject]@{a=123;b=123}; expectedTable = @" @{ variation = "right/right"; obj = [PSCustomObject]@{a=123;b=123}; expectedTable = @"
@ -753,7 +733,6 @@ abc abc
123 123 123 123
"@ } "@ }
) { ) {
param($obj, $expectedTable) param($obj, $expectedTable)
@ -771,7 +750,6 @@ A B Name
multiline content multiline content
"@ }, "@ },
@{ variation = "left"; obj = [pscustomobject] @{Name="This`nIs some random`nmultiline content";A=1;B=2}; expectedTable = @" @{ variation = "left"; obj = [pscustomobject] @{Name="This`nIs some random`nmultiline content";A=1;B=2}; expectedTable = @"
@ -782,7 +760,6 @@ Is some random
multiline content multiline content
"@ }, "@ },
@{ variation = "middle"; obj = [pscustomobject] @{A=1;Name="This`nIs some random`nmultiline content";B=2}; expectedTable = @" @{ variation = "middle"; obj = [pscustomobject] @{A=1;Name="This`nIs some random`nmultiline content";B=2}; expectedTable = @"
@ -793,7 +770,6 @@ A Name B
multiline content multiline content
"@ } "@ }
) { ) {
param($obj, $expectedTable) param($obj, $expectedTable)

View file

@ -83,12 +83,11 @@ Describe "Out-File" -Tags "CI" {
$actual[3] | Should -Match "some test text" $actual[3] | Should -Match "some test text"
$actual[4] | Should -BeNullOrEmpty $actual[4] | Should -BeNullOrEmpty
$actual[5] | Should -BeNullOrEmpty $actual[5] | Should -BeNullOrEmpty
$actual[6] | Should -BeNullOrEmpty $actual[6] | Should -Match "text"
$actual[7] | Should -Match "text" $actual[7] | Should -Match "----"
$actual[8] | Should -Match "----" $actual[8] | Should -Match "some test text"
$actual[9] | Should -Match "some test text" $actual[9] | Should -BeNullOrEmpty
$actual[10] | Should -BeNullOrEmpty $actual[10] | Should -BeNullOrEmpty
$actual[11] | Should -BeNullOrEmpty
} }
It "Should limit each line to the specified number of characters when the width switch is used on objects" { It "Should limit each line to the specified number of characters when the width switch is used on objects" {
@ -119,12 +118,11 @@ Describe "Out-File" -Tags "CI" {
$actual[3] | Should -Match "some test text" $actual[3] | Should -Match "some test text"
$actual[4] | Should -BeNullOrEmpty $actual[4] | Should -BeNullOrEmpty
$actual[5] | Should -BeNullOrEmpty $actual[5] | Should -BeNullOrEmpty
$actual[6] | Should -BeNullOrEmpty $actual[6] | Should -Match "text"
$actual[7] | Should -Match "text" $actual[7] | Should -Match "----"
$actual[8] | Should -Match "----" $actual[8] | Should -Match "some test text"
$actual[9] | Should -Match "some test text" $actual[9] | Should -BeNullOrEmpty
$actual[10] | Should -BeNullOrEmpty $actual[10] | Should -BeNullOrEmpty
$actual[11] | Should -BeNullOrEmpty
# reset to not read only so it can be deleted # reset to not read only so it can be deleted
Set-ItemProperty -Path $testfile -Name IsReadOnly -Value $false Set-ItemProperty -Path $testfile -Name IsReadOnly -Value $false