2020-03-24 19:08:37 +01:00
|
|
|
# Copyright (c) Microsoft Corporation.
|
2019-10-24 21:45:26 +02:00
|
|
|
# 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' {
|
Update pester syntax to v4 (#11544)
* Capitalize 'Should' command and fix whitespace
```powershell
$_ -ireplace '\s?\|\s?should\b',' | Should'
```
* Capitalise and apply hyphen to 'Not' parameter
```powershell
$_ -ireplace '(\| Should) not\b','$1 -Not'
```
* Capitalise and apply hyphen to 'Be' parameter
```powershell
$_ -ireplace '(\| Should(?: -Not)?) -?be\b','$1 -Be'
```
* Capitalise and apply hyphen to 'BeExactly' parameter
$_ -ireplace '(\| Should(?: -Not)?) -?beexactly\b','$1 -BeExactly'
* Capitalise and apply hyphen to 'BeGreaterThan' parameter
```powershell
$_ -ireplace '(\| Should(?: -Not)?) -?begreaterthan\b','$1 -BeGreaterThan'
```
* Use 'BeTrue' parameter
```powershell
$_ -ireplace '(\| Should(?: -Not)?) -Be\s\$?true\b','$1 -BeTrue'
```
* Use 'BeFalse' parameter
```powershell
$_ -ireplace '(\| Should(?: -Not)?) -Be\s\$?false\b','$1 -BeFalse'
```
* Capitalise and apply hyphen to 'Match' parameter
```powershell
$_ -ireplace '(\| Should(?: -Not)?)\s-?match\b','$1 -Match'
```
* Capitalise and apply hyphen to 'Throw' parameter
```powershell
$_ -ireplace '(\| Should(?: -Not)?)\s-?throw\b','$1 -Throw'
```
* Capitalise and apply hyphen to 'BeNullOrEmpty' parameter
```powershell
$_ -ireplace '(\| Should(?: -Not)?)\s-?benullorempty\b','$1 -BeNullOrEmpty'
```
* Capitalise 'Because' parameter
```powershell
$_ -ireplace '\s-because\b',' -Because'
```
* Fix 'BeNullOrEmpty'
2020-01-11 16:41:59 +01:00
|
|
|
"select this string" | Select-String 'this' | Out-String | Should -BeLikeExactly "*`e*"
|
2019-10-24 21:45:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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*"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|