|
10 | 10 | using System.Threading;
|
11 | 11 | using System.Threading.Tasks;
|
12 | 12 | using Microsoft.Extensions.Logging.Abstractions;
|
| 13 | +using Microsoft.PowerShell.EditorServices.Handlers; |
13 | 14 | using Microsoft.PowerShell.EditorServices.Services;
|
14 | 15 | using Microsoft.PowerShell.EditorServices.Services.DebugAdapter;
|
15 | 16 | using Microsoft.PowerShell.EditorServices.Services.PowerShell.Host;
|
@@ -521,6 +522,40 @@ await debugService.SetCommandBreakpointsAsync(
|
521 | 522 | Assert.Equal("\"True > \"", prompt.ValueString);
|
522 | 523 | }
|
523 | 524 |
|
| 525 | + [SkippableFact] |
| 526 | + public async Task DebuggerBreaksInUntitledScript() |
| 527 | + { |
| 528 | + Skip.IfNot(VersionUtils.PSEdition == "Core", "Untitled script breakpoints only supported in PowerShell Core"); |
| 529 | + const string contents = "Write-Output $($MyInvocation.Line)"; |
| 530 | + const string scriptPath = "untitled:Untitled-1"; |
| 531 | + Assert.True(ScriptFile.IsUntitledPath(scriptPath)); |
| 532 | + ScriptFile scriptFile = workspace.GetFileBuffer(scriptPath, contents); |
| 533 | + Assert.Equal(scriptFile.DocumentUri, scriptPath); |
| 534 | + Assert.Equal(scriptFile.Contents, contents); |
| 535 | + Assert.True(workspace.TryGetFile(scriptPath, out ScriptFile _)); |
| 536 | + |
| 537 | + await debugService.SetCommandBreakpointsAsync( |
| 538 | + new[] { CommandBreakpointDetails.Create("Write-Output") }).ConfigureAwait(true); |
| 539 | + |
| 540 | + ConfigurationDoneHandler configurationDoneHandler = new( |
| 541 | + NullLoggerFactory.Instance, null, debugService, null, null, psesHost, workspace, null, psesHost); |
| 542 | + |
| 543 | + Task _ = configurationDoneHandler.LaunchScriptAsync(scriptPath); |
| 544 | + AssertDebuggerStopped(scriptPath, 1); |
| 545 | + |
| 546 | + VariableDetailsBase[] variables = GetVariables(VariableContainerDetails.CommandVariablesName); |
| 547 | + VariableDetailsBase myInvocation = Array.Find(variables, v => v.Name == "$MyInvocation"); |
| 548 | + Assert.NotNull(myInvocation); |
| 549 | + Assert.True(myInvocation.IsExpandable); |
| 550 | + |
| 551 | + // Here we're asserting that our hacky workaround to support breakpoints in untitled |
| 552 | + // scripts is working, namely that we're actually dot-sourcing our first argument, which |
| 553 | + // should be a cached script block. See the `LaunchScriptAsync` for more info. |
| 554 | + VariableDetailsBase[] myInvocationChildren = debugService.GetVariables(myInvocation.Id); |
| 555 | + VariableDetailsBase myInvocationLine = Array.Find(myInvocationChildren, v => v.Name == "Line"); |
| 556 | + Assert.Equal("\". $args[0]\"", myInvocationLine.ValueString); |
| 557 | + } |
| 558 | + |
524 | 559 | [Fact]
|
525 | 560 | public async Task DebuggerVariableStringDisplaysCorrectly()
|
526 | 561 | {
|
|
0 commit comments