Merge pull request #933 from PowerShell/FormatCustomListWidePesterTest

Add Format-Custom,Format-List,Format-Wide Pester Test
This commit is contained in:
Andy Schwartzmeyer committed 2016-05-06 10:00:12 -07:00
commit 649cfb4c10
3 files changed
+152 -10

No files matched your search

+19
View File
@@ -23,3 +23,22 @@ Describe "Format-Custom" {
}
}
Describe "Format-Custom DRT basic functionality" -Tags DRT{
It "Format-Custom with subobject should work"{
$expectResult1 = "this is the name"
$expectResult2 = "this is the name of the sub object"
$testObject = @{}
$testObject.name = $expectResult1
$testObject.subObjectValue = @{}
$testObject.subObjectValue.name = $expectResult2
$testObject.subObjectValue.array = (0..63)
$testObject.subObjectValue.stringarray = @("one","two")
$result = $testObject | Format-Custom | Out-String
$result | Should Match $expectResult1
$result | Should Match $expectResult2
$result | Should Match "one"
$result | Should Match "two"
}
}
+63 -4
View File
@@ -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 :"
@@ -66,3 +66,62 @@ Describe "Format-List" {
}
}
Describe "Format-List DRT basic functionality" -Tags DRT{
It "Format-List with array should work"{
$al = (0..255)
$info = @{}
$info.array = $al
$result = $info | Format-List | Out-String
$result | Should Match "Name : array\s+Value : {0, 1, 2, 3...}"
}
It "Format-List with No Objects for End-To-End should work"{
$p = @{}
$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 -Force -Property "foo","bar" | Out-String
$result.Trim() | Should BeNullOrEmpty
}
It "Format-List with single line string for End-To-End should work"{
$p = "single line string"
$result = $p | Format-List -Force -Property "foo","bar" | Out-String
$result.Trim() | Should BeNullOrEmpty
}
It "Format-List with multiple line string for End-To-End should work"{
$p = "Line1\nLine2"
$result = $p | Format-List -Force -Property "foo","bar" | Out-String
$result.Trim() | Should BeNullOrEmpty
}
It "Format-List with string sequence for End-To-End should work"{
$p = "Line1","Line2"
$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"{
Add-Type -TypeDefinition "public enum MyDayOfWeek{Sun,Mon,Tue,Wed,Thr,Fri,Sat}"
$eto = New-Object MyDayOfWeek
$info = @{}
$info.intArray = 1,2,3,4
$info.arrayList = "string1","string2"
$info.enumerable = [MyDayOfWeek]$eto
$info.enumerableTestObject = $eto
$result = $info|Format-List|Out-String
$result | Should Match "Name : enumerableTestObject"
$result | Should Match "Value : Sun"
$result | Should Match "Name : arrayList"
$result | Should Match "Value : {string1, string2}"
$result | Should Match "Name : enumerable"
$result | Should Match "Value : Sun"
$result | Should Match "Name : intArray"
$result | Should Match "Value : {1, 2, 3, 4}"
}
}
+70 -6
View File
@@ -8,26 +8,90 @@ 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
}
}
Describe "Format-Wide DRT basic functionality" -Tags DRT{
It "Format-Wide with array should work"{
$al = (0..255)
$info = @{}
$info.array = $al
$result = $info | Format-Wide | Out-String
$result | Should Match "array"
}
It "Format-Wide with No Objects for End-To-End should work"{
$p = @{}
$result = $p | Format-Wide | Out-String
$result | Should BeNullOrEmpty
}
It "Format-Wide with Null Objects for End-To-End should work"{
$p = $null
$result = $p | Format-Wide | Out-String
$result | Should BeNullOrEmpty
}
It "Format-Wide with single line string for End-To-End should work"{
$p = "single line string"
$result = $p | Format-Wide | Out-String
$result | Should Match $p
}
It "Format-Wide with multiple line string for End-To-End should work"{
$p = "Line1\nLine2"
$result = $p | Format-Wide | Out-String
$result | Should Match "Line1"
$result | Should Match "Line2"
}
It "Format-Wide with string sequence for End-To-End should work"{
$p = "Line1","Line2"
$result = $p |Format-Wide | Out-String
$result | Should Match "Line1"
$result | Should Match "Line2"
}
It "Format-Wide with complex object for End-To-End should work"{
Add-Type -TypeDefinition "public enum MyDayOfWeek{Sun,Mon,Tue,Wed,Thr,Fri,Sat}"
$eto = New-Object MyDayOfWeek
$info = @{}
$info.intArray = 1,2,3,4
$info.arrayList = "string1","string2"
$info.enumerable = [MyDayOfWeek]$eto
$info.enumerableTestObject = $eto
$result = $info|Format-Wide|Out-String
$result | Should Match "intArray"
$result | Should Match "arrayList"
$result | Should Match "enumerable"
$result | Should Match "enumerableTestObject"
}
}