Skip to content

Commit

Permalink
Updated dependencies, switch the way debugger launching works
Browse files Browse the repository at this point in the history
  • Loading branch information
bradwilson committed Aug 13, 2024
1 parent 1d50be3 commit 41e8dc0
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 9 deletions.
4 changes: 2 additions & 2 deletions Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
<NSubstituteVersion>5.1.0</NSubstituteVersion>
<TunnelVisionLabsReferenceAssemblyAnnotatorVersion>1.0.0-alpha.160</TunnelVisionLabsReferenceAssemblyAnnotatorVersion>
<XunitAnalyzersVersion>1.16.0-pre.23</XunitAnalyzersVersion>
<XunitV2Version>2.9.1-pre.8</XunitV2Version>
<XunitV3Version>0.2.0-pre.87</XunitV3Version>
<XunitV2Version>2.9.1-pre.10</XunitV2Version>
<XunitV3Version>0.3.0-pre.5</XunitV3Version>
</PropertyGroup>

</Project>
21 changes: 21 additions & 0 deletions src/xunit.runner.visualstudio/Utility/DebuggerProcessLauncher.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter;
using Xunit.v3;

namespace Xunit.Runner.VisualStudio;

internal class DebuggerProcessLauncher(IFrameworkHandle2 frameworkHandle2) :
OutOfProcessTestProcessLauncherBase
{
protected override ITestProcess? StartTestProcess(
string executable,
string executableArguments,
string? responseFile)
{
var testProcess = LocalTestProcess.Start(executable, executableArguments, responseFile);
if (testProcess is null)
return null;

frameworkHandle2.AttachDebuggerToProcess(testProcess.ProcessID);
return testProcess;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,7 @@ public void LogWarning(
{
loggerHelper.LogWarning("{0}", message);
}

public void WaitForAcknowledgment()
{ }
}
16 changes: 9 additions & 7 deletions src/xunit.runner.visualstudio/VsTestRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using Xunit.Internal;
using Xunit.Runner.Common;
using Xunit.Sdk;
using Xunit.v3;

namespace Xunit.Runner.VisualStudio
{
Expand Down Expand Up @@ -504,8 +505,13 @@ async Task RunTestsInAssembly(
var diagnosticSink = new DiagnosticMessageSink(logger, assemblyDisplayName, runInfo.Assembly.Configuration.DiagnosticMessagesOrDefault, runInfo.Assembly.Configuration.InternalDiagnosticMessagesOrDefault);
var discoveryOptions = TestFrameworkOptions.ForDiscovery(runInfo.Assembly.Configuration);

var frameworkHandle2 = frameworkHandle as IFrameworkHandle2;
var testProcessLauncher = default(ITestProcessLauncher);
if (runContext.IsBeingDebugged && frameworkHandle2 is not null)
testProcessLauncher = new DebuggerProcessLauncher(frameworkHandle2);

await using var sourceInformationProvider = new VisualStudioSourceInformationProvider(assemblyFileName, diagnosticSink);
await using var controller = XunitFrontController.Create(runInfo.Assembly, sourceInformationProvider, diagnosticSink);
await using var controller = XunitFrontController.Create(runInfo.Assembly, sourceInformationProvider, diagnosticSink, testProcessLauncher);
if (controller is null)
return;

Expand Down Expand Up @@ -605,14 +611,10 @@ await DiscoverTestsInAssembly(
var resultsSink = new ExecutionSink(runInfo.Assembly, discoveryOptions, executionOptions, appDomainOption, shadowCopy, vsExecutionSink, executionSinkOptions);

var frontControllerSettings = new FrontControllerRunSettings(executionOptions, testCaseSerializations);
var frameworkHandle2 = frameworkHandle as IFrameworkHandle2;
if (runContext.IsBeingDebugged && frameworkHandle2 is not null)
if (testProcessLauncher is not null)
frontControllerSettings.LaunchOptions.WaitForDebugger = true;

var processId = controller.Run(resultsSink, frontControllerSettings);
if (processId.HasValue && frameworkHandle2 is not null)
frameworkHandle2.AttachDebuggerToProcess(processId.Value);

controller.Run(resultsSink, frontControllerSettings);
resultsSink.Finished.WaitOne();

if ((resultsSink.ExecutionSummary.Failed != 0 || resultsSink.ExecutionSummary.Errors != 0) && executionOptions.GetStopOnTestFailOrDefault())
Expand Down

0 comments on commit 41e8dc0

Please sign in to comment.