-
Notifications
You must be signed in to change notification settings - Fork 510
Debugger crashing unexpectedly on Pester tests #66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Haven't seen this issue before, I'll take a look. Thanks Andrew! |
@daviwil Spent a little time looking at this and I'm a bit perplexed. PowerShell is telling me (via Get-PSCallStack) that there are 13 stack frames. However when we ask for the variables for the 4th stack frame (index 3) it errors out. I observe the very same behavior from ISE (just using the commands directly):
Any idea what's up with that? Get-PSCallStack and Get-Variable -Scope don't seem to be in agreement over the number of stack frames. I guess we can add code to detect the error from Get-Variable but then do we pitch the stack frames we don't have variables for? Here's a repro ZIP - |
Hmmm, I'll ask someone about this, haven't seen that before. |
Ok, it looks like |
@daviwil Thanks. I'll look at this tonight. |
Hmm, $scriptVar = 'scriptVar'
function Test-Scope ($p1) {
$foo = 42
return $true
}
Test-Scope bar After the breakpoint is hit in the debugger, here is the output I get querying
The results of calling |
Hey @lzybkr, could you help us understand the use of |
GetFrameVariables was added for debuggers, but it does look useless in V5. I recall it working better in V3, but there were issues with it. Get-Variable is the alternative, there is no other api or cmdlet that provides the promise of GetFrameVariables. The primary issue is dot sourcing. When you dot source, you introduce a new frame, but not a new scope. A secondary issue is that some variables are preserved when you dot source, e.g.
Get-Variable doesn't handle this correctly, and GetFrameVariables did, or at least was meant to. Bottom line, I need to fix GetFrameVariables, but you'll need to use Get-Variable until then, and w/ older versions of PS. |
Thanks for the clarification! We'll continue using Get-Variable and try find a graceful way to handle the gotchas until a fix for GetFrameVariables appears in a later version of PowerShell. Having the ability to easily see the user-defined variables for each call stack frame is really helpful so I think using Get-Variable is fine for now even if there are some cases in which it doesn't work. We just need to make sure we're showing things as accurately possible or not at all in those cases if accuracy can't be guaranteed. |
Do we have a property somewhere that we can query from C# for which version of PowerShell the debug host is currently using? I see the code for this eventually needing this sort of check. Or would this be a compile-time |
Yep, PowerShellContext.PowerShellVersion will give you that. |
OK fixing this but the fix is in the PowerShellEditorServices repo. Just realized that so my commit reference to issue 66 is for the wrong repo. |
Keith submitted a fix for this here: PowerShell/PowerShellEditorServices@b1e0e2d This should work fine for you in the 0.4.0 release :) |
Thanks, guys! |
I've got a pester test that I'm trying to debug in VS Code. To invoke the test, I have a script pester.ps1 registered to a debug configuration in .vscode\launch.json. This script is simple:
.vscode\pester.ps1:
My pester code looks like this:
tests\MyModule.Tests.ps1
Watching the Debug Console, the Describe and Context portion are logged before the debugger crashes. If I put a breakpoint on the Context line, however, it crashes before breaking, only printing the Describe line. If I put a breakpoint on the Describe line, it successfully breaks into the debugger at that line.
The text was updated successfully, but these errors were encountered: