From 41e8dc0d4e6eb6c46d832f4314c3ff34395512dd Mon Sep 17 00:00:00 2001 From: Brad Wilson Date: Tue, 13 Aug 2024 13:09:02 -0700 Subject: [PATCH] Updated dependencies, switch the way debugger launching works --- Versions.props | 4 ++-- .../Utility/DebuggerProcessLauncher.cs | 21 +++++++++++++++++++ .../Utility/VisualStudioRunnerLogger.cs | 3 +++ src/xunit.runner.visualstudio/VsTestRunner.cs | 16 +++++++------- 4 files changed, 35 insertions(+), 9 deletions(-) create mode 100644 src/xunit.runner.visualstudio/Utility/DebuggerProcessLauncher.cs diff --git a/Versions.props b/Versions.props index abb4eb5..ff35e23 100644 --- a/Versions.props +++ b/Versions.props @@ -11,8 +11,8 @@ 5.1.0 1.0.0-alpha.160 1.16.0-pre.23 - 2.9.1-pre.8 - 0.2.0-pre.87 + 2.9.1-pre.10 + 0.3.0-pre.5 diff --git a/src/xunit.runner.visualstudio/Utility/DebuggerProcessLauncher.cs b/src/xunit.runner.visualstudio/Utility/DebuggerProcessLauncher.cs new file mode 100644 index 0000000..b2eeda4 --- /dev/null +++ b/src/xunit.runner.visualstudio/Utility/DebuggerProcessLauncher.cs @@ -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; + } +} diff --git a/src/xunit.runner.visualstudio/Utility/VisualStudioRunnerLogger.cs b/src/xunit.runner.visualstudio/Utility/VisualStudioRunnerLogger.cs index e242719..a041494 100644 --- a/src/xunit.runner.visualstudio/Utility/VisualStudioRunnerLogger.cs +++ b/src/xunit.runner.visualstudio/Utility/VisualStudioRunnerLogger.cs @@ -41,4 +41,7 @@ public void LogWarning( { loggerHelper.LogWarning("{0}", message); } + + public void WaitForAcknowledgment() + { } } diff --git a/src/xunit.runner.visualstudio/VsTestRunner.cs b/src/xunit.runner.visualstudio/VsTestRunner.cs index 0520b58..5816a62 100644 --- a/src/xunit.runner.visualstudio/VsTestRunner.cs +++ b/src/xunit.runner.visualstudio/VsTestRunner.cs @@ -13,6 +13,7 @@ using Xunit.Internal; using Xunit.Runner.Common; using Xunit.Sdk; +using Xunit.v3; namespace Xunit.Runner.VisualStudio { @@ -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; @@ -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())