From 4b207b4b7dce52bd2db62f2741b8be8f9f572434 Mon Sep 17 00:00:00 2001 From: Andy Jordan Date: Wed, 3 Aug 2022 13:54:08 -0700 Subject: [PATCH 1/2] Add regression test for when `prompt` is undefined Also improve regression test for when it throws. --- .../Session/PsesInternalHostTests.cs | 25 ++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/test/PowerShellEditorServices.Test/Session/PsesInternalHostTests.cs b/test/PowerShellEditorServices.Test/Session/PsesInternalHostTests.cs index 41d5cbb82..c41f97308 100644 --- a/test/PowerShellEditorServices.Test/Session/PsesInternalHostTests.cs +++ b/test/PowerShellEditorServices.Test/Session/PsesInternalHostTests.cs @@ -88,7 +88,7 @@ public async Task CanQueueParallelPSCommands() public async Task CanCancelExecutionWithToken() { using CancellationTokenSource cancellationSource = new(millisecondsDelay: 1000); - await Assert.ThrowsAsync(() => + _ = await Assert.ThrowsAsync(() => { return psesHost.ExecutePSCommandAsync( new PSCommand().AddScript("Start-Sleep 10"), @@ -170,10 +170,29 @@ await psesHost.ExecuteDelegateAsync( [Fact] public async Task CanHandleBrokenPrompt() { - await psesHost.ExecutePSCommandAsync( - new PSCommand().AddScript("function prompt { throw }"), + _ = await Assert.ThrowsAsync(() => + { + return psesHost.ExecutePSCommandAsync( + new PSCommand().AddScript("function prompt { throw }; prompt"), + CancellationToken.None); + }).ConfigureAwait(true); + + string prompt = await psesHost.ExecuteDelegateAsync( + nameof(psesHost.GetPrompt), + executionOptions: null, + (_, _) => psesHost.GetPrompt(CancellationToken.None), CancellationToken.None).ConfigureAwait(true); + Assert.Equal(PsesInternalHost.DefaultPrompt, prompt); + } + + [Fact] + public async Task CanHandleUndefinedPrompt() + { + Assert.Empty(await psesHost.ExecutePSCommandAsync( + new PSCommand().AddScript("Remove-Item function:prompt; Get-Item function:prompt"), + CancellationToken.None).ConfigureAwait(true)); + string prompt = await psesHost.ExecuteDelegateAsync( nameof(psesHost.GetPrompt), executionOptions: null, From 238a9d8a13673bd2a008b6bbc8d17b69e902f323 Mon Sep 17 00:00:00 2001 From: Andy Jordan <2226434+andschwa@users.noreply.github.com> Date: Wed, 3 Aug 2022 14:04:56 -0700 Subject: [PATCH 2/2] Update test/PowerShellEditorServices.Test/Session/PsesInternalHostTests.cs Co-authored-by: Patrick Meinecke --- .../Session/PsesInternalHostTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/PowerShellEditorServices.Test/Session/PsesInternalHostTests.cs b/test/PowerShellEditorServices.Test/Session/PsesInternalHostTests.cs index c41f97308..d66c46938 100644 --- a/test/PowerShellEditorServices.Test/Session/PsesInternalHostTests.cs +++ b/test/PowerShellEditorServices.Test/Session/PsesInternalHostTests.cs @@ -190,7 +190,7 @@ public async Task CanHandleBrokenPrompt() public async Task CanHandleUndefinedPrompt() { Assert.Empty(await psesHost.ExecutePSCommandAsync( - new PSCommand().AddScript("Remove-Item function:prompt; Get-Item function:prompt"), + new PSCommand().AddScript("Remove-Item function:prompt; Get-Item function:prompt -ErrorAction Ignore"), CancellationToken.None).ConfigureAwait(true)); string prompt = await psesHost.ExecuteDelegateAsync(