Skip to content
Merged
Changes from 1 commit
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
Next Next commit
Add regression test for when prompt is undefined
Also improve regression test for when it throws.
  • Loading branch information
andyleejordan committed Aug 3, 2022
commit 4b207b4b7dce52bd2db62f2741b8be8f9f572434
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public async Task CanQueueParallelPSCommands()
public async Task CanCancelExecutionWithToken()
{
using CancellationTokenSource cancellationSource = new(millisecondsDelay: 1000);
await Assert.ThrowsAsync<TaskCanceledException>(() =>
_ = await Assert.ThrowsAsync<TaskCanceledException>(() =>
{
return psesHost.ExecutePSCommandAsync(
new PSCommand().AddScript("Start-Sleep 10"),
Expand Down Expand Up @@ -170,10 +170,29 @@ await psesHost.ExecuteDelegateAsync(
[Fact]
public async Task CanHandleBrokenPrompt()
{
await psesHost.ExecutePSCommandAsync(
new PSCommand().AddScript("function prompt { throw }"),
_ = await Assert.ThrowsAsync<RuntimeException>(() =>
{
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<PSObject>(
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,
Expand Down