2015-08-04 16:07:14 -07:00
|
|
|
Describe "Test-Format-List" {
|
|
|
|
|
It "Should call format list without error" {
|
2015-08-06 16:40:10 -07:00
|
|
|
$input = New-Object PSObject
|
|
|
|
|
Add-Member -InputObject $input -MemberType NoteProperty -Name testName -Value testValue
|
2015-08-04 16:07:14 -07:00
|
|
|
|
2015-08-06 16:40:10 -07:00
|
|
|
{ $input | Format-List } | Should Not Throw
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
It "Should be able to call the alias" {
|
|
|
|
|
$input = New-Object PSObject
|
|
|
|
|
Add-Member -InputObject $input -MemberType NoteProperty -Name testName -Value testValue
|
|
|
|
|
|
|
|
|
|
{ $input | fl } | Should Not Throw
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
It "Should have the same output whether choosing alias or not" {
|
|
|
|
|
$input = New-Object PSObject
|
|
|
|
|
Add-Member -InputObject $input -MemberType NoteProperty -Name testName -Value testValue
|
|
|
|
|
|
2015-08-07 10:12:37 -07:00
|
|
|
$expected = $input | Format-List | Out-String
|
|
|
|
|
$actual = $input | fl | Out-String
|
|
|
|
|
|
|
|
|
|
$actual | Should Be $expected
|
|
|
|
|
|
2015-08-06 16:40:10 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
It "Should produce the expected output" {
|
|
|
|
|
$expected = "`n`ntestName : testValue`n`n`n`n"
|
|
|
|
|
$input = New-Object PSObject
|
|
|
|
|
Add-Member -InputObject $input -MemberType NoteProperty -Name testName -Value testValue
|
|
|
|
|
|
2015-08-07 10:12:37 -07:00
|
|
|
$input | Format-List | Should Not BeNullOrEmpty
|
|
|
|
|
$input | Format-List | Out-String | Should Not BeNullOrEmpty
|
|
|
|
|
$input | Format-List | Out-String | Should Be $expected
|
2015-08-04 16:07:14 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
It "Should be able to call a property of the piped input" {
|
2015-08-06 16:40:10 -07:00
|
|
|
# Tested on two input commands to verify functionality.
|
2015-08-04 16:07:14 -07:00
|
|
|
|
2015-08-07 10:12:37 -07:00
|
|
|
{ Get-Process | Format-List -Property Name } | Should Not Throw
|
|
|
|
|
{ Get-Process | Format-List -Property Name } | Should Not BeNullOrEmpty
|
|
|
|
|
|
|
|
|
|
{ Get-Date | Format-List -Property DisplayName } | Should Not Throw
|
|
|
|
|
{ Get-Date | Format-List -Property DisplayName } | Should Not BeNullOrEmpty
|
2015-08-04 16:07:14 -07:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
It "Should be able to display a list of props when separated by a comma" {
|
2015-08-06 16:40:10 -07:00
|
|
|
{ Get-Process | Format-List -Property Name,BasePriority } | Should Not Throw
|
2015-08-04 16:07:14 -07:00
|
|
|
|
2015-08-07 10:12:37 -07:00
|
|
|
$output = ( Get-Process | Format-List -Property Name,BasePriority | Out-String)
|
2015-08-04 16:07:14 -07:00
|
|
|
|
2015-08-07 10:12:37 -07:00
|
|
|
$output.Contains("Name") | Should Be $true
|
|
|
|
|
$output.Contains("BasePriority") | Should Be $true
|
2015-08-04 16:07:14 -07:00
|
|
|
}
|
2015-08-05 16:01:10 -07:00
|
|
|
|
2015-08-06 11:31:30 -07:00
|
|
|
It "Should not show anything other than the requested props" {
|
2015-08-06 16:40:10 -07:00
|
|
|
<# the structure of the output of format-list, although iterable, is not a proper collection of
|
|
|
|
|
objects we can test
|
2015-08-05 16:01:10 -07:00
|
|
|
|
2015-08-06 16:40:10 -07:00
|
|
|
gps | fl | ForEach-Object{$_.ToString()} confirms that each item is a format object.
|
2015-08-06 13:11:05 -07:00
|
|
|
|
2015-08-06 16:40:10 -07:00
|
|
|
(Get-Process | Format-List | Out-String).split("\n") | ForEach-Object { $_} will list objects,
|
|
|
|
|
but not allow interaction with them.
|
2015-08-06 13:11:05 -07:00
|
|
|
#>
|
2015-08-05 16:01:10 -07:00
|
|
|
|
2015-08-07 10:12:37 -07:00
|
|
|
( Get-Process | Format-List | Out-String).Contains("CPU") | Should Be $true
|
2015-08-06 16:40:10 -07:00
|
|
|
|
|
|
|
|
|
2015-08-07 10:12:37 -07:00
|
|
|
$output = ( Get-Process | Format-List -Property Name | Out-String)
|
2015-08-06 16:40:10 -07:00
|
|
|
|
2015-08-07 11:31:50 -07:00
|
|
|
$output | Should Not Match "CPU"
|
|
|
|
|
$output | Should Not Match "Id"
|
|
|
|
|
$output | Should Not Match "Handle"
|
|
|
|
|
|
|
|
|
|
# Testing each element of format-list, using a for-each loop since the Format-List is so opaque
|
|
|
|
|
(Get-Process | Format-List -Property CPU | Out-String) -Split "`n" |
|
|
|
|
|
Where-Object {
|
|
|
|
|
$_.trim() -ne ""
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
ForEach-Object{
|
|
|
|
|
$_ | Should Match "CPU :"
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-05 16:01:10 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
It "Should be able to take input without piping objects to it" {
|
2015-08-06 16:40:10 -07:00
|
|
|
$input = New-Object PSObject
|
|
|
|
|
Add-Member -InputObject $input -MemberType NoteProperty -Name testName -Value testValue
|
2015-08-05 16:01:10 -07:00
|
|
|
|
2015-08-07 10:12:37 -07:00
|
|
|
$output = { Format-List -InputObject $input }
|
|
|
|
|
|
|
|
|
|
$output | Should Not Throw
|
|
|
|
|
$output | Should Not BeNullOrEmpty
|
2015-08-05 16:01:10 -07:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-04 16:07:14 -07:00
|
|
|
}
|