Skip to content

Add regression test for when prompt is undefined #1867

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
Aug 3, 2022
Merged
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
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 -ErrorAction Ignore"),
CancellationToken.None).ConfigureAwait(true));

string prompt = await psesHost.ExecuteDelegateAsync(
nameof(psesHost.GetPrompt),
executionOptions: null,
Expand Down