22// Licensed under the MIT License.
33
44using System ;
5+ using System . Diagnostics ;
56using System . IO ;
67using System . Linq ;
78using System . Runtime . InteropServices ;
1112using Microsoft . Extensions . Logging ;
1213using Microsoft . Extensions . Logging . Debug ;
1314using OmniSharp . Extensions . DebugAdapter . Client ;
15+ using DapStackFrame = OmniSharp . Extensions . DebugAdapter . Protocol . Models . StackFrame ;
1416using OmniSharp . Extensions . DebugAdapter . Protocol . Events ;
1517using OmniSharp . Extensions . DebugAdapter . Protocol . Models ;
1618using OmniSharp . Extensions . DebugAdapter . Protocol . Requests ;
2022
2123namespace PowerShellEditorServices . Test . E2E
2224{
25+ public class XunitOutputTraceListener ( ITestOutputHelper output ) : TraceListener
26+ {
27+ public override void Write ( string message ) => output . WriteLine ( message ) ;
28+ public override void WriteLine ( string message ) => output . WriteLine ( message ) ;
29+ }
30+
2331 [ Trait ( "Category" , "DAP" ) ]
2432 public class DebugAdapterProtocolMessageTests : IAsyncLifetime , IDisposable
2533 {
@@ -38,13 +46,20 @@ public class DebugAdapterProtocolMessageTests : IAsyncLifetime, IDisposable
3846 /// Completes when the first breakpoint is reached.
3947 /// </summary>
4048 public TaskCompletionSource < StoppedEvent > Stopped { get ; } = new TaskCompletionSource < StoppedEvent > ( ) ;
49+
50+ /// <summary>
51+ /// Constructor. The ITestOutputHelper is injected by xUnit and used to write diagnostic logs.
52+ /// </summary>
53+ /// <param name="output"></param>
4154 public DebugAdapterProtocolMessageTests ( ITestOutputHelper output ) => _output = output ;
4255
4356 public async Task InitializeAsync ( )
4457 {
4558 LoggerFactory debugLoggerFactory = new ( ) ;
4659 debugLoggerFactory . AddProvider ( new DebugLoggerProvider ( ) ) ;
4760
61+ // NOTE: To see debug logger output, add this line to your test
62+
4863 _psesProcess = new PsesStdioProcess ( debugLoggerFactory , true ) ;
4964 await _psesProcess . Start ( ) ;
5065
@@ -308,7 +323,7 @@ await Assert.ThrowsAsync<JsonRpcException>(() => PsesDebugAdapterClient.RequestS
308323 }
309324
310325 [ SkippableFact ]
311- public async Task SendsInitialLabelBreakpointForPerformanceReasons ( )
326+ public async Task SendsInitialLabelBreakpointForPerformanceReasons ( ITestOutputHelper output )
312327 {
313328 Skip . If ( PsesStdioProcess . RunningInConstrainedLanguageMode ,
314329 "Breakpoints can't be set in Constrained Language Mode." ) ;
@@ -318,6 +333,9 @@ public async Task SendsInitialLabelBreakpointForPerformanceReasons()
318333 "after breakpoint"
319334 ) ) ;
320335
336+ // Enables DAP messages to be written to the test output
337+ Trace . Listeners . Add ( new XunitOutputTraceListener ( _output ) ) ;
338+
321339 //TODO: This is technically wrong per the spec, configDone should be completed BEFORE launching, but this is how the vscode client does it today and we really need to fix that.
322340 await PsesDebugAdapterClient . LaunchScript ( filePath , Started ) ;
323341
@@ -348,7 +366,7 @@ public async Task SendsInitialLabelBreakpointForPerformanceReasons()
348366 StackTraceResponse stackTraceResponse = await PsesDebugAdapterClient . RequestStackTrace (
349367 new StackTraceArguments { ThreadId = 1 }
350368 ) ;
351- StackFrame firstFrame = stackTraceResponse . StackFrames . First ( ) ;
369+ DapStackFrame firstFrame = stackTraceResponse . StackFrames . First ( ) ;
352370 Assert . Equal (
353371 firstFrame . PresentationHint ,
354372 StackFramePresentationHint . Label
0 commit comments