Skip to content

Commit aa2b193

Browse files
authored
Merge pull request #383 from daviwil/fix-382
Add SupportsVirtualTerminal property to ConsolePSHostUserInterface
2 parents ea66b59 + 7868fcb commit aa2b193

File tree

5 files changed

+71
-9
lines changed

5 files changed

+71
-9
lines changed

appveyor.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ environment:
1414

1515
install:
1616
- ps: |
17+
1718
Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force | Out-Null
19+
Import-PackageProvider NuGet -Force | Out-Null
20+
Set-PSRepository -Name PSGallery -InstallationPolicy Trusted | Out-Null
1821
Install-Module InvokeBuild -RequiredVersion 3.2.1 -Scope CurrentUser -Force | Out-Null
1922
2023
build_script:

src/PowerShellEditorServices/Session/SessionPSHostUserInterface.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ internal IConsoleHost ConsoleHost
4141
}
4242
}
4343

44+
#if !PowerShellv3 && !PowerShellv4 && !PowerShellv5r1 // Only available in Windows 10 Update 1 or higher
45+
public override bool SupportsVirtualTerminal => true;
46+
#endif
47+
4448
#endregion
4549

4650
#region Constructors
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//
2+
// Copyright (c) Microsoft. All rights reserved.
3+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
4+
//
5+
6+
using Xunit;
7+
8+
// Disable test parallelization to avoid port reuse issues
9+
[assembly: CollectionBehavior(DisableTestParallelization = true)]
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//
2+
// Copyright (c) Microsoft. All rights reserved.
3+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
4+
//
5+
6+
using Xunit;
7+
8+
// Disable test parallelization to avoid port reuse issues
9+
[assembly: CollectionBehavior(DisableTestParallelization = true)]

test/PowerShellEditorServices.Test/Debugging/DebugServiceTests.cs

Lines changed: 46 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,9 @@ await this.debugService.SetLineBreakpoints(
239239
BreakpointDetails.Create("", 10)
240240
});
241241

242-
Assert.Equal(2, breakpoints.Length);
242+
var confirmedBreakpoints = await this.GetConfirmedBreakpoints(this.debugScriptFile);
243+
244+
Assert.Equal(2, confirmedBreakpoints.Count());
243245
Assert.Equal(5, breakpoints[0].LineNumber);
244246
Assert.Equal(10, breakpoints[1].LineNumber);
245247

@@ -248,15 +250,20 @@ await this.debugService.SetLineBreakpoints(
248250
this.debugScriptFile,
249251
new[] { BreakpointDetails.Create("", 2) });
250252

251-
Assert.Equal(1, breakpoints.Length);
253+
confirmedBreakpoints = await this.GetConfirmedBreakpoints(this.debugScriptFile);
254+
255+
Assert.Equal(1, confirmedBreakpoints.Count());
252256
Assert.Equal(2, breakpoints[0].LineNumber);
253257

254-
breakpoints =
255-
await this.debugService.SetLineBreakpoints(
256-
this.debugScriptFile,
257-
new[] { BreakpointDetails.Create("", 0) });
258+
await this.debugService.SetLineBreakpoints(
259+
this.debugScriptFile,
260+
new[] { BreakpointDetails.Create("", 0) });
258261

259-
Assert.Equal(0, breakpoints.Length);
262+
var remainingBreakpoints = await this.GetConfirmedBreakpoints(this.debugScriptFile);
263+
264+
Assert.False(
265+
remainingBreakpoints.Any(),
266+
"Breakpoints in the script file were not cleared");
260267
}
261268

262269
[Fact]
@@ -458,15 +465,24 @@ await this.debugService.SetLineBreakpoints(
458465
[Fact]
459466
public async Task DebuggerBreaksWhenRequested()
460467
{
468+
var confirmedBreakpoints = await this.GetConfirmedBreakpoints(this.debugScriptFile);
469+
470+
await this.AssertStateChange(
471+
PowerShellContextState.Ready,
472+
PowerShellExecutionResult.Completed);
473+
474+
Assert.False(
475+
confirmedBreakpoints.Any(),
476+
"Unexpected breakpoint found in script file");
477+
461478
Task executeTask =
462479
this.powerShellContext.ExecuteScriptString(
463480
this.debugScriptFile.FilePath);
464481

465482
// Break execution and wait for the debugger to stop
466483
this.debugService.Break();
467484

468-
// File path is an empty string when paused while running
469-
await this.AssertDebuggerStopped(string.Empty);
485+
await this.AssertDebuggerPaused();
470486
await this.AssertStateChange(
471487
PowerShellContextState.Ready,
472488
PowerShellExecutionResult.Stopped);
@@ -885,6 +901,16 @@ await this.debugService.SetLineBreakpoints(
885901
this.powerShellContext.AbortExecution();
886902
}
887903

904+
public async Task AssertDebuggerPaused()
905+
{
906+
SynchronizationContext syncContext = SynchronizationContext.Current;
907+
908+
DebuggerStoppedEventArgs eventArgs =
909+
await this.debuggerStoppedQueue.DequeueAsync();
910+
911+
Assert.Equal(0, eventArgs.OriginalEvent.Breakpoints.Count);
912+
}
913+
888914
public async Task AssertDebuggerStopped(
889915
string scriptPath,
890916
int lineNumber = -1)
@@ -894,6 +920,8 @@ public async Task AssertDebuggerStopped(
894920
DebuggerStoppedEventArgs eventArgs =
895921
await this.debuggerStoppedQueue.DequeueAsync();
896922

923+
924+
897925
Assert.Equal(scriptPath, eventArgs.ScriptPath);
898926
if (lineNumber > -1)
899927
{
@@ -911,6 +939,15 @@ private async Task AssertStateChange(
911939
Assert.Equal(expectedState, newState.NewSessionState);
912940
Assert.Equal(expectedResult, newState.ExecutionResult);
913941
}
942+
943+
private async Task<IEnumerable<LineBreakpoint>> GetConfirmedBreakpoints(ScriptFile scriptFile)
944+
{
945+
return
946+
await this.powerShellContext.ExecuteCommand<LineBreakpoint>(
947+
new PSCommand()
948+
.AddCommand("Get-PSBreakpoint")
949+
.AddParameter("Script", scriptFile.FilePath));
950+
}
914951
}
915952
}
916953

0 commit comments

Comments
 (0)