From 81f92402ecd137647ac216444101e4bedc85abd6 Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Wed, 20 Jul 2022 09:57:11 -0700 Subject: [PATCH 1/2] Add regression test for `$PSDebugContext` in `prompt` function --- .../Debugging/PSDebugContextTest.ps1 | 11 +++++++++++ .../Debugging/DebugServiceTests.cs | 18 ++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 test/PowerShellEditorServices.Test.Shared/Debugging/PSDebugContextTest.ps1 diff --git a/test/PowerShellEditorServices.Test.Shared/Debugging/PSDebugContextTest.ps1 b/test/PowerShellEditorServices.Test.Shared/Debugging/PSDebugContextTest.ps1 new file mode 100644 index 000000000..103af9918 --- /dev/null +++ b/test/PowerShellEditorServices.Test.Shared/Debugging/PSDebugContextTest.ps1 @@ -0,0 +1,11 @@ +$promptSawDebug = $false + +function prompt { + if (Test-Path variable:/PSDebugContext -ErrorAction SilentlyContinue) { + $promptSawDebug = $true + } + + return "$promptSawDebug > " +} + +Write-Host "Debug over" diff --git a/test/PowerShellEditorServices.Test/Debugging/DebugServiceTests.cs b/test/PowerShellEditorServices.Test/Debugging/DebugServiceTests.cs index cb018ae5e..2603a3186 100644 --- a/test/PowerShellEditorServices.Test/Debugging/DebugServiceTests.cs +++ b/test/PowerShellEditorServices.Test/Debugging/DebugServiceTests.cs @@ -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() { From 49500fa48b9502595641f654a3bf63bd4b5d9901 Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Thu, 21 Jul 2022 09:38:21 -0700 Subject: [PATCH 2/2] Skip flaky test on Linux --- .../Debugging/DebugServiceTests.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/PowerShellEditorServices.Test/Debugging/DebugServiceTests.cs b/test/PowerShellEditorServices.Test/Debugging/DebugServiceTests.cs index 2603a3186..02adda0d3 100644 --- a/test/PowerShellEditorServices.Test/Debugging/DebugServiceTests.cs +++ b/test/PowerShellEditorServices.Test/Debugging/DebugServiceTests.cs @@ -587,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);