From 0097802cee5f8b20e371e0057c1f264c46672b74 Mon Sep 17 00:00:00 2001 From: Aditya Patwardhan Date: Wed, 8 Jan 2020 13:33:28 -0800 Subject: [PATCH] Normalize line endings before comparing string in tests (#11499) --- .../Debugging/DebuggerCommand.Tests.ps1 | 20 ++++++++++++++++--- .../Format-List.Tests.ps1 | 5 ++++- .../Format-Table.Tests.ps1 | 3 ++- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/test/powershell/Language/Scripting/Debugging/DebuggerCommand.Tests.ps1 b/test/powershell/Language/Scripting/Debugging/DebuggerCommand.Tests.ps1 index 399c4927e8..852e9efbac 100644 --- a/test/powershell/Language/Scripting/Debugging/DebuggerCommand.Tests.ps1 +++ b/test/powershell/Language/Scripting/Debugging/DebuggerCommand.Tests.ps1 @@ -5,6 +5,15 @@ Describe 'Basic debugger command tests' -tag 'CI' { BeforeAll { Register-DebuggerHandler + + function NormalizeLineEnd + { + param ( + [string] $string + ) + + $string -replace "`r`n", "`n" + } } AfterAll { @@ -76,6 +85,7 @@ Describe 'Basic debugger command tests' -tag 'CI' { 7: } 8: '@ + $testScriptList = NormalizeLineEnd -string $testScriptList $results = @(Test-Debugger -ScriptBlock $testScript -CommandQueue 'l','list') $result = @{ @@ -99,7 +109,7 @@ Describe 'Basic debugger command tests' -tag 'CI' { } It 'Should show the entire script listing with the current position on line 5' { - $result['l'] | Should -BeExactly $testScriptList + (NormalizeLineEnd -string $result['l']) | Should -BeExactly $testScriptList } } @@ -122,6 +132,8 @@ Describe 'Basic debugger command tests' -tag 'CI' { 8: '@ + $testScriptList = NormalizeLineEnd -string $testScriptList + $results = @(Test-Debugger -ScriptBlock $testScript -CommandQueue 'l 4','list 4') $result = @{ 'l 4' = if ($results.Count -gt 0) {$results[0].Output -replace '\s+$' -join [Environment]::NewLine -replace "^[`r`n]+|[`r`n]+$"} @@ -144,7 +156,7 @@ Describe 'Basic debugger command tests' -tag 'CI' { } It 'Should show a partial script listing starting on line 4 with the current position on line 5' { - $result['l 4'] | Should -BeExactly $testScriptList + (NormalizeLineEnd -string $result['l 4']) | Should -BeExactly $testScriptList } } @@ -164,6 +176,8 @@ Describe 'Basic debugger command tests' -tag 'CI' { 4:* Get-Process -Id $PID > $null '@ + $testScriptList = NormalizeLineEnd -string $testScriptList + $results = @(Test-Debugger -ScriptBlock $testScript -CommandQueue 'l 3 2','list 3 2') $result = @{ 'l 3 2' = if ($results.Count -gt 0) {$results[0].Output -replace '\s+$' -join [Environment]::NewLine -replace "^[`r`n]+|[`r`n]+$"} @@ -186,7 +200,7 @@ Describe 'Basic debugger command tests' -tag 'CI' { } It 'Should show a partial script listing showing 3 lines starting on line 4 with the current position on line 5' { - $result['l 3 2'] | Should -BeExactly $testScriptList + (NormalizeLineEnd -string $result['l 3 2']) | Should -BeExactly $testScriptList } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Format-List.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Format-List.Tests.ps1 index 4ebba15a18..dff2eeb963 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Format-List.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Format-List.Tests.ps1 @@ -176,7 +176,10 @@ dbda : KM "@ + $expected = $expected -replace "`r`n", "`n" - $obj | Format-List | Out-String | Should -BeExactly $expected + $actual = $obj | Format-List | Out-String + $actual = $actual -replace "`r`n", "`n" + $actual | Should -BeExactly $expected } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Format-Table.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Format-Table.Tests.ps1 index f2132aa280..809182caa8 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Format-Table.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Format-Table.Tests.ps1 @@ -829,6 +829,7 @@ A Name B "@ - $obj | Format-Table | Out-String | Should -BeExactly $expected + $actual = $obj | Format-Table | Out-String + ($actual.Replace("`r`n", "`n")) | Should -BeExactly ($expected.Replace("`r`n", "`n")) } }