Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions test/powershell/Host/PSVersionTable.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ Describe "PSVersionTable" -Tags "CI" {

It "Verify `$PSVersionTable is ordered and 'PSVersion' is on first place" {
$PSVersionName = "PSVersion"
$keys1 = ($PSVersionTable | Format-Table -HideTableHeaders -Property Name | Out-String) -split [System.Environment]::NewLine | Where-Object {$_} | ForEach-Object {$_.Trim()}
$keys1 = ($PSVersionTable | Format-Table -HideTableHeaders -Property Name | Out-String -Width 120) -split [System.Environment]::NewLine | Where-Object {$_} | ForEach-Object {$_.Trim()}

$keys1[0] | Should -Be "PSVersion"
$keys1[1] | Should -Be "PSEdition"
Expand All @@ -112,7 +112,7 @@ Describe "PSVersionTable" -Tags "CI" {
$VersionValue = $PSVersionTable["PSVersion"]
$PSVersionTable.Remove("PSVersion")

$keys1 = ($PSVersionTable | Format-Table -HideTableHeaders -Property Name | Out-String) -split [System.Environment]::NewLine | Where-Object {$_} | ForEach-Object {$_.Trim()}
$keys1 = ($PSVersionTable | Format-Table -HideTableHeaders -Property Name | Out-String -Width 120) -split [System.Environment]::NewLine | Where-Object {$_} | ForEach-Object {$_.Trim()}
$keys1[0] | Should -Be "PSEdition"
$keys1.Length | Should -Be $PSVersionTable.Count

Expand All @@ -129,7 +129,7 @@ Describe "PSVersionTable" -Tags "CI" {
$EditionValue = $PSVersionTable["PSEdition"]
$PSVersionTable.Remove("PSEdition")

$keys1 = ($PSVersionTable | Format-Table -HideTableHeaders -Property Name | Out-String) -split [System.Environment]::NewLine | Where-Object {$_} | ForEach-Object {$_.Trim()}
$keys1 = ($PSVersionTable | Format-Table -HideTableHeaders -Property Name | Out-String -Width 120) -split [System.Environment]::NewLine | Where-Object {$_} | ForEach-Object {$_.Trim()}
$keys1[0] | Should -Be "PSVersion"
$keys1.Length | Should -Be $PSVersionTable.Count

Expand All @@ -148,7 +148,7 @@ Describe "PSVersionTable" -Tags "CI" {
$PSVersionTable.Remove("PSVersion")
$PSVersionTable.Remove("PSEdition")

$keys1 = ($PSVersionTable | Format-Table -HideTableHeaders -Property Name | Out-String) -split [System.Environment]::NewLine | Where-Object {$_} | ForEach-Object {$_.Trim()}
$keys1 = ($PSVersionTable | Format-Table -HideTableHeaders -Property Name | Out-String -Width 120) -split [System.Environment]::NewLine | Where-Object {$_} | ForEach-Object {$_.Trim()}
$keys1.Length | Should -Be $PSVersionTable.Count

$keys1sortedlast = $keys1 | Sort-Object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ Describe 'Hidden Members Test ' -Tags "CI" {
It "Access hidden property should still work" { $instance.hiddenZ | Should -Be 42 }

# Formatting should not include hidden members by default
$tableOutput = $instance | Format-Table -HideTableHeaders -AutoSize | Out-String
$tableOutput = $instance | Format-Table -HideTableHeaders -AutoSize | Out-String -Width 120
It "Table formatting should not have included hidden member hiddenZ - should contain 10" { $tableOutput.Contains(10) | Should -BeTrue}
It "Table formatting should not have included hidden member hiddenZ- should contain 12" { $tableOutput.Contains(12) | Should -BeTrue}
It "Table formatting should not have included hidden member hiddenZ - should not contain 42" { $tableOutput.Contains(42) | Should -BeFalse}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,67 +30,60 @@ Describe "Format-Table" -Tags "CI" {
$al = (0..255)
$info = @{}
$info.array = $al
$result = $info | Format-Table | Out-String
$result = $info | Format-Table | Out-String -Width 120
$result | Should -Match "array\s+{0, 1, 2, 3...}"
}

It "Format-Table with Negative Count should work" {
$FormatEnumerationLimit = -1
$result = Format-Table -inputobject @{'test'= 1, 2}
$resultStr = $result | Out-String
$resultStr | Should -Match "test\s+{1, 2}"
$result = Format-Table -inputobject @{'test'= 1, 2} | Out-String -Width 120
$result | Should -Match "test\s+{1, 2}"
}

# Pending on issue#888
It "Format-Table with Zero Count should work" -Pending {
$FormatEnumerationLimit = 0
$result = Format-Table -inputobject @{'test'= 1, 2}
$resultStr = $result | Out-String
$resultStr | Should -Match "test\s+{...}"
$result = Format-Table -inputobject @{'test'= 1, 2} | Out-String -Width 120
$result | Should -Match "test\s+{...}"
}

It "Format-Table with Less Count should work" {
$FormatEnumerationLimit = 1
$result = Format-Table -inputobject @{'test'= 1, 2}
$resultStr = $result | Out-String
$resultStr | Should -Match "test\s+{1...}"
$result = Format-Table -inputobject @{'test'= 1, 2} | Out-String -Width 120
$result | Should -Match "test\s+{1...}"
}

It "Format-Table with More Count should work" {
$FormatEnumerationLimit = 10
$result = Format-Table -inputobject @{'test'= 1, 2}
$resultStr = $result | Out-String
$resultStr | Should -Match "test\s+{1, 2}"
$result = Format-Table -inputobject @{'test'= 1, 2} | Out-String -Width 120
$result | Should -Match "test\s+{1, 2}"
}

It "Format-Table with Equal Count should work" {
$FormatEnumerationLimit = 2
$result = Format-Table -inputobject @{'test'= 1, 2}
$resultStr = $result | Out-String
$resultStr | Should -Match "test\s+{1, 2}"
$result = Format-Table -inputobject @{'test'= 1, 2} | Out-String -Width 120
$result | Should -Match "test\s+{1, 2}"
}

# Pending on issue#888
It "Format-Table with Bogus Count should throw Exception" -Pending {
$FormatEnumerationLimit = "abc"
$result = Format-Table -inputobject @{'test'= 1, 2}
$resultStr = $result|Out-String
$resultStr | Should -Match "test\s+{1, 2}"
$result = Format-Table -inputobject @{'test'= 1, 2} | Out-String
$result | Should -Match "test\s+{1, 2}"
}

# Pending on issue#888
It "Format-Table with Var Deleted should throw Exception" -Pending {
$FormatEnumerationLimit = 2
Remove-Variable FormatEnumerationLimit
$result = Format-Table -inputobject @{'test'= 1, 2}
$resultStr = $result | Out-String
$resultStr | Should -Match "test\s+{1, 2}"
$result = Format-Table -inputobject @{'test'= 1, 2} | Out-String -Width 120
$result | Should -Match "test\s+{1, 2}"
}

It "Format-Table with new line should work" {
$info = @{}
$info.name = "1\n2"
$result = $info | Format-Table | Out-String
$result = $info | Format-Table | Out-String -Width 120
$result | Should -Match "name\s+1.+2"
}

Expand All @@ -102,7 +95,7 @@ Describe "Format-Table" -Tags "CI" {
$IPs.Add($IP2)
$info = @{}
$info.test = $IPs
$result = $info | Format-Table | Out-String
$result = $info | Format-Table | Out-String -Width 120
$result | Should -Match "test\s+{1.1.1.1, 4fde::2:22:f376:ff3b:ab3f}"
}

Expand All @@ -112,7 +105,7 @@ Describe "Format-Table" -Tags "CI" {
$IPs = New-Object System.Collections.ArrayList
$IPs.Add($IP1)
$IPs.Add($IP2)
$result = $IPs | Format-Table -Autosize | Out-String
$result = $IPs | Format-Table -Autosize | Out-String -Width 120
$result | Should -Match "name size booleanValue"
$result | Should -Match "---- ---- ------------"
$result | Should -Match "Bob\s+1234\s+True"
Expand All @@ -124,7 +117,7 @@ Describe "Format-Table" -Tags "CI" {
@{ testName = "null" ; testObject = $null }
) {
param ($testObject)
$result = $testObject | Format-Table -Property "foo","bar" | Out-String
$result = $testObject | Format-Table -Property "foo","bar" | Out-String -Width 120
$result | Should -BeNullOrEmpty
}

Expand All @@ -134,7 +127,7 @@ Describe "Format-Table" -Tags "CI" {
@{ testName = "array" ; testString = "line1","line2" }
) {
param ($testString)
$result = $testString | Format-Table -Property "foo","bar" -Force | Out-String
$result = $testString | Format-Table -Property "foo","bar" -Force | Out-String -Width 120
$result.Replace(" ","").Replace([Environment]::NewLine,"") | Should -BeExactly "foobar------"
}

Expand All @@ -146,7 +139,7 @@ Describe "Format-Table" -Tags "CI" {
$info.arrayList = "string1","string2"
$info.enumerable = [MyDayOfWeek]$eto
$info.enumerableTestObject = $eto
$result = $info|Format-Table|Out-String
$result = $info | Format-Table | Out-String -Width 120
$result | Should -Match "intArray\s+{1, 2, 3, 4}"
$result | Should -Match "arrayList\s+{string1, string2}"
$result | Should -Match "enumerable\s+Sun"
Expand All @@ -160,26 +153,26 @@ Describe "Format-Table" -Tags "CI" {
$objs.Add($obj1)
$objs.Add($obj2)
$mo = [PSCustomObject]@{name = "this is name";sub = $objs}
$result1 = $mo|Format-Table -Expand CoreOnly|Out-String
$result1 = $mo | Format-Table -Expand CoreOnly | Out-String -Width 120
$result1 | Should -Match "name\s+sub"
$result1 | Should -Match "this is name"

$result2 = $mo|Format-Table -Expand EnumOnly|Out-String
$result2 = $mo | Format-Table -Expand EnumOnly | Out-String -Width 120
$result2 | Should -Match "name\s+sub"
$result2 | Should -Match "this is name\s+{x 0 y 0, x 1 y 1}"

$result3 = $mo|Format-Table -Expand Both|Out-String
$result3 = $mo | Format-Table -Expand Both | Out-String -Width 120
$result3 | Should -Match "name\s+sub"
$result3 | Should -Match "this is name\s+{x 0 y 0, x 1 y 1}"
}

It "Format-Table should not add trailing whitespace to the header" {
$out = "hello" | Format-Table -Property foo -Force | Out-String
$out = "hello" | Format-Table -Property foo -Force | Out-String -Width 120
$out.Replace([System.Environment]::NewLine, "") | Should -BeExactly "foo---"
}

It "Format-Table should not add trailing whitespace to rows" {
$out = [pscustomobject]@{a=1;b=2} | Format-Table -HideTableHeaders | Out-String
$out = [pscustomobject]@{a=1;b=2} | Format-Table -HideTableHeaders | Out-String -Width 120
$out.Replace([System.Environment]::NewLine, "") | Should -BeExactly "1 2"
}

Expand Down Expand Up @@ -323,7 +316,7 @@ Left Center Right
param($ps1xmlPath,$view,$object)
Update-FormatData -AppendPath $ps1xmlPath
$object.PSObject.TypeNames.Insert(0,"Test.Format")
$object | Format-Table -View $view | Out-String
$object | Format-Table -View $view | Out-String -Width 120
} ).AddArgument($ps1xmlPath).AddArgument($view).AddArgument($object) | Out-Null
$output = $ps.Invoke()
$output.Replace("`n","").Replace("`r","") | Should -BeExactly $expected
Expand Down Expand Up @@ -455,7 +448,7 @@ er
Update-FormatData -AppendPath $ps1xmlPath
$a = [PSCustomObject]@{First=1;Second=2;Third=3}
$a.PSObject.TypeNames.Insert(0,"Test.Format")
$a | Format-Table -View $view | Out-String
$a | Format-Table -View $view | Out-String -Width 120
} ).AddArgument($ps1xmlPath).AddArgument($view) | Out-Null
$output = $ps.Invoke()
foreach ($e in $ps.Streams.Error)
Expand Down Expand Up @@ -660,7 +653,7 @@ er
param($ps1xmlPath, $view, $values, $wrap)
Update-FormatData -AppendPath $ps1xmlPath
$values.PSObject.TypeNames.Insert(0,"Test.Format")
$values | Format-Table -View $view -Wrap:$wrap | Out-String
$values | Format-Table -View $view -Wrap:$wrap | Out-String -Width 120
} ).AddArgument($ps1xmlPath).AddArgument($view).AddArgument($values).AddArgument($wrap) | Out-Null
$output = $ps.Invoke()
foreach ($e in $ps.Streams.Error)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Describe "Format-Wide DRT basic functionality" -Tags "CI" {
$al = (0..255)
$info = @{}
$info.array = $al
$result = $info | Format-Wide | Out-String
$result = $info | Format-Wide | Out-String -Width 120
$result | Should -Match "array"
}

Expand Down Expand Up @@ -83,7 +83,7 @@ Describe "Format-Wide DRT basic functionality" -Tags "CI" {
$info.arrayList = "string1", "string2"
$info.enumerable = [MyDayOfWeek]$eto
$info.enumerableTestObject = $eto
$result = $info|Format-Wide|Out-String
$result = $info | Format-Wide | Out-String -Width 120
$result | Should -Match "intArray"
$result | Should -Match "arrayList"
$result | Should -Match "enumerable"
Expand All @@ -99,7 +99,7 @@ Describe "Format-Wide DRT basic functionality" -Tags "CI" {
$testobject3 = [TestGroupingClass]::New('name3', 3)
$testobject1.GroupingKey = "bar"
$testobjects = @($testobject1, $testobject2, $testobject3)
$result = $testobjects|Format-Wide -GroupBy GroupingKey|Out-String
$result = $testobjects | Format-Wide -GroupBy GroupingKey | Out-String -Width 120
$result | Should -Match "GroupingKey: bar"
$result | Should -Match "name1"
$result | Should -Match " GroupingKey:"
Expand Down