Add $env:__SuppressAnsiEscapeSequences to control whether to… (#10814)

This commit is contained in:
Steve Lee
2019-10-24 12:45:26 -07:00
committed by Travis Plunk
parent 09b5ed3fd0
commit 4ff9924cbf
9 changed files with 220 additions and 72 deletions
@@ -0,0 +1,89 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
Describe '$env:__SuppressAnsiEscapeSequences tests' -Tag CI {
BeforeAll {
$originalSuppressPref = $env:__SuppressAnsiEscapeSequences
}
AfterAll {
$env:__SuppressAnsiEscapeSequences = $originalSuppressPref
}
Context 'Allow Escape Sequences' {
BeforeAll {
Remove-Item env:__SuppressAnsiEscapeSequences -ErrorAction Ignore
}
It 'Select-String emits VT' {
"select this string" | Select-String 'this' | Out-String |Should -BeLikeExactly "*`e*"
}
It 'ConciseView emits VT' {
$oldErrorView = $ErrorView
try {
$ErrorView = 'ConciseView'
Invoke-Expression '1/d'
}
catch {
$e = $_
}
finally {
$ErrorView = $oldErrorView
}
$e | Out-String | Should -BeLikeExactly "*`e*"
}
It 'Get-Error emits VT' {
try {
1/0
}
catch {
# ignore
}
Get-Error | Out-String | Should -BeLikeExactly "*`e*"
}
}
Context 'No Escape Sequences' {
BeforeAll {
$env:__SuppressAnsiEscapeSequences = 1
}
It 'Select-String does not emit VT' {
"select this string" | Select-String 'this' | Out-String | Should -Not -BeLikeExactly "*`e*"
}
It 'ConciseView does not emit VT' {
$oldErrorView = $ErrorView
try {
$ErrorView = 'ConciseView'
Invoke-Expression '1/d'
}
catch {
$e = $_
}
finally {
$ErrorView = $oldErrorView
}
$e | Out-String | Should -Not -BeLikeExactly "*`e*"
}
It 'Get-Error does not emit VT' {
try {
1/0
}
catch {
# ignore
}
Get-Error | Out-String | Should -Not -BeLikeExactly "*`e*"
}
}
}