Compare-Object Apply -IncludeEqual when -ExcludeDifferent is specified (#12317)

This commit is contained in:
David Seibel
2020-04-30 13:23:55 -07:00
committed by GitHub
parent a543b304bc
commit 6d1d62f2f8
2 changed files with 11 additions and 10 deletions
@@ -372,18 +372,13 @@ namespace Microsoft.PowerShell.Commands
#region Overrides
/// <summary>
/// If the parameter 'ExcludeDifferent' is present, then we need to turn on the
/// 'IncludeEqual' switch unless it's turned off by the user specifically.
/// If the parameter 'ExcludeDifferent' is present, then the 'IncludeEqual'
/// switch is turned on unless it's turned off by the user specifically.
/// </summary>
protected override void BeginProcessing()
{
if (ExcludeDifferent)
{
if (_isIncludeEqualSpecified == false)
{
return;
}
if (_isIncludeEqualSpecified && !_includeEqual)
{
return;
@@ -76,10 +76,10 @@ Describe "Compare-Object" -Tags "CI" {
{ Compare-Object -ReferenceObject $(Get-Content $file3) -DifferenceObject $anonexistentvariable } | Should -Throw
}
It "Should give a 0 array when using excludedifferent switch without also using the includeequal switch" {
$actualOutput = Compare-Object -ReferenceObject $(Get-Content $file3) -DifferenceObject $(Get-Content $file4) -ExcludeDifferent
It "Should only display equal lines when excludeDifferent switch is used without the includeequal switch" {
$actualOutput = Compare-Object -ReferenceObject $(Get-Content $file3) -DifferenceObject $(Get-Content $file4) -ExcludeDifferent
$actualOutput.Length | Should -Be 0
$actualOutput.Length | Should -Be 2
}
It "Should only display equal lines when excludeDifferent switch is used alongside the includeequal switch" {
@@ -88,6 +88,12 @@ Describe "Compare-Object" -Tags "CI" {
$actualOutput.Length | Should -Be 2
}
It "Should give a 0 array when using excludedifferent switch when also setting the includeequal switch to false" {
$actualOutput = Compare-Object -ReferenceObject $(Get-Content $file3) -DifferenceObject $(Get-Content $file4) -ExcludeDifferent -IncludeEqual:$false
$actualOutput.Length | Should -Be 0
}
It "Should be able to pass objects to pipeline using the passthru switch" {
{ Compare-Object -ReferenceObject $(Get-Content $file3) -DifferenceObject $(Get-Content $file4) -Passthru | Format-Wide } | Should -Not -Throw
}