From 3de6b7d4266349f5cdfc136c77eafc6bc23b2931 Mon Sep 17 00:00:00 2001 From: davidseibel <> Date: Wed, 15 Apr 2020 09:00:21 -0400 Subject: [PATCH 1/4] Replace test for using -ExcludeDifferent without -IncludeEqual --- .../Microsoft.PowerShell.Utility/Compare-Object.Tests.ps1 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Compare-Object.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Compare-Object.Tests.ps1 index 55819fba180..e37d0058f6f 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Compare-Object.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Compare-Object.Tests.ps1 @@ -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" { From ea8a7848844910f193c21a5522998321280c283a Mon Sep 17 00:00:00 2001 From: davidseibel <> Date: Wed, 15 Apr 2020 09:10:52 -0400 Subject: [PATCH 2/4] Create test for using -ExcludeDifferent switch with -IncludeEqual set to $false --- .../Microsoft.PowerShell.Utility/Compare-Object.Tests.ps1 | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Compare-Object.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Compare-Object.Tests.ps1 index e37d0058f6f..3f8a521cb15 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Compare-Object.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Compare-Object.Tests.ps1 @@ -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 } From 78445871e29ea9a2187b69948a1d25df9a1c27db Mon Sep 17 00:00:00 2001 From: davidseibel <> Date: Wed, 15 Apr 2020 09:12:19 -0400 Subject: [PATCH 3/4] Apply -IncludeEqual switch when -ExcludeDifferent is specified --- .../commands/utility/Compare-Object.cs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/Compare-Object.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/Compare-Object.cs index 5ee48da98de..4d896a46c89 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/Compare-Object.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/Compare-Object.cs @@ -379,11 +379,6 @@ protected override void BeginProcessing() { if (ExcludeDifferent) { - if (_isIncludeEqualSpecified == false) - { - return; - } - if (_isIncludeEqualSpecified && !_includeEqual) { return; From b0f98f1c80a18310f1dd7eda211ba5224c314132 Mon Sep 17 00:00:00 2001 From: davidseibel <> Date: Wed, 15 Apr 2020 09:50:41 -0400 Subject: [PATCH 4/4] Update comment to reflect new behavior --- .../commands/utility/Compare-Object.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/Compare-Object.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/Compare-Object.cs index 4d896a46c89..ae6e48180e5 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/Compare-Object.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/Compare-Object.cs @@ -372,8 +372,8 @@ private void Emit(OrderByPropertyEntry entry, string sideIndicator) #region Overrides /// - /// 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. /// protected override void BeginProcessing() {