2015-10-22 23:35:31 +00:00
|
|
|
Describe "Format-List" {
|
2015-11-30 22:35:23 +00:00
|
|
|
$nl = [Environment]::NewLine
|
2015-08-07 21:12:40 +00:00
|
|
|
BeforeEach {
|
2016-04-25 21:41:17 +00:00
|
|
|
$in = New-Object PSObject
|
|
|
|
Add-Member -InputObject $in -MemberType NoteProperty -Name testName -Value testValue
|
2015-08-07 21:12:40 +00:00
|
|
|
}
|
2015-08-06 23:40:10 +00:00
|
|
|
|
2015-08-07 21:12:40 +00:00
|
|
|
It "Should call format list without error" {
|
2016-04-25 21:41:17 +00:00
|
|
|
{ $in | Format-List } | Should Not BeNullOrEmpty
|
2015-08-06 23:40:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
It "Should be able to call the alias" {
|
2016-04-25 21:41:17 +00:00
|
|
|
{ $in | fl } | Should Not BeNullOrEmpty
|
2015-08-06 23:40:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
It "Should have the same output whether choosing alias or not" {
|
2016-04-25 21:41:17 +00:00
|
|
|
$expected = $in | Format-List | Out-String
|
|
|
|
$actual = $in | fl | Out-String
|
2015-08-07 17:12:37 +00:00
|
|
|
|
2016-04-25 21:41:17 +00:00
|
|
|
$actual | Should Be $expected
|
2015-08-06 23:40:10 +00:00
|
|
|
}
|
|
|
|
|
2016-05-14 01:23:28 +00:00
|
|
|
It "Should produce the expected output" -Pending:($env:TRAVIS_OS_NAME -eq "osx") {
|
2016-04-25 21:41:17 +00:00
|
|
|
$expected = "${nl}${nl}testName : testValue${nl}${nl}${nl}${nl}"
|
|
|
|
$in = New-Object PSObject
|
|
|
|
Add-Member -InputObject $in -MemberType NoteProperty -Name testName -Value testValue
|
2015-08-06 23:40:10 +00:00
|
|
|
|
2016-04-25 21:41:17 +00:00
|
|
|
$in | Format-List | Should Not BeNullOrEmpty
|
|
|
|
$in | Format-List | Out-String | Should Not BeNullOrEmpty
|
|
|
|
$in | Format-List | Out-String | Should Be $expected
|
2015-08-04 23:07:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
It "Should be able to call a property of the piped input" {
|
2016-04-25 21:41:17 +00:00
|
|
|
# Tested on two input commands to verify functionality.
|
2016-05-03 03:12:35 +00:00
|
|
|
{ Get-Command | Select-Object -First 5 | Format-List -Property Name } | Should Not BeNullOrEmpty
|
2015-08-07 17:12:37 +00:00
|
|
|
|
2016-04-25 21:41:17 +00:00
|
|
|
{ Get-Date | Format-List -Property DisplayName } | Should Not BeNullOrEmpty
|
2015-08-04 23:07:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
It "Should be able to display a list of props when separated by a comma" {
|
2015-08-06 23:40:10 +00:00
|
|
|
|
2016-05-03 03:12:35 +00:00
|
|
|
(Get-Command | Select-Object -First 5 | Format-List -Property Name,Source | Out-String) -Split "${nl}" |
|
2016-04-25 21:41:17 +00:00
|
|
|
Where-Object { $_.trim() -ne "" } |
|
|
|
|
ForEach-Object { $_ | Should Match "(Name)|(Source)" }
|
2015-08-07 21:07:03 +00:00
|
|
|
}
|
2015-08-04 23:07:14 +00:00
|
|
|
|
2015-08-07 21:07:03 +00:00
|
|
|
It "Should show the requested prop in every element" {
|
2016-04-25 21:41:17 +00:00
|
|
|
# Testing each element of format-list, using a for-each loop since the Format-List is so opaque
|
2016-05-03 03:12:35 +00:00
|
|
|
(Get-Command | Select-Object -First 5 | Format-List -Property Source | Out-String) -Split "${nl}" |
|
2016-04-25 21:41:17 +00:00
|
|
|
Where-Object { $_.trim() -ne "" } |
|
|
|
|
ForEach-Object { $_ | Should Match "Source :" }
|
2015-08-04 23:07:14 +00:00
|
|
|
}
|
2015-08-05 23:01:10 +00:00
|
|
|
|
2015-08-06 18:31:30 +00:00
|
|
|
It "Should not show anything other than the requested props" {
|
2016-05-03 03:12:35 +00:00
|
|
|
$output = Get-Command | Select-Object -First 5 | Format-List -Property Name | Out-String
|
2015-08-06 23:40:10 +00:00
|
|
|
|
2016-04-25 21:41:17 +00:00
|
|
|
$output | Should Not Match "CommandType :"
|
|
|
|
$output | Should Not Match "Source :"
|
|
|
|
$output | Should Not Match "Module :"
|
2015-08-05 23:01:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
It "Should be able to take input without piping objects to it" {
|
2016-04-25 21:41:17 +00:00
|
|
|
$output = { Format-List -InputObject $in }
|
2015-08-05 23:01:10 +00:00
|
|
|
|
2016-04-25 21:41:17 +00:00
|
|
|
$output | Should Not BeNullOrEmpty
|
2015-08-05 23:01:10 +00:00
|
|
|
|
|
|
|
}
|
2015-08-04 23:07:14 +00:00
|
|
|
}
|
2016-04-29 10:10:09 +00:00
|
|
|
|
|
|
|
Describe "Format-List DRT basic functionality" -Tags DRT{
|
2016-05-14 01:23:28 +00:00
|
|
|
It "Format-List with array should work"-Pending:($env:TRAVIS_OS_NAME -eq "osx") {
|
|
|
|
$al = (0..255)
|
|
|
|
$info = @{}
|
|
|
|
$info.array = $al
|
|
|
|
$result = $info | Format-List | Out-String
|
|
|
|
$result | Should Match "Name : array\s+Value : {0, 1, 2, 3...}"
|
|
|
|
}
|
|
|
|
|
2016-04-29 10:10:09 +00:00
|
|
|
It "Format-List with No Objects for End-To-End should work"{
|
|
|
|
$p = @{}
|
2016-05-03 03:12:35 +00:00
|
|
|
$result = $p | Format-List -Force -Property "foo","bar" | Out-String
|
|
|
|
$result.Trim() | Should BeNullOrEmpty
|
2016-04-29 10:10:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
It "Format-List with Null Objects for End-To-End should work"{
|
|
|
|
$p = $null
|
2016-05-03 03:12:35 +00:00
|
|
|
$result = $p | Format-List -Force -Property "foo","bar" | Out-String
|
|
|
|
$result.Trim() | Should BeNullOrEmpty
|
2016-04-29 10:10:09 +00:00
|
|
|
}
|
|
|
|
|
2016-05-03 03:12:35 +00:00
|
|
|
It "Format-List with single line string for End-To-End should work"{
|
2016-04-29 10:10:09 +00:00
|
|
|
$p = "single line string"
|
2016-05-03 03:12:35 +00:00
|
|
|
$result = $p | Format-List -Force -Property "foo","bar" | Out-String
|
|
|
|
$result.Trim() | Should BeNullOrEmpty
|
2016-04-29 10:10:09 +00:00
|
|
|
}
|
|
|
|
|
2016-05-03 03:12:35 +00:00
|
|
|
It "Format-List with multiple line string for End-To-End should work"{
|
2016-04-29 10:10:09 +00:00
|
|
|
$p = "Line1\nLine2"
|
2016-05-03 03:12:35 +00:00
|
|
|
$result = $p | Format-List -Force -Property "foo","bar" | Out-String
|
|
|
|
$result.Trim() | Should BeNullOrEmpty
|
2016-04-29 10:10:09 +00:00
|
|
|
}
|
|
|
|
|
2016-05-03 03:12:35 +00:00
|
|
|
It "Format-List with string sequence for End-To-End should work"{
|
2016-04-29 10:10:09 +00:00
|
|
|
$p = "Line1","Line2"
|
2016-05-03 03:12:35 +00:00
|
|
|
$result = $p | Format-List -Force -Property "foo","bar" | Out-String
|
|
|
|
$result.Trim() | Should BeNullOrEmpty
|
2016-04-29 10:10:09 +00:00
|
|
|
}
|
|
|
|
|
2016-05-14 01:23:28 +00:00
|
|
|
It "Format-List with complex object for End-To-End should work" -Pending:($env:TRAVIS_OS_NAME -eq "osx") {
|
|
|
|
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}"
|
|
|
|
}
|
2016-04-29 10:10:09 +00:00
|
|
|
}
|