mirror of
https://github.com/aphrody-labs/PowerShell.git
synced 2026-10-17 04:36:39 +00:00
Merge pull request #1090 from PowerShell/scriptdebug
Fix Broken Powershell Debugging
This commit is contained in:
commit
cd6b4e2ebc
3 files changed
+197
-2
No files matched your search
@@ -24,7 +24,7 @@
|
|||||||
"netstandard1.5": {
|
"netstandard1.5": {
|
||||||
"imports": [ "dnxcore50" ],
|
"imports": [ "dnxcore50" ],
|
||||||
"buildOptions": {
|
"buildOptions": {
|
||||||
"define": [ "CORECLR" ],
|
"define": [ "CORECLR", "PORTABLE" ],
|
||||||
"compile": {
|
"compile": {
|
||||||
"exclude": [
|
"exclude": [
|
||||||
"cimSupport/cmdletization/xml/cmdlets-over-objects.objectModel.autogen.cs",
|
"cimSupport/cmdletization/xml/cmdlets-over-objects.objectModel.autogen.cs",
|
||||||
|
|||||||
@@ -1408,7 +1408,7 @@ namespace System.Management.Automation
|
|||||||
{
|
{
|
||||||
defaultMshSnapins = new List<DefaultPSSnapInInformation>()
|
defaultMshSnapins = new List<DefaultPSSnapInInformation>()
|
||||||
{
|
{
|
||||||
#if !LINUX // Microsoft.PowerShell.Commands.Diagnostics.dll needs to be ported
|
#if !PORTABLE // Microsoft.PowerShell.Commands.Diagnostics.dll needs to be ported
|
||||||
new DefaultPSSnapInInformation("Microsoft.PowerShell.Diagnostics", "Microsoft.PowerShell.Commands.Diagnostics", null,
|
new DefaultPSSnapInInformation("Microsoft.PowerShell.Diagnostics", "Microsoft.PowerShell.Commands.Diagnostics", null,
|
||||||
"GetEventResources,Description", "GetEventResources,Vendor"),
|
"GetEventResources,Description", "GetEventResources,Vendor"),
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -0,0 +1,195 @@
|
|||||||
|
using namespace System.Diagnostics
|
||||||
|
|
||||||
|
Describe "PowerShell Command Debugging" {
|
||||||
|
|
||||||
|
BeforeAll {
|
||||||
|
# These tests cannot yet be run on OS X on Travis, or on any Windows, due to redirected stdin problems
|
||||||
|
if ($env:TRAVIS_OS_NAME -eq "osx" -or $IsWindows) {
|
||||||
|
$ItArgs = @{ pending = $true }
|
||||||
|
} else {
|
||||||
|
$ItArgs = @{}
|
||||||
|
}
|
||||||
|
|
||||||
|
$powershell = Join-Path -Path $PsHome -ChildPath "powershell"
|
||||||
|
}
|
||||||
|
|
||||||
|
function NewProcessStartInfo([string]$CommandLine, [switch]$RedirectStdIn)
|
||||||
|
{
|
||||||
|
return [ProcessStartInfo]@{
|
||||||
|
FileName = $powershell
|
||||||
|
Arguments = $CommandLine
|
||||||
|
RedirectStandardInput = $RedirectStdIn
|
||||||
|
RedirectStandardOutput = $true
|
||||||
|
RedirectStandardError = $true
|
||||||
|
UseShellExecute = $false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function RunPowerShell([ProcessStartInfo]$debugfn)
|
||||||
|
{
|
||||||
|
$process = [Process]::Start($debugfn)
|
||||||
|
return $process
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function EnsureChildHasExited([Process]$process, [int]$WaitTimeInMS = 15000)
|
||||||
|
{
|
||||||
|
$process.WaitForExit($WaitTimeInMS)
|
||||||
|
|
||||||
|
if (!$process.HasExited)
|
||||||
|
{
|
||||||
|
$process.HasExited | Should Be $true
|
||||||
|
$process.Kill()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
It @ItArgs "Should be able to step into debugging" {
|
||||||
|
$debugfn = NewProcessStartInfo "-noprofile ""`$function:foo = { 'bar' }""" -RedirectStdIn
|
||||||
|
$process = RunPowerShell $debugfn
|
||||||
|
$process.StandardInput.Write("Set-PsBreakpoint -command foo`n")
|
||||||
|
|
||||||
|
$process.StandardInput.Write("foo`n")
|
||||||
|
|
||||||
|
$process.StandardInput.Write("s`n")
|
||||||
|
|
||||||
|
$process.StandardInput.Write("s`n")
|
||||||
|
|
||||||
|
$process.StandardInput.Write("s`n")
|
||||||
|
|
||||||
|
$process.StandardInput.Close()
|
||||||
|
|
||||||
|
EnsureChildHasExited $process
|
||||||
|
$process.ExitCode | Should Be 0
|
||||||
|
}
|
||||||
|
|
||||||
|
It @ItArgs "Should be able to continue into debugging" {
|
||||||
|
$debugfn = NewProcessStartInfo "-noprofile ""`$function:foo = { 'bar' }""" -RedirectStdIn
|
||||||
|
$process = RunPowerShell $debugfn
|
||||||
|
$process.StandardInput.Write("Set-PsBreakpoint -command foo`n")
|
||||||
|
|
||||||
|
$process.StandardInput.Write("foo`n")
|
||||||
|
|
||||||
|
$process.StandardInput.Write("c`n")
|
||||||
|
$process.StandardOutput.ReadLine()
|
||||||
|
$process.StandardOutput.ReadLine()
|
||||||
|
|
||||||
|
$process.StandardInput.Close()
|
||||||
|
|
||||||
|
EnsureChildHasExited $process
|
||||||
|
$process.ExitCode | Should Be 0
|
||||||
|
}
|
||||||
|
|
||||||
|
It @ItArgs "Should be able to list help for debugging" {
|
||||||
|
$debugfn = NewProcessStartInfo "-noprofile ""`$function:foo = { 'bar' }""" -RedirectStdIn
|
||||||
|
$process = RunPowerShell $debugfn
|
||||||
|
$process.StandardInput.Write("Set-PsBreakpoint -command foo`n")
|
||||||
|
|
||||||
|
$process.StandardInput.Write("foo`n")
|
||||||
|
|
||||||
|
$process.StandardInput.Write("h`n")
|
||||||
|
|
||||||
|
foreach ($i in 1..38) {
|
||||||
|
$line = $process.StandardOutput.ReadLine()
|
||||||
|
}
|
||||||
|
|
||||||
|
$process.StandardInput.Write("s`n")
|
||||||
|
$process.StandardInput.Write("s`n")
|
||||||
|
$process.StandardInput.Write("s`n")
|
||||||
|
$process.StandardInput.Close()
|
||||||
|
|
||||||
|
EnsureChildHasExited $process
|
||||||
|
$line | Should Be "For instructions about how to customize your debugger prompt, type `"help about_prompt`"."
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
It @ItArgs "Should be able to step over debugging" {
|
||||||
|
$debugfn = NewProcessStartInfo "-noprofile ""`$function:foo = { 'bar' }""" -RedirectStdIn
|
||||||
|
$process = RunPowerShell $debugfn
|
||||||
|
$process.StandardInput.Write("Set-PsBreakpoint -command foo`n")
|
||||||
|
|
||||||
|
$process.StandardInput.Write("foo`n")
|
||||||
|
$process.StandardInput.Write("v`n")
|
||||||
|
$process.StandardInput.Write("v`n")
|
||||||
|
$process.StandardInput.Write("v`n")
|
||||||
|
|
||||||
|
$process.StandardInput.Close()
|
||||||
|
|
||||||
|
EnsureChildHasExited $process
|
||||||
|
$process.ExitCode | Should Be 0
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
It @ItArgs "Should be able to step out of debugging" {
|
||||||
|
$debugfn = NewProcessStartInfo "-noprofile ""`$function:foo = { 'bar' }""" -RedirectStdIn
|
||||||
|
$process = RunPowerShell $debugfn
|
||||||
|
$process.StandardInput.Write("Set-PsBreakpoint -command foo`n")
|
||||||
|
|
||||||
|
$process.StandardInput.Write("foo`n")
|
||||||
|
$process.StandardInput.Write("o`n")
|
||||||
|
|
||||||
|
$process.StandardInput.Close()
|
||||||
|
|
||||||
|
EnsureChildHasExited $process
|
||||||
|
$process.ExitCode | Should Be 0
|
||||||
|
}
|
||||||
|
|
||||||
|
It @ItArgs "Should be able to quit debugging" {
|
||||||
|
$debugfn = NewProcessStartInfo "-noprofile ""`$function:foo = { 'bar' }""" -RedirectStdIn
|
||||||
|
$process = RunPowerShell $debugfn
|
||||||
|
$process.StandardInput.Write("Set-PsBreakpoint -command foo`n")
|
||||||
|
|
||||||
|
$process.StandardInput.Write("foo`n")
|
||||||
|
$process.StandardInput.Write("q`n")
|
||||||
|
|
||||||
|
$process.StandardInput.Close()
|
||||||
|
|
||||||
|
EnsureChildHasExited $process
|
||||||
|
$process.ExitCode | Should Be 0
|
||||||
|
}
|
||||||
|
|
||||||
|
It @ItArgs "Should be able to list source code in debugging" {
|
||||||
|
$debugfn = NewProcessStartInfo "-noprofile ""`$function:foo = { 'bar' }""" -RedirectStdIn
|
||||||
|
$process = RunPowerShell $debugfn
|
||||||
|
$process.StandardInput.Write("Set-PsBreakpoint -command foo`n") | Write-Host
|
||||||
|
|
||||||
|
$process.StandardInput.Write("foo`n") | Write-Host
|
||||||
|
$process.StandardInput.Write("l`n") | Write-Host
|
||||||
|
|
||||||
|
foreach ($i in 1..19) {
|
||||||
|
$line = $process.StandardOutput.ReadLine()
|
||||||
|
}
|
||||||
|
|
||||||
|
$process.StandardInput.Write("`n")
|
||||||
|
$process.StandardInput.Write("`n")
|
||||||
|
$process.StandardInput.Write("`n")
|
||||||
|
|
||||||
|
$line | Should Be " 1:* `$function:foo = { 'bar' }"
|
||||||
|
$process.StandardInput.Close()
|
||||||
|
EnsureChildHasExited $process
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
It @ItArgs "Should be able to get the call stack in debugging" {
|
||||||
|
$debugfn = NewProcessStartInfo "-noprofile ""`$function:foo = { 'bar' }""" -RedirectStdIn
|
||||||
|
$process = RunPowerShell $debugfn
|
||||||
|
$process.StandardInput.Write("Set-PsBreakpoint -command foo`n") | Write-Host
|
||||||
|
|
||||||
|
$process.StandardInput.Write("foo`n") | Write-Host
|
||||||
|
$process.StandardInput.Write("k`n") | Write-Host
|
||||||
|
|
||||||
|
foreach ($i in 1..20) {
|
||||||
|
$line = $process.StandardOutput.ReadLine()
|
||||||
|
}
|
||||||
|
|
||||||
|
$line | Should Be "foo {} <No file>"
|
||||||
|
$process.StandardInput.Close()
|
||||||
|
EnsureChildHasExited $process
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Reference in new issue
Block a user