Add support to ActionPreference.Break to break into debugger (#8205)

This commit is contained in:
Kirk Munro
2019-08-23 10:34:10 -07:00
committed by Dongbo Wang
parent 27fcb35913
commit 8b9f4124ce
16 changed files with 655 additions and 115 deletions
@@ -1,6 +1,56 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
Describe 'Basic debugger tests' -tag 'CI' {
BeforeAll {
Register-DebuggerHandler
}
AfterAll {
Unregister-DebuggerHandler
}
Context 'The value of $? should be preserved when exiting the debugger' {
BeforeAll {
$testScript = {
function Test-DollarQuestionMark {
[CmdletBinding()]
param()
Get-Process -id ([int]::MaxValue)
if (-not $?) {
'The value of $? was preserved during debugging.'
} else {
'The value of $? was changed to $true during debugging.'
}
}
$global:DollarQuestionMarkResults = Test-DollarQuestionMark -ErrorAction Break
}
$global:results = @(Test-Debugger -ScriptBlock $testScript -CommandQueue '$?')
}
AfterAll {
Remove-Variable -Name DollarQuestionMarkResults -Scope Global -ErrorAction Ignore
}
It 'Should show 2 debugger commands were invoked' {
# One extra for the implicit 'c' command that keeps the debugger automation moving
$results.Count | Should -Be 2
}
It 'Should have $false output from the first $? command' {
$results[0].Output | Should -BeOfType bool
$results[0].Output | Should -Not -BeTrue
}
It 'Should have string output showing that $? was preserved as $false by the debugger' {
$global:DollarQuestionMarkResults | Should -BeOfType string
$global:DollarQuestionMarkResults | Should -BeExactly 'The value of $? was preserved during debugging.'
}
}
}
Describe "Breakpoints when set should be hit" -tag "CI" {
Context "Basic tests" {
BeforeAll {