Skip to content

Commit 56e1ccb

Browse files
committed
Add startDebugging tests
1 parent 45e23de commit 56e1ccb

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

test/PowerShellEditorServices.Test.E2E/DebugAdapterProtocolMessageTests.cs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using System.Runtime.InteropServices;
88
using System.Text;
99
using System.Threading.Tasks;
10+
using Microsoft.PowerShell.EditorServices.Handlers;
1011
using Nerdbank.Streams;
1112
using OmniSharp.Extensions.DebugAdapter.Client;
1213
using OmniSharp.Extensions.DebugAdapter.Protocol.Client;
@@ -53,6 +54,12 @@ public class DebugAdapterProtocolMessageTests(ITestOutputHelper output) : IAsync
5354
/// </summary>
5455
private Task<StoppedEvent> nextStopped => nextStoppedTcs.Task;
5556

57+
private readonly TaskCompletionSource<StartDebuggingAttachRequestArguments> startDebuggingAttachRequestTcs = new();
58+
/// <summary>
59+
/// This task is useful for waiting until a StartDebuggingAttachRequest is received.
60+
/// </summary>
61+
private Task<StartDebuggingAttachRequestArguments> startDebuggingAttachRequest => startDebuggingAttachRequestTcs.Task;
62+
5663
public async Task InitializeAsync()
5764
{
5865
// Cleanup testScriptLogPath if it exists due to an interrupted previous run
@@ -100,6 +107,11 @@ send until a launch is sent.
100107
nextStoppedTcs.SetResult(e);
101108
nextStoppedTcs = new();
102109
})
110+
.OnRequest("startDebugging", (StartDebuggingAttachRequestArguments request) =>
111+
{
112+
startDebuggingAttachRequestTcs.SetResult(request);
113+
return Task.CompletedTask;
114+
})
103115
;
104116
});
105117

@@ -513,5 +525,37 @@ public async Task CanRunPesterTestFile()
513525
await client.RequestConfigurationDone(new ConfigurationDoneArguments());
514526
Assert.Equal("pester", await ReadScriptLogLineAsync());
515527
}
528+
529+
#nullable enable
530+
[InlineData("", null, null, 0, 0, null)]
531+
[InlineData("-ProcessId 1234 -RunspaceId 5678", null, null, 1234, 5678, null)]
532+
[InlineData("-ProcessId 1234 -RunspaceId 5678 -ComputerName comp", "comp", null, 1234, 5678, null)]
533+
[InlineData("-CustomPipeName testpipe -RunspaceName rs-name", null, "testpipe", 0, 0, "rs-name")]
534+
[Theory]
535+
public async Task CanLaunchScriptWithNewChildAttachSession(
536+
string paramString,
537+
string? expectedComputerName,
538+
string? expectedPipeName,
539+
int expectedProcessId,
540+
int expectedRunspaceId,
541+
string? expectedRunspaceName)
542+
{
543+
string script = NewTestFile($"Start-DebugAttachSession {paramString}");
544+
545+
await client.LaunchScript(script);
546+
await client.RequestConfigurationDone(new ConfigurationDoneArguments());
547+
548+
StartDebuggingAttachRequestArguments attachRequest = await startDebuggingAttachRequest;
549+
Assert.Equal("attach", attachRequest.Request);
550+
Assert.Equal(expectedComputerName, attachRequest.Configuration.ComputerName);
551+
Assert.Equal(expectedPipeName, attachRequest.Configuration.CustomPipeName);
552+
Assert.Equal(expectedProcessId, attachRequest.Configuration.ProcessId);
553+
Assert.Equal(expectedRunspaceId, attachRequest.Configuration.RunspaceId);
554+
Assert.Equal(expectedRunspaceName, attachRequest.Configuration.RunspaceName);
555+
}
556+
557+
private record StartDebuggingAttachRequestArguments(PsesAttachRequestArguments Configuration, string Request);
558+
559+
#nullable disable
516560
}
517561
}

0 commit comments

Comments
 (0)