From 6367d998e45a53e4ddc91f7bec62a35688b5be72 Mon Sep 17 00:00:00 2001 From: Steve Lee Date: Sun, 24 May 2020 22:15:28 -0700 Subject: [PATCH 1/6] Remove use of `Test-Path` in ConciseView --- .../DefaultFormatters/PowerShellCore_format_ps1xml.cs | 8 ++++---- test/powershell/engine/Formatting/ErrorView.Tests.ps1 | 5 +++++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/System.Management.Automation/FormatAndOutput/DefaultFormatters/PowerShellCore_format_ps1xml.cs b/src/System.Management.Automation/FormatAndOutput/DefaultFormatters/PowerShellCore_format_ps1xml.cs index f22ccc9725a..7963ef4c1ad 100644 --- a/src/System.Management.Automation/FormatAndOutput/DefaultFormatters/PowerShellCore_format_ps1xml.cs +++ b/src/System.Management.Automation/FormatAndOutput/DefaultFormatters/PowerShellCore_format_ps1xml.cs @@ -766,14 +766,14 @@ private static IEnumerable ViewsOf_System_Management_Autom $maxDepth = 10 $ellipsis = ""`u{2026}"" $resetColor = '' - if ($Host.UI.SupportsVirtualTerminal -and !(Test-Path env:__SuppressAnsiEscapeSequences)) { + if ($Host.UI.SupportsVirtualTerminal -and ($null -eq $env:__SuppressAnsiEscapeSequences)) { $resetColor = [System.Management.Automation.VTUtility]::GetEscapeSequence( [System.Management.Automation.VTUtility+VT]::Reset ) } function Get-VT100Color([ConsoleColor] $color) { - if (!$Host.UI.SupportsVirtualTerminal -or (Test-Path env:__SuppressAnsiEscapeSequences)) { + if (!$Host.UI.SupportsVirtualTerminal -or ($null -ne $env:__SuppressAnsiEscapeSequences)) { return '' } @@ -1013,14 +1013,14 @@ private static IEnumerable ViewsOf_System_Management_Autom function Get-ConciseViewPositionMessage { $resetColor = '' - if ($Host.UI.SupportsVirtualTerminal -and !(Test-Path env:__SuppressAnsiEscapeSequences)) { + if ($Host.UI.SupportsVirtualTerminal -and ($null -eq $env:__SuppressAnsiEscapeSequences)) { $resetColor = [System.Management.Automation.VTUtility]::GetEscapeSequence( [System.Management.Automation.VTUtility+VT]::Reset ) } function Get-VT100Color([ConsoleColor] $color) { - if (!$Host.UI.SupportsVirtualTerminal -or (Test-Path env:__SuppressAnsiEscapeSequences)) { + if (!$Host.UI.SupportsVirtualTerminal -or ($null -ne $env:__SuppressAnsiEscapeSequences)) { return '' } diff --git a/test/powershell/engine/Formatting/ErrorView.Tests.ps1 b/test/powershell/engine/Formatting/ErrorView.Tests.ps1 index b230ce59f68..c23883410b6 100644 --- a/test/powershell/engine/Formatting/ErrorView.Tests.ps1 +++ b/test/powershell/engine/Formatting/ErrorView.Tests.ps1 @@ -105,6 +105,11 @@ Describe 'Tests for $ErrorView' -Tag CI { $e = & "$PSHOME/pwsh" -noprofile -command "foreach abc" | Out-String $e | Should -Not -BeLike "*At line*" } + + It "Error shows if `$PSModuleAutoLoadingPreference is set to 'none'" { + $e = & "$PSHOME/pwsh" -noprofile -command '$PSModuleAutoLoadingPreference = ""none""; cmdletThatDoesntExist' | Out-String + $e | Should -BeLike "*cmdletThatDoesntExist*" + } } Context 'NormalView tests' { From 53ce2d98165aad8d1a3491cfdc54cc571655857c Mon Sep 17 00:00:00 2001 From: Steve Lee Date: Fri, 5 Jun 2020 12:37:32 -0700 Subject: [PATCH 2/6] address Vexx32's feedback using [string]::isnullormepty --- .../DefaultFormatters/PowerShellCore_format_ps1xml.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/System.Management.Automation/FormatAndOutput/DefaultFormatters/PowerShellCore_format_ps1xml.cs b/src/System.Management.Automation/FormatAndOutput/DefaultFormatters/PowerShellCore_format_ps1xml.cs index 7963ef4c1ad..dfd610e4750 100644 --- a/src/System.Management.Automation/FormatAndOutput/DefaultFormatters/PowerShellCore_format_ps1xml.cs +++ b/src/System.Management.Automation/FormatAndOutput/DefaultFormatters/PowerShellCore_format_ps1xml.cs @@ -766,14 +766,14 @@ private static IEnumerable ViewsOf_System_Management_Autom $maxDepth = 10 $ellipsis = ""`u{2026}"" $resetColor = '' - if ($Host.UI.SupportsVirtualTerminal -and ($null -eq $env:__SuppressAnsiEscapeSequences)) { + if ($Host.UI.SupportsVirtualTerminal -and ([string]::IsNullOrEmpty($env:__SuppressAnsiEscapeSequences))) { $resetColor = [System.Management.Automation.VTUtility]::GetEscapeSequence( [System.Management.Automation.VTUtility+VT]::Reset ) } function Get-VT100Color([ConsoleColor] $color) { - if (!$Host.UI.SupportsVirtualTerminal -or ($null -ne $env:__SuppressAnsiEscapeSequences)) { + if (!$Host.UI.SupportsVirtualTerminal -or !([string]::IsNullOrEmpty($env:__SuppressAnsiEscapeSequences))) { return '' } @@ -1013,14 +1013,14 @@ private static IEnumerable ViewsOf_System_Management_Autom function Get-ConciseViewPositionMessage { $resetColor = '' - if ($Host.UI.SupportsVirtualTerminal -and ($null -eq $env:__SuppressAnsiEscapeSequences)) { + if ($Host.UI.SupportsVirtualTerminal -and ([string]::IsNullOrEmpty($env:__SuppressAnsiEscapeSequences))) { $resetColor = [System.Management.Automation.VTUtility]::GetEscapeSequence( [System.Management.Automation.VTUtility+VT]::Reset ) } function Get-VT100Color([ConsoleColor] $color) { - if (!$Host.UI.SupportsVirtualTerminal -or ($null -ne $env:__SuppressAnsiEscapeSequences)) { + if (!$Host.UI.SupportsVirtualTerminal -or !([string]::IsNullOrEmpty($env:__SuppressAnsiEscapeSequences))) { return '' } From 8748514f445b43313f170ac7e825762b7e8536c2 Mon Sep 17 00:00:00 2001 From: Steve Lee Date: Fri, 5 Jun 2020 17:14:47 -0700 Subject: [PATCH 3/6] fix test redirecting stderr --- 1 | 6 ++++++ test/powershell/engine/Formatting/ErrorView.Tests.ps1 | 5 +++-- 2 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 1 diff --git a/1 b/1 new file mode 100644 index 00000000000..3c80b03dfcf --- /dev/null +++ b/1 @@ -0,0 +1,6 @@ +ParserError: +Line | + 1 |  foreach abc + |  ~ + | Missing opening '(' after keyword 'foreach'. + diff --git a/test/powershell/engine/Formatting/ErrorView.Tests.ps1 b/test/powershell/engine/Formatting/ErrorView.Tests.ps1 index c23883410b6..237114a1e3d 100644 --- a/test/powershell/engine/Formatting/ErrorView.Tests.ps1 +++ b/test/powershell/engine/Formatting/ErrorView.Tests.ps1 @@ -102,12 +102,13 @@ Describe 'Tests for $ErrorView' -Tag CI { It "Position message does not contain line information" { - $e = & "$PSHOME/pwsh" -noprofile -command "foreach abc" | Out-String + $e = & "$PSHOME/pwsh" -noprofile -command "foreach abc" 2>&1 | out-string + $e | Should -Not -BeNullOrEmpty $e | Should -Not -BeLike "*At line*" } It "Error shows if `$PSModuleAutoLoadingPreference is set to 'none'" { - $e = & "$PSHOME/pwsh" -noprofile -command '$PSModuleAutoLoadingPreference = ""none""; cmdletThatDoesntExist' | Out-String + $e = & "$PSHOME/pwsh" -noprofile -command '$PSModuleAutoLoadingPreference = ""none""; cmdletThatDoesntExist' 2>&1 | out-string $e | Should -BeLike "*cmdletThatDoesntExist*" } } From 48096dab26448c25786f8cfeeb38e222417fce8f Mon Sep 17 00:00:00 2001 From: Steve Lee Date: Fri, 5 Jun 2020 18:44:46 -0700 Subject: [PATCH 4/6] remove accidentally added file --- 1 | 6 ------ 1 file changed, 6 deletions(-) delete mode 100644 1 diff --git a/1 b/1 deleted file mode 100644 index 3c80b03dfcf..00000000000 --- a/1 +++ /dev/null @@ -1,6 +0,0 @@ -ParserError: -Line | - 1 |  foreach abc - |  ~ - | Missing opening '(' after keyword 'foreach'. - From b853f73840eababfea3de38db9f1127ef35f534d Mon Sep 17 00:00:00 2001 From: Ilya Date: Sun, 7 Jun 2020 00:23:07 +0500 Subject: [PATCH 5/6] Update test/powershell/engine/Formatting/ErrorView.Tests.ps1 --- test/powershell/engine/Formatting/ErrorView.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/powershell/engine/Formatting/ErrorView.Tests.ps1 b/test/powershell/engine/Formatting/ErrorView.Tests.ps1 index 237114a1e3d..c08973051d9 100644 --- a/test/powershell/engine/Formatting/ErrorView.Tests.ps1 +++ b/test/powershell/engine/Formatting/ErrorView.Tests.ps1 @@ -102,7 +102,7 @@ Describe 'Tests for $ErrorView' -Tag CI { It "Position message does not contain line information" { - $e = & "$PSHOME/pwsh" -noprofile -command "foreach abc" 2>&1 | out-string + $e = & "$PSHOME/pwsh" -noprofile -command "foreach abc" 2>&1 | Out-String $e | Should -Not -BeNullOrEmpty $e | Should -Not -BeLike "*At line*" } From d5d595eb91060ed0ea591e8ae4f14b50dbfa1436 Mon Sep 17 00:00:00 2001 From: Ilya Date: Sun, 7 Jun 2020 00:23:22 +0500 Subject: [PATCH 6/6] Update test/powershell/engine/Formatting/ErrorView.Tests.ps1 --- test/powershell/engine/Formatting/ErrorView.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/powershell/engine/Formatting/ErrorView.Tests.ps1 b/test/powershell/engine/Formatting/ErrorView.Tests.ps1 index c08973051d9..1087f3700a7 100644 --- a/test/powershell/engine/Formatting/ErrorView.Tests.ps1 +++ b/test/powershell/engine/Formatting/ErrorView.Tests.ps1 @@ -108,7 +108,7 @@ Describe 'Tests for $ErrorView' -Tag CI { } It "Error shows if `$PSModuleAutoLoadingPreference is set to 'none'" { - $e = & "$PSHOME/pwsh" -noprofile -command '$PSModuleAutoLoadingPreference = ""none""; cmdletThatDoesntExist' 2>&1 | out-string + $e = & "$PSHOME/pwsh" -noprofile -command '$PSModuleAutoLoadingPreference = ""none""; cmdletThatDoesntExist' 2>&1 | Out-String $e | Should -BeLike "*cmdletThatDoesntExist*" } }