File size: 2,599 Bytes
8c763fb | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 | # Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
Describe '$env:__SuppressAnsiEscapeSequences tests' -Tag CI {
BeforeAll {
$originalDefaultParameterValues = $PSDefaultParameterValues.Clone()
if (-not $host.ui.SupportsVirtualTerminal) {
$PSDefaultParameterValues["it:skip"] = $true
}
$originalSuppressPref = $env:__SuppressAnsiEscapeSequences
$originalRendering = $PSStyle.OutputRendering
$PSStyle.OutputRendering = 'Ansi'
}
AfterAll {
$global:PSDefaultParameterValues = $originalDefaultParameterValues
$env:__SuppressAnsiEscapeSequences = $originalSuppressPref
$PSStyle.OutputRendering = $originalRendering
}
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*"
}
}
}
|