Skip to content

Commit e49fa0a

Browse files
Add regression test for when prompt is undefined (#1867)
Also improve regression test for when it throws. Co-authored-by: Patrick Meinecke <[email protected]>
1 parent 9dec136 commit e49fa0a

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

test/PowerShellEditorServices.Test/Session/PsesInternalHostTests.cs

+22-3
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public async Task CanQueueParallelPSCommands()
8888
public async Task CanCancelExecutionWithToken()
8989
{
9090
using CancellationTokenSource cancellationSource = new(millisecondsDelay: 1000);
91-
await Assert.ThrowsAsync<TaskCanceledException>(() =>
91+
_ = await Assert.ThrowsAsync<TaskCanceledException>(() =>
9292
{
9393
return psesHost.ExecutePSCommandAsync(
9494
new PSCommand().AddScript("Start-Sleep 10"),
@@ -170,10 +170,29 @@ await psesHost.ExecuteDelegateAsync(
170170
[Fact]
171171
public async Task CanHandleBrokenPrompt()
172172
{
173-
await psesHost.ExecutePSCommandAsync(
174-
new PSCommand().AddScript("function prompt { throw }"),
173+
_ = await Assert.ThrowsAsync<RuntimeException>(() =>
174+
{
175+
return psesHost.ExecutePSCommandAsync(
176+
new PSCommand().AddScript("function prompt { throw }; prompt"),
177+
CancellationToken.None);
178+
}).ConfigureAwait(true);
179+
180+
string prompt = await psesHost.ExecuteDelegateAsync(
181+
nameof(psesHost.GetPrompt),
182+
executionOptions: null,
183+
(_, _) => psesHost.GetPrompt(CancellationToken.None),
175184
CancellationToken.None).ConfigureAwait(true);
176185

186+
Assert.Equal(PsesInternalHost.DefaultPrompt, prompt);
187+
}
188+
189+
[Fact]
190+
public async Task CanHandleUndefinedPrompt()
191+
{
192+
Assert.Empty(await psesHost.ExecutePSCommandAsync<PSObject>(
193+
new PSCommand().AddScript("Remove-Item function:prompt; Get-Item function:prompt -ErrorAction Ignore"),
194+
CancellationToken.None).ConfigureAwait(true));
195+
177196
string prompt = await psesHost.ExecuteDelegateAsync(
178197
nameof(psesHost.GetPrompt),
179198
executionOptions: null,

0 commit comments

Comments
 (0)