|
7 | 7 | using System.Runtime.InteropServices;
|
8 | 8 | using System.Text;
|
9 | 9 | using System.Threading.Tasks;
|
| 10 | +using Microsoft.PowerShell.EditorServices.Handlers; |
10 | 11 | using Nerdbank.Streams;
|
11 | 12 | using OmniSharp.Extensions.DebugAdapter.Client;
|
12 | 13 | using OmniSharp.Extensions.DebugAdapter.Protocol.Client;
|
@@ -53,6 +54,12 @@ public class DebugAdapterProtocolMessageTests(ITestOutputHelper output) : IAsync
|
53 | 54 | /// </summary>
|
54 | 55 | private Task<StoppedEvent> nextStopped => nextStoppedTcs.Task;
|
55 | 56 |
|
| 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 | + |
56 | 63 | public async Task InitializeAsync()
|
57 | 64 | {
|
58 | 65 | // Cleanup testScriptLogPath if it exists due to an interrupted previous run
|
@@ -100,6 +107,11 @@ send until a launch is sent.
|
100 | 107 | nextStoppedTcs.SetResult(e);
|
101 | 108 | nextStoppedTcs = new();
|
102 | 109 | })
|
| 110 | + .OnRequest("startDebugging", (StartDebuggingAttachRequestArguments request) => |
| 111 | + { |
| 112 | + startDebuggingAttachRequestTcs.SetResult(request); |
| 113 | + return Task.CompletedTask; |
| 114 | + }) |
103 | 115 | ;
|
104 | 116 | });
|
105 | 117 |
|
@@ -513,5 +525,37 @@ public async Task CanRunPesterTestFile()
|
513 | 525 | await client.RequestConfigurationDone(new ConfigurationDoneArguments());
|
514 | 526 | Assert.Equal("pester", await ReadScriptLogLineAsync());
|
515 | 527 | }
|
| 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 |
516 | 560 | }
|
517 | 561 | }
|
0 commit comments