Skip to content

Commit

Permalink
#415: VS Code debug broken
Browse files Browse the repository at this point in the history
  • Loading branch information
bradwilson committed Sep 4, 2024
1 parent 879b81d commit 124b22a
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/xunit.runner.visualstudio/Utility/DebuggerProcessLauncher.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using System.IO;
using System.Linq;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter;
using Xunit.v3;

Expand All @@ -15,7 +17,25 @@ internal class DebuggerProcessLauncher(IFrameworkHandle2 frameworkHandle2) :
if (testProcess is null)
return null;

frameworkHandle2.AttachDebuggerToProcess(testProcess.ProcessID);
var waitForDebugger = false;

if (responseFile is not null)
{
try
{
var switches = File.ReadAllLines(responseFile);
waitForDebugger = switches.Any(s => s.Equals("-waitForDebugger", System.StringComparison.OrdinalIgnoreCase));
}
catch { }
}

if (waitForDebugger)
try
{
frameworkHandle2.AttachDebuggerToProcess(testProcess.ProcessID);
}
catch { }

return testProcess;
}
}

3 comments on commit 124b22a

@careri
Copy link

@careri careri commented on 124b22a Sep 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How did this change solve my problem? You're just awaiting the debugger. Still calling the same code if waitForDebugger is true. Which I guess it is in my case?
#415

frameworkHandle2.AttachDebuggerToProcess(testProcess.ProcessID);

@bradwilson
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not every invocation of DebuggerProcessLauncher needs to wait for the debugger (in particular, we call into the test process with -assemblyInfo just to get the metadata about the test assembly). A change we made in 0.3.0 shifted around these calls such that the new launcher is seeing all invocations, not just ones that should wait for the debugger. So we need to inspect the switches that are being passed to only try to debug attach when we see -waitForDebugger.

@careri
Copy link

@careri careri commented on 124b22a Sep 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, that explains things. Thanks

Please sign in to comment.