Fix ConciseView for interactive advanced function writing error (#13623)

This commit is contained in:
Steve Lee 2020-09-14 11:07:37 -07:00 committed by GitHub
parent af6d9fbe14
commit d25d964d57
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 1 deletions

View file

@ -1226,7 +1226,7 @@ namespace System.Management.Automation.Runspaces
$reason = 'Exception'
}
# MyCommand can be the script block, so we don't want to show that so check if it's an actual command
elseif ($myinv.MyCommand -and (Get-Command -Name $myinv.MyCommand -ErrorAction Ignore))
elseif ($myinv.MyCommand -and $myinv.MyCommand.Name -and (Get-Command -Name $myinv.MyCommand -ErrorAction Ignore))
{
$reason = $myinv.MyCommand
}

View file

@ -111,6 +111,20 @@ Describe 'Tests for $ErrorView' -Tag CI {
$e = & "$PSHOME/pwsh" -noprofile -command '$PSModuleAutoLoadingPreference = ""none""; cmdletThatDoesntExist' 2>&1 | Out-String
$e | Should -BeLike "*cmdletThatDoesntExist*"
}
It "Error shows for advanced function" {
# need to have it virtually interactive so that InvocationInfo.MyCommand is empty
$e = '[cmdletbinding()]param()$pscmdlet.writeerror([System.Management.Automation.ErrorRecord]::new(([System.NotImplementedException]::new("myTest")),"stub","notimplemented","command"))' | pwsh -noprofile -file - 2>&1 | Out-String
$e | Should -Not -BeNullOrEmpty
# need to see if ANSI escape sequences are in the output as ANSI is disabled for CI
if ($e.Contains("`e")) {
$e | Should -BeLike "*: `e*myTest*"
}
else {
$e | Should -BeLike "*: myTest*"
}
}
}
Context 'NormalView tests' {