Skip to content

Add regression test for $PSDebugContext in prompt function #1857

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

Merged
merged 2 commits into from
Jul 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
$promptSawDebug = $false

function prompt {
if (Test-Path variable:/PSDebugContext -ErrorAction SilentlyContinue) {
$promptSawDebug = $true
}

return "$promptSawDebug > "
}

Write-Host "Debug over"
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,24 @@ public async Task DebuggerRunsCommandsWhileStopped()
Assert.Equal(17, (await executeTask.ConfigureAwait(true))[0]);
}

// Regression test asserting that the PSDebugContext variable is available when running the
// "prompt" function. While we're unable to test the REPL loop, this still covers the
// behavior as I verified that it stepped through "ExecuteInDebugger" (which was the
// original problem).
[Fact]
public async Task DebugContextAvailableInPrompt()
{
await debugService.SetCommandBreakpointsAsync(
new[] { CommandBreakpointDetails.Create("Write-Host") }).ConfigureAwait(true);

ScriptFile testScript = GetDebugScript("PSDebugContextTest.ps1");
Task _ = ExecutePowerShellCommand(testScript.FilePath);
AssertDebuggerStopped(testScript.FilePath, 11);

VariableDetails prompt = await debugService.EvaluateExpressionAsync("prompt", false).ConfigureAwait(true);
Assert.Equal("\"True > \"", prompt.ValueString);
}

[Fact]
public async Task DebuggerVariableStringDisplaysCorrectly()
{
Expand Down Expand Up @@ -569,9 +587,10 @@ await debugService.SetLineBreakpointsAsync(
Assert.Equal("$false", falseVar.ValueString);
}

[Fact]
[SkippableFact]
public async Task DebuggerSetsVariablesNoConversion()
{
Skip.If(VersionUtils.IsLinux, "Test hangs on Linux for some reason");
await debugService.SetLineBreakpointsAsync(
variableScriptFile,
new[] { BreakpointDetails.Create(variableScriptFile.FilePath, 14) }).ConfigureAwait(true);
Expand Down