mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Compare-Object Apply -IncludeEqual when -ExcludeDifferent is specified (#12317)
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user