Move Set-StrictMode to outer scriptblock for ErrorView (#11381)

This commit is contained in:
Steve Lee
2019-12-17 23:43:47 +05:00
committed by Ilya
parent 04cf068878
commit edd3e7680c
2 changed files with 20 additions and 1 deletions
@@ -991,9 +991,9 @@ namespace System.Management.Automation.Runspaces
}
")
.AddScriptBlockExpressionBinding(@"
Set-StrictMode -Off
function Get-ConciseViewPositionMessage {
Set-StrictMode -Off
$resetColor = ''
if ($Host.UI.SupportsVirtualTerminal -and !(Test-Path env:__SuppressAnsiEscapeSequences)) {
@@ -63,4 +63,23 @@ Describe 'Tests for $ErrorView' -Tag CI {
$e | Out-String | Should -Not -BeLike '*pester*'
}
}
Context 'NormalView tests' {
It 'Error shows up when using strict mode' {
try {
$ErrorView = 'NormalView'
Set-StrictMode -Version 2
throw 'Oops!'
}
catch {
$e = $_ | Out-String
}
finally {
Set-StrictMode -Off
}
$e | Should -BeLike '*Oops!*'
}
}
}