Skip to content

Commit 81f9240

Browse files
committed
Add regression test for $PSDebugContext in prompt function
1 parent c710490 commit 81f9240

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
$promptSawDebug = $false
2+
3+
function prompt {
4+
if (Test-Path variable:/PSDebugContext -ErrorAction SilentlyContinue) {
5+
$promptSawDebug = $true
6+
}
7+
8+
return "$promptSawDebug > "
9+
}
10+
11+
Write-Host "Debug over"

test/PowerShellEditorServices.Test/Debugging/DebugServiceTests.cs

+18
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,24 @@ public async Task DebuggerRunsCommandsWhileStopped()
501501
Assert.Equal(17, (await executeTask.ConfigureAwait(true))[0]);
502502
}
503503

504+
// Regression test asserting that the PSDebugContext variable is available when running the
505+
// "prompt" function. While we're unable to test the REPL loop, this still covers the
506+
// behavior as I verified that it stepped through "ExecuteInDebugger" (which was the
507+
// original problem).
508+
[Fact]
509+
public async Task DebugContextAvailableInPrompt()
510+
{
511+
await debugService.SetCommandBreakpointsAsync(
512+
new[] { CommandBreakpointDetails.Create("Write-Host") }).ConfigureAwait(true);
513+
514+
ScriptFile testScript = GetDebugScript("PSDebugContextTest.ps1");
515+
Task _ = ExecutePowerShellCommand(testScript.FilePath);
516+
AssertDebuggerStopped(testScript.FilePath, 11);
517+
518+
VariableDetails prompt = await debugService.EvaluateExpressionAsync("prompt", false).ConfigureAwait(true);
519+
Assert.Equal("\"True > \"", prompt.ValueString);
520+
}
521+
504522
[Fact]
505523
public async Task DebuggerVariableStringDisplaysCorrectly()
506524
{

0 commit comments

Comments
 (0)