From 72cd28c3366e0d7511f586f41cfd0d1ba8407520 Mon Sep 17 00:00:00 2001 From: v-alexjo Date: Thu, 9 Jun 2016 15:00:52 -0700 Subject: [PATCH] Moving debugging tests out of Set-PSBreakpoint tests --- .../singleshell/config/MshSnapinInfo.cs | 4 +- test/powershell/PSDebugging.Tests.ps1 | 148 ++++++++++++++++++ 2 files changed, 150 insertions(+), 2 deletions(-) create mode 100644 test/powershell/PSDebugging.Tests.ps1 diff --git a/src/System.Management.Automation/singleshell/config/MshSnapinInfo.cs b/src/System.Management.Automation/singleshell/config/MshSnapinInfo.cs index 361d3c7cc..eb6bd942e 100644 --- a/src/System.Management.Automation/singleshell/config/MshSnapinInfo.cs +++ b/src/System.Management.Automation/singleshell/config/MshSnapinInfo.cs @@ -1408,7 +1408,7 @@ namespace System.Management.Automation { defaultMshSnapins = new List() { -#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, "GetEventResources,Description", "GetEventResources,Vendor"), #endif @@ -1427,7 +1427,7 @@ namespace System.Management.Automation "SecurityMshSnapInResources,Description","SecurityMshSnapInResources,Vendor") }; -#if !LINUX +#if !CORECLR //TODO:CORECLR - The 'Microsoft.WSMan.Management' module will be available on OneCore soon if (!Utils.IsWinPEHost()) { defaultMshSnapins.Add(new DefaultPSSnapInInformation("Microsoft.WSMan.Management", "Microsoft.WSMan.Management", null, diff --git a/test/powershell/PSDebugging.Tests.ps1 b/test/powershell/PSDebugging.Tests.ps1 new file mode 100644 index 000000000..9dd964c13 --- /dev/null +++ b/test/powershell/PSDebugging.Tests.ps1 @@ -0,0 +1,148 @@ +using namespace System.Diagnostics + +Describe "PowerShell Command Debugging"{ + $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 "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") + + foreach ($i in 1..2) { + $process.StandardOutput.ReadLine() + } + + $process.StandardInput.Write("foo`n") + + foreach ($i in 1..13) { + $process.StandardOutput.ReadLine() + } + + $process.StandardInput.Write("s`n") + + foreach ($i in 1..3) { + $process.StandardOutput.ReadLine() } + + $process.StandardInput.Write("s`n") + + foreach ($i in 1..3) { + $process.StandardOutput.ReadLine() + } + + $process.StandardInput.Write("s`n") + + foreach ($i in 1..3) { + $process.StandardOutput.ReadLine() + } + + $process.StandardInput.Close() + + EnsureChildHasExited $process + $process.ExitCode | Should Be 0 + } + + It "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") + + foreach ($i in 1..2) { + $process.StandardOutput.ReadLine() + } + + $process.StandardInput.Write("foo`n") + + foreach ($i in 1..13) { + $process.StandardOutput.ReadLine() + } + + $process.StandardInput.Write("c`n") + $process.StandardOutput.ReadLine() + $process.StandardOutput.ReadLine() + + $process.StandardInput.Close() + + EnsureChildHasExited $process + $process.ExitCode | Should Be 0 + } + + It "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") + + foreach ($i in 1..2) { + $process.StandardOutput.ReadLine() + } + + $process.StandardInput.Write("foo`n") + + foreach ($i in 1..13) { + $process.StandardOutput.ReadLine() + } + $process.StandardInput.Write("h`n") + foreach ($i in 1..23) { + $line = $process.StandardOutput.ReadLine() + } + + $process.StandardInput.Write("s`n") + + foreach ($i in 1..3) { + $process.StandardOutput.ReadLine() + } + + $process.StandardInput.Write("s`n") + + foreach ($i in 1..3) { + $process.StandardOutput.ReadLine() + } + + $process.StandardInput.Write("s`n") + + foreach ($i in 1..3) { + $process.StandardOutput.ReadLine() + } + + $process.StandardInput.Close() + + EnsureChildHasExited $process + $line | Should Be "For instructions about how to customize your debugger prompt, type `"help about_prompt`"." +# $process.ExitCode | Should Be 0 + + + + } +} + + +