From ec20043a91ebb58e7e208630c5ef38f2af69e7e4 Mon Sep 17 00:00:00 2001 From: Steve Lee Date: Thu, 11 Jun 2020 04:07:18 -0700 Subject: [PATCH] Remove use of `Test-Path` in ConciseView (#12778) --- .../DefaultFormatters/PowerShellCore_format_ps1xml.cs | 8 ++++---- test/powershell/engine/Formatting/ErrorView.Tests.ps1 | 8 +++++++- 2 files changed, 11 insertions(+), 5 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 f22ccc9725..dfd610e475 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 @@ namespace System.Management.Automation.Runspaces $maxDepth = 10 $ellipsis = ""`u{2026}"" $resetColor = '' - if ($Host.UI.SupportsVirtualTerminal -and !(Test-Path 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 (Test-Path env:__SuppressAnsiEscapeSequences)) { + if (!$Host.UI.SupportsVirtualTerminal -or !([string]::IsNullOrEmpty($env:__SuppressAnsiEscapeSequences))) { return '' } @@ -1013,14 +1013,14 @@ namespace System.Management.Automation.Runspaces function Get-ConciseViewPositionMessage { $resetColor = '' - if ($Host.UI.SupportsVirtualTerminal -and !(Test-Path 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 (Test-Path env:__SuppressAnsiEscapeSequences)) { + if (!$Host.UI.SupportsVirtualTerminal -or !([string]::IsNullOrEmpty($env:__SuppressAnsiEscapeSequences))) { return '' } diff --git a/test/powershell/engine/Formatting/ErrorView.Tests.ps1 b/test/powershell/engine/Formatting/ErrorView.Tests.ps1 index b230ce59f6..1087f3700a 100644 --- a/test/powershell/engine/Formatting/ErrorView.Tests.ps1 +++ b/test/powershell/engine/Formatting/ErrorView.Tests.ps1 @@ -102,9 +102,15 @@ 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' 2>&1 | Out-String + $e | Should -BeLike "*cmdletThatDoesntExist*" + } } Context 'NormalView tests' {