Skip to content

Commit

Permalink
Experiment: replace Microsoft.TestPlatform.ObjectModel NUGet referenc…
Browse files Browse the repository at this point in the history
…e with AssemblyHelper for one of its types
  • Loading branch information
bradwilson committed Oct 15, 2023
1 parent 174f994 commit 36a4029
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
27 changes: 16 additions & 11 deletions src/xunit.runner.visualstudio/VsTestRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Threading;
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Host;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;
using Xunit.Abstractions;
using Xunit.Internal;
Expand Down Expand Up @@ -228,8 +229,11 @@ void DiscoverTests<TVisitor>(
RemotingUtility.CleanUpRegisteredChannels();

var internalDiagnosticsMessageSink = DiagnosticMessageSink.ForInternalDiagnostics(logger, runSettings.InternalDiagnosticMessages ?? false);
var wrappedInternalDiagnosticsMessageSink = MessageSinkAdapter.Wrap(internalDiagnosticsMessageSink);

using var _1 = AssemblyHelper.SubscribeResolveForAssembly(typeof(VsTestRunner), wrappedInternalDiagnosticsMessageSink);
using var _2 = AssemblyHelper.SubscribeResolveForAssembly(typeof(ITestRuntimeProvider), wrappedInternalDiagnosticsMessageSink);

using var _ = AssemblyHelper.SubscribeResolveForAssembly(typeof(VsTestRunner), MessageSinkAdapter.Wrap(internalDiagnosticsMessageSink));
foreach (var assemblyFileNameCanBeWithoutAbsolutePath in sources)
{
var assembly = new XunitProjectAssembly { AssemblyFilename = GetAssemblyFileName(assemblyFileNameCanBeWithoutAbsolutePath) };
Expand Down Expand Up @@ -385,17 +389,18 @@ void RunTests(
var reporter = GetRunnerReporter(logger, runSettings, runInfos.Select(ari => ari.Assembly.AssemblyFilename).ToList());
using var reporterMessageHandler = MessageSinkWithTypesAdapter.Wrap(reporter.CreateMessageHandler(new VisualStudioRunnerLogger(logger)));
using var internalDiagnosticsMessageSink = DiagnosticMessageSink.ForInternalDiagnostics(logger, runSettings.InternalDiagnosticMessages ?? false);
var wrappedInternalDiagnosticsMessageSink = MessageSinkAdapter.Wrap(internalDiagnosticsMessageSink);

using (AssemblyHelper.SubscribeResolveForAssembly(typeof(VsTestRunner), MessageSinkAdapter.Wrap(internalDiagnosticsMessageSink)))
{
if (parallelizeAssemblies)
runInfos
.Select(runInfo => RunTestsInAssemblyAsync(runContext, frameworkHandle, logger, testPlatformContext, runSettings, reporterMessageHandler, runInfo))
.ToList()
.ForEach(@event => @event.WaitOne());
else
runInfos.ForEach(runInfo => RunTestsInAssembly(runContext, frameworkHandle, logger, testPlatformContext, runSettings, reporterMessageHandler, runInfo));
}
using var _1 = AssemblyHelper.SubscribeResolveForAssembly(typeof(VsTestRunner), wrappedInternalDiagnosticsMessageSink);
using var _2 = AssemblyHelper.SubscribeResolveForAssembly(typeof(ITestRuntimeProvider), wrappedInternalDiagnosticsMessageSink);

if (parallelizeAssemblies)
runInfos
.Select(runInfo => RunTestsInAssemblyAsync(runContext, frameworkHandle, logger, testPlatformContext, runSettings, reporterMessageHandler, runInfo))
.ToList()
.ForEach(@event => @event.WaitOne());
else
runInfos.ForEach(runInfo => RunTestsInAssembly(runContext, frameworkHandle, logger, testPlatformContext, runSettings, reporterMessageHandler, runInfo));
}
catch (Exception ex)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@
<repository type="git" url="https://github.com/xunit/visualstudio.xunit" commit="$GitCommitId$" />
<developmentDependency>true</developmentDependency>
<dependencies>
<group targetFramework="net462">
<dependency id="Microsoft.TestPlatform.ObjectModel" version="$MicrosoftTestPlatformObjectModelVersion$" />
</group>
<group targetFramework="net462" />
<group targetFramework="net6.0" />
</dependencies>
<frameworkAssemblies>
Expand Down

0 comments on commit 36a4029

Please sign in to comment.