Skip to content

Commit

Permalink
Latest dependencies (and code cleanup)
Browse files Browse the repository at this point in the history
  • Loading branch information
bradwilson committed Jul 24, 2024
1 parent 0978d60 commit 2b3d2ce
Show file tree
Hide file tree
Showing 12 changed files with 177 additions and 181 deletions.
1 change: 1 addition & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ dotnet_naming_style.begins_with_i.capitalization = pascal_case

#### Roslyn diagnostics ####

dotnet_diagnostic.CA1845.severity = none # Use span-based 'string.Concat'
dotnet_diagnostic.CA1851.severity = warning
dotnet_diagnostic.IDE0057.severity = none
dotnet_diagnostic.IDE1006.severity = none
6 changes: 3 additions & 3 deletions Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
<NerdbankGitVersioningVersion>3.6.133</NerdbankGitVersioningVersion>
<NSubstituteVersion>5.1.0</NSubstituteVersion>
<TunnelVisionLabsReferenceAssemblyAnnotatorVersion>1.0.0-alpha.160</TunnelVisionLabsReferenceAssemblyAnnotatorVersion>
<XunitAnalyzersVersion>1.16.0-pre.2</XunitAnalyzersVersion>
<XunitV2Version>2.9.1-pre.5</XunitV2Version>
<XunitV3Version>0.2.0-pre.25</XunitV3Version>
<XunitAnalyzersVersion>1.16.0-pre.20</XunitAnalyzersVersion>
<XunitV2Version>2.9.1-pre.8</XunitV2Version>
<XunitV3Version>0.2.0-pre.47</XunitV3Version>
</PropertyGroup>

</Project>
37 changes: 18 additions & 19 deletions src/xunit.runner.visualstudio/Sinks/VsDiscoverySink.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
using System.Security.Cryptography;
using System.Text;
using System.Threading;
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter;
using Xunit.Runner.Common;
using Xunit.Sdk;
using VsTestCase = Microsoft.VisualStudio.TestPlatform.ObjectModel.TestCase;
using VsTestCaseDiscoverySink = Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter.ITestCaseDiscoverySink;

#if NETCOREAPP
using System.Reflection;
Expand All @@ -21,24 +21,23 @@ public sealed class VsDiscoverySink : IVsDiscoverySink, IDisposable
const int MaximumDisplayNameLength = 447;
const int TestCaseBatchSize = 100;

static readonly Action<TestCase, string, string>? addTraitThunk = GetAddTraitThunk();
static readonly Action<VsTestCase, string, string>? addTraitThunk = GetAddTraitThunk();
static readonly Uri uri = new(Constants.ExecutorUri);

readonly Func<bool> cancelThunk;
readonly ITestFrameworkDiscoveryOptions discoveryOptions;
readonly ITestCaseDiscoverySink discoverySink;
readonly VsTestCaseDiscoverySink discoverySink;
readonly DiscoveryEventSink discoveryEventSink = new();
readonly LoggerHelper logger;
readonly string source;
readonly List<TestCaseDiscovered> testCaseBatch = [];
readonly List<ITestCaseDiscovered> testCaseBatch = [];
readonly TestPlatformContext testPlatformContext;
readonly TestCaseFilter testCaseFilter;

public VsDiscoverySink(
string source,
IFrontControllerDiscoverer discoverer,
LoggerHelper logger,
ITestCaseDiscoverySink discoverySink,
VsTestCaseDiscoverySink discoverySink,
ITestFrameworkDiscoveryOptions discoveryOptions,
TestPlatformContext testPlatformContext,
TestCaseFilter testCaseFilter,
Expand All @@ -63,9 +62,9 @@ public VsDiscoverySink(
public void Dispose() =>
Finished.Dispose();

public static TestCase? CreateVsTestCase(
public static VsTestCase? CreateVsTestCase(
string source,
TestCaseDiscovered testCase,
ITestCaseDiscovered testCase,
LoggerHelper logger,
TestPlatformContext testPlatformContext)
{
Expand All @@ -78,7 +77,7 @@ public void Dispose() =>
try
{
var fqTestMethodName = $"{testCase.TestClassName}.{testCase.TestMethodName}";
var result = new TestCase(fqTestMethodName, uri, source) { DisplayName = Escape(testCase.TestCaseDisplayName) };
var result = new VsTestCase(fqTestMethodName, uri, source) { DisplayName = Escape(testCase.TestCaseDisplayName) };
result.SetPropertyValue(VsTestRunner.TestCaseUniqueIDProperty, testCase.TestCaseUniqueID);

if (testPlatformContext.DesignMode)
Expand Down Expand Up @@ -128,11 +127,11 @@ public int Finish()
return TotalTests;
}

static Action<TestCase, string, string>? GetAddTraitThunk()
static Action<VsTestCase, string, string>? GetAddTraitThunk()
{
try
{
var testCaseType = typeof(TestCase);
var testCaseType = typeof(VsTestCase);
var stringType = typeof(string);

#if NETCOREAPP
Expand All @@ -144,9 +143,9 @@ public int Finish()
return null;

#if NETCOREAPP
var method = property.PropertyType.GetRuntimeMethod("Add", new[] { typeof(string), typeof(string) });
var method = property.PropertyType.GetRuntimeMethod("Add", [typeof(string), typeof(string)]);
#else
var method = property.PropertyType.GetMethod("Add", new[] { typeof(string), typeof(string) });
var method = property.PropertyType.GetMethod("Add", [typeof(string), typeof(string)]);
#endif
if (method is null)
return null;
Expand All @@ -155,9 +154,9 @@ public int Finish()
var nameParam = Expression.Parameter(stringType, "name");
var valueParam = Expression.Parameter(stringType, "value");
var instance = Expression.Property(thisParam, property);
var body = Expression.Call(instance, method, new[] { nameParam, valueParam });
var body = Expression.Call(instance, method, [nameParam, valueParam]);

return Expression.Lambda<Action<TestCase, string, string>>(body, thisParam, nameParam, valueParam).Compile();
return Expression.Lambda<Action<VsTestCase, string, string>>(body, thisParam, nameParam, valueParam).Compile();
}
catch (Exception)
{
Expand All @@ -171,7 +170,7 @@ void HandleCancellation(MessageHandlerArgs args)
args.Stop();
}

void HandleTestCaseDiscoveredMessage(MessageHandlerArgs<TestCaseDiscovered> args)
void HandleTestCaseDiscoveredMessage(MessageHandlerArgs<ITestCaseDiscovered> args)
{
testCaseBatch.Add(args.Message);
TotalTests++;
Expand All @@ -182,7 +181,7 @@ void HandleTestCaseDiscoveredMessage(MessageHandlerArgs<TestCaseDiscovered> args
HandleCancellation(args);
}

void HandleDiscoveryCompleteMessage(MessageHandlerArgs<DiscoveryComplete> args)
void HandleDiscoveryCompleteMessage(MessageHandlerArgs<IDiscoveryComplete> args)
{
try
{
Expand All @@ -198,7 +197,7 @@ void HandleDiscoveryCompleteMessage(MessageHandlerArgs<DiscoveryComplete> args)
HandleCancellation(args);
}

bool IMessageSink.OnMessage(MessageSinkMessage message) =>
bool IMessageSink.OnMessage(IMessageSinkMessage message) =>
discoveryEventSink.OnMessage(message);

private void SendExistingTestCases()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,9 @@ namespace Xunit.Runner.VisualStudio;
/// <summary>
/// Used to discover tests before running when VS says "run everything in the assembly".
/// </summary>
internal class VsExecutionDiscoverySink : TestDiscoverySink, IVsDiscoverySink
internal class VsExecutionDiscoverySink(Func<bool> cancelThunk) :
TestDiscoverySink(cancelThunk), IVsDiscoverySink
{
public VsExecutionDiscoverySink(Func<bool> cancelThunk) :
base(cancelThunk)
{ }

public int Finish()
{
Finished.WaitOne();
Expand Down
Loading

0 comments on commit 2b3d2ce

Please sign in to comment.