mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Fix line breakpoints for return statements without a value (#17179)
This commit is contained in:
@@ -331,6 +331,50 @@ elseif (Test-Path $PSCommandPath)
|
||||
$Breakpoint.HitCount | Should -Be $HitCount
|
||||
}
|
||||
}
|
||||
|
||||
Context "Break point on return should hit" {
|
||||
BeforeAll {
|
||||
$return_script_1 = @'
|
||||
return
|
||||
'@
|
||||
$return_script_2 = @'
|
||||
return 10
|
||||
'@
|
||||
$return_script_3 = @'
|
||||
trap {
|
||||
'statement to ignore trap registration sequence point'
|
||||
return
|
||||
}
|
||||
|
||||
throw
|
||||
'@
|
||||
|
||||
$ReturnScript_1 = Setup -PassThru -File ReturnScript_1.ps1 -Content $return_script_1
|
||||
$bp_1 = Set-PSBreakpoint -Script $ReturnScript_1 -Line 1 -Action { continue }
|
||||
|
||||
$ReturnScript_2 = Setup -PassThru -File ReturnScript_2.ps1 -Content $return_script_2
|
||||
$bp_2 = Set-PSBreakpoint -Script $ReturnScript_2 -Line 1 -Action { continue }
|
||||
|
||||
$ReturnScript_3 = Setup -PassThru -File ReturnScript_3.ps1 -Content $return_script_3
|
||||
$bp_3 = Set-PSBreakpoint -Script $ReturnScript_3 -Line 3 -Action { continue }
|
||||
|
||||
$testCases = @(
|
||||
@{ Name = "return without pipeline should be hit once"; Path = $ReturnScript_1; Breakpoint = $bp_1; HitCount = 1 }
|
||||
@{ Name = "return with pipeline should be hit once"; Path = $ReturnScript_2; Breakpoint = $bp_2; HitCount = 1 }
|
||||
@{ Name = "return from trap should be hit once"; Path = $ReturnScript_3; Breakpoint = $bp_3; HitCount = 1 }
|
||||
)
|
||||
}
|
||||
|
||||
AfterAll {
|
||||
Get-PSBreakpoint -Script $ReturnScript_1, $ReturnScript_2, $ReturnScript_3 | Remove-PSBreakpoint
|
||||
}
|
||||
|
||||
It "Return statement <Name>" -TestCases $testCases {
|
||||
param($Path, $Breakpoint, $HitCount)
|
||||
$null = & $Path
|
||||
$Breakpoint.HitCount | Should -Be $HitCount
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Describe "It should be possible to reset runspace debugging" -Tag "Feature" {
|
||||
|
||||
Reference in New Issue
Block a user