Fix ConciseView for interactive advanced function writing error (#13623)
This commit is contained in:
parent
af6d9fbe14
commit
d25d964d57
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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' {
|
||||
|
|
Loading…
Reference in a new issue