From b1328d144b90652d7f84453fd7f15e9cdb972be6 Mon Sep 17 00:00:00 2001 From: JumpingYang001 Date: Mon, 2 May 2016 20:12:35 -0700 Subject: [PATCH] Update Format-Custom,Format-List,Format-Wide Pester Test --- test/powershell/Format-List.Tests.ps1 | 37 ++++++++++++--------------- test/powershell/Format-Wide.Tests.ps1 | 19 +++++++++----- 2 files changed, 30 insertions(+), 26 deletions(-) diff --git a/test/powershell/Format-List.Tests.ps1 b/test/powershell/Format-List.Tests.ps1 index 060fea779..782456551 100644 --- a/test/powershell/Format-List.Tests.ps1 +++ b/test/powershell/Format-List.Tests.ps1 @@ -32,27 +32,27 @@ Describe "Format-List" { It "Should be able to call a property of the piped input" { # Tested on two input commands to verify functionality. - { Get-Command | Format-List -Property Name } | Should Not BeNullOrEmpty + { Get-Command | Select-Object -First 5 | Format-List -Property Name } | Should Not BeNullOrEmpty { Get-Date | Format-List -Property DisplayName } | Should Not BeNullOrEmpty } It "Should be able to display a list of props when separated by a comma" { - (Get-Command | Format-List -Property Name,Source | Out-String) -Split "${nl}" | + (Get-Command | Select-Object -First 5 | Format-List -Property Name,Source | Out-String) -Split "${nl}" | Where-Object { $_.trim() -ne "" } | ForEach-Object { $_ | Should Match "(Name)|(Source)" } } It "Should show the requested prop in every element" { # Testing each element of format-list, using a for-each loop since the Format-List is so opaque - (Get-Command | Format-List -Property Source | Out-String) -Split "${nl}" | + (Get-Command | Select-Object -First 5 | Format-List -Property Source | Out-String) -Split "${nl}" | Where-Object { $_.trim() -ne "" } | ForEach-Object { $_ | Should Match "Source :" } } It "Should not show anything other than the requested props" { - $output = Get-Command | Format-List -Property Name | Out-String + $output = Get-Command | Select-Object -First 5 | Format-List -Property Name | Out-String $output | Should Not Match "CommandType :" $output | Should Not Match "Source :" @@ -78,35 +78,32 @@ Describe "Format-List DRT basic functionality" -Tags DRT{ It "Format-List with No Objects for End-To-End should work"{ $p = @{} - $result = $p | Format-List -Property "foo","bar" | Out-String - $result | Should BeNullOrEmpty + $result = $p | Format-List -Force -Property "foo","bar" | Out-String + $result.Trim() | Should BeNullOrEmpty } It "Format-List with Null Objects for End-To-End should work"{ $p = $null - $result = $p | Format-List -Property "foo","bar" | Out-String - $result | Should BeNullOrEmpty + $result = $p | Format-List -Force -Property "foo","bar" | Out-String + $result.Trim() | Should BeNullOrEmpty } - #pending on issue#900 - It "Format-List with single line string for End-To-End should work" -pending{ + It "Format-List with single line string for End-To-End should work"{ $p = "single line string" - $result = $p | Format-List -Property "foo","bar" | Out-String - $result | Should BeNullOrEmpty + $result = $p | Format-List -Force -Property "foo","bar" | Out-String + $result.Trim() | Should BeNullOrEmpty } - #pending on issue#900 - It "Format-List with multiple line string for End-To-End should work" -pending{ + It "Format-List with multiple line string for End-To-End should work"{ $p = "Line1\nLine2" - $result = $p | Format-List -Property "foo","bar" | Out-String - $result | Should BeNullOrEmpty + $result = $p | Format-List -Force -Property "foo","bar" | Out-String + $result.Trim() | Should BeNullOrEmpty } - #pending on issue#900 - It "Format-List with string sequence for End-To-End should work" -pending{ + It "Format-List with string sequence for End-To-End should work"{ $p = "Line1","Line2" - $result = $p | Format-List -Property "foo","bar" | Out-String - $result | Should BeNullOrEmpty + $result = $p | Format-List -Force -Property "foo","bar" | Out-String + $result.Trim() | Should BeNullOrEmpty } It "Format-List with complex object for End-To-End should work"{ diff --git a/test/powershell/Format-Wide.Tests.ps1 b/test/powershell/Format-Wide.Tests.ps1 index 56cc40760..c4e9a5862 100644 --- a/test/powershell/Format-Wide.Tests.ps1 +++ b/test/powershell/Format-Wide.Tests.ps1 @@ -8,27 +8,34 @@ Describe "Format-Wide" { } It "Should be able to specify the columns in output using the column switch" { - { ls | Format-Wide -Column 3 } | Should Not Throw + { Get-ChildItem | Format-Wide -Column 3 } | Should Not Throw } It "Should be able to use the autosize switch" { - { ls | Format-Wide -Autosize } | Should Not Throw + { Get-ChildItem | Format-Wide -Autosize } | Should Not Throw } It "Should be able to take inputobject instead of pipe" { - { Format-Wide -InputObject $(ls) } | Should Not Throw + { Format-Wide -InputObject $(Get-ChildItem) } | Should Not Throw } It "Should be able to use the property switch" { - { Format-Wide -InputObject $(ls) -Property Mode } | Should Not Throw + { Format-Wide -InputObject $(Get-ChildItem) -Property Mode } | Should Not Throw } It "Should throw an error when property switch and view switch are used together" { - { Format-Wide -InputObject $(ls) -Property CreationTime -View aoeu } | Should Throw "Found invalid data" + try + { + Format-Wide -InputObject $(Get-ChildItem) -Property CreationTime -View aoeu + } + catch + { + $_.FullyQualifiedErrorId | Should be "FormatCannotSpecifyViewAndProperty,Microsoft.PowerShell.Commands.FormatWideCommand" + } } It "Should throw and suggest proper input when view is used with invalid input without the property switch" { - { Format-Wide -InputObject $(gps) -View aoeu } | Should Throw + { Format-Wide -InputObject $(Get-Process) -View aoeu } | Should Throw } }