2015-10-23 01:35:31 +02:00
|
|
|
Describe "Format-List" {
|
2015-11-30 23:35:23 +01:00
|
|
|
$nl = [Environment]::NewLine
|
2015-08-07 23:12:40 +02:00
|
|
|
BeforeEach {
|
2016-03-04 23:52:27 +01:00
|
|
|
$in = New-Object PSObject
|
|
|
|
Add-Member -InputObject $in -MemberType NoteProperty -Name testName -Value testValue
|
2015-08-07 23:12:40 +02:00
|
|
|
}
|
2015-08-07 01:40:10 +02:00
|
|
|
|
2015-08-07 23:12:40 +02:00
|
|
|
It "Should call format list without error" {
|
2016-03-04 23:52:27 +01:00
|
|
|
{ $in | Format-List } | Should Not Throw
|
|
|
|
{ $in | Format-List } | Should Not BeNullOrEmpty
|
2015-08-07 01:40:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
It "Should be able to call the alias" {
|
2016-03-04 23:52:27 +01:00
|
|
|
{ $in | fl } | Should Not Throw
|
|
|
|
{ $in | fl } | Should Not BeNullOrEmpty
|
2015-08-07 01:40:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
It "Should have the same output whether choosing alias or not" {
|
2016-03-04 23:52:27 +01:00
|
|
|
$expected = $in | Format-List | Out-String
|
|
|
|
$actual = $in | fl | Out-String
|
2015-08-07 19:12:37 +02:00
|
|
|
|
2016-03-04 23:52:27 +01:00
|
|
|
$actual | Should Be $expected
|
2015-08-07 01:40:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
It "Should produce the expected output" {
|
2016-03-04 23:52:27 +01: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-07 01:40:10 +02:00
|
|
|
|
2016-03-04 23:52:27 +01: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-05 01:07:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
It "Should be able to call a property of the piped input" {
|
2016-03-04 23:52:27 +01:00
|
|
|
# Tested on two input commands to verify functionality.
|
|
|
|
{ Get-Process | Format-List -Property Name } | Should Not Throw
|
|
|
|
{ Get-Process | Format-List -Property Name } | Should Not BeNullOrEmpty
|
2015-08-07 19:12:37 +02:00
|
|
|
|
2016-03-04 23:52:27 +01:00
|
|
|
{ Get-Date | Format-List -Property DisplayName } | Should Not Throw
|
|
|
|
{ Get-Date | Format-List -Property DisplayName } | Should Not BeNullOrEmpty
|
2015-08-05 01:07:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
It "Should be able to display a list of props when separated by a comma" {
|
2016-03-04 23:52:27 +01:00
|
|
|
{ Get-Process | Format-List -Property Name,BasePriority } | Should Not Throw
|
2015-08-07 01:40:10 +02:00
|
|
|
|
2016-03-04 23:52:27 +01:00
|
|
|
(Get-Process | Format-List -Property Name,BasePriority | Out-String) -Split "${nl}" |
|
|
|
|
Where-Object { $_.trim() -ne "" } |
|
|
|
|
ForEach-Object { $_ | Should Match "(Name)|(BasePriority)" }
|
2015-08-07 23:07:03 +02:00
|
|
|
}
|
2015-08-05 01:07:14 +02:00
|
|
|
|
2015-08-07 23:07:03 +02:00
|
|
|
It "Should show the requested prop in every element" {
|
2016-03-04 23:52:27 +01:00
|
|
|
# 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 "${nl}" |
|
|
|
|
Where-Object { $_.trim() -ne "" } |
|
|
|
|
ForEach-Object { $_ | Should Match "CPU :" }
|
2015-08-05 01:07:14 +02:00
|
|
|
}
|
2015-08-06 01:01:10 +02:00
|
|
|
|
2015-08-06 20:31:30 +02:00
|
|
|
It "Should not show anything other than the requested props" {
|
2016-03-04 23:52:27 +01:00
|
|
|
$output = Get-Process | Format-List -Property Name | Out-String
|
2015-08-07 01:40:10 +02:00
|
|
|
|
2016-03-04 23:52:27 +01:00
|
|
|
$output | Should Not Match "CPU :"
|
|
|
|
$output | Should Not Match "Id :"
|
|
|
|
$output | Should Not Match "Handle :"
|
2015-08-06 01:01:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
It "Should be able to take input without piping objects to it" {
|
2016-03-04 23:52:27 +01:00
|
|
|
$output = { Format-List -InputObject $in }
|
2015-08-06 01:01:10 +02:00
|
|
|
|
2016-03-04 23:52:27 +01:00
|
|
|
$output | Should Not Throw
|
|
|
|
$output | Should Not BeNullOrEmpty
|
2015-08-06 01:01:10 +02:00
|
|
|
|
|
|
|
}
|
2015-08-05 01:07:14 +02:00
|
|
|
}
|