Skip to content

Commit f742b3d

Browse files
committed
Add TraceWriter Stuff
1 parent a2eda58 commit f742b3d

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

test/PowerShellEditorServices.Test.E2E/DebugAdapterProtocolMessageTests.cs

+20-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the MIT License.
33

44
using System;
5+
using System.Diagnostics;
56
using System.IO;
67
using System.Linq;
78
using System.Runtime.InteropServices;
@@ -11,6 +12,7 @@
1112
using Microsoft.Extensions.Logging;
1213
using Microsoft.Extensions.Logging.Debug;
1314
using OmniSharp.Extensions.DebugAdapter.Client;
15+
using DapStackFrame = OmniSharp.Extensions.DebugAdapter.Protocol.Models.StackFrame;
1416
using OmniSharp.Extensions.DebugAdapter.Protocol.Events;
1517
using OmniSharp.Extensions.DebugAdapter.Protocol.Models;
1618
using OmniSharp.Extensions.DebugAdapter.Protocol.Requests;
@@ -20,6 +22,12 @@
2022

2123
namespace 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

Comments
 (0)