Skip to content

Commit

Permalink
Attempt to fix as much of xunit/xunit#3023 as possible (generics acro…
Browse files Browse the repository at this point in the history
…ss projects remain broken for source lookup)
  • Loading branch information
bradwilson committed Sep 25, 2024
1 parent e828f60 commit dd3ab46
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 333 deletions.
16 changes: 16 additions & 0 deletions src/xunit.runner.visualstudio/Sinks/VsDiscoverySink.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Linq.Expressions;
using System.Security.Cryptography;
using System.Text;
Expand Down Expand Up @@ -78,8 +80,22 @@ public void Dispose() =>
{
var fqTestMethodName = $"{testCase.TestClassName}.{testCase.TestMethodName}";
var result = new VsTestCase(fqTestMethodName, uri, source) { DisplayName = Escape(testCase.TestCaseDisplayName) };

// TODO: Waiting for feedback from https://github.com/xunit/xunit/issues/3023 to understand how this actually supposed
// to be done. Right now it appears that:
// (a) method lookups across projects absolutely requires parameter types
// (b) method lookups in the same project do not require parameter types
// (c) generic parameter types break lookup in both cases
// which leads us to the convoluted logic here, which is that we'll add parameter types unless they contain generics, in
// the hopes that that gives us the best possible coverage.
var managedMethodName = testCase.TestMethodName;
if (testCase.TestMethodParameterTypes is not null && testCase.TestMethodParameterTypes.Length > 0 && !testCase.TestMethodParameterTypes.Any(t => t.Contains('`')))
managedMethodName = string.Format(CultureInfo.InvariantCulture, "{0}({1})", managedMethodName, string.Join(",", testCase.TestMethodParameterTypes));

result.SetPropertyValue(VsTestRunner.TestCaseUniqueIDProperty, testCase.TestCaseUniqueID);
result.SetPropertyValue(VsTestRunner.TestCaseExplicitProperty, testCase.Explicit);
result.SetPropertyValue(VsTestRunner.ManagedTypeProperty, testCase.TestClassName);
result.SetPropertyValue(VsTestRunner.ManagedMethodProperty, managedMethodName);

if (testPlatformContext.DesignMode)
result.SetPropertyValue(VsTestRunner.TestCaseSerializationProperty, testCase.Serialization);
Expand Down
73 changes: 0 additions & 73 deletions src/xunit.runner.visualstudio/Utility/AppDomainManager.cs

This file was deleted.

This file was deleted.

81 changes: 0 additions & 81 deletions src/xunit.runner.visualstudio/Utility/DiaSessionWrapper.cs

This file was deleted.

119 changes: 0 additions & 119 deletions src/xunit.runner.visualstudio/Utility/DiaSessionWrapperHelper.cs

This file was deleted.

This file was deleted.

12 changes: 8 additions & 4 deletions src/xunit.runner.visualstudio/VsTestRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,12 @@ public class VsTestRunner : ITestDiscoverer, ITestExecutor
"xunit.v3.runner.utility.netstandard20.dll",
};

public static TestProperty ManagedMethodProperty { get; } =
TestProperty.Register("TestCase.ManagedMethod", "ManagedMethod", string.Empty, string.Empty, typeof(string), x => !string.IsNullOrWhiteSpace(x as string), TestPropertyAttributes.Hidden, typeof(TestCase));

public static TestProperty ManagedTypeProperty { get; } =
TestProperty.Register("TestCase.ManagedType", "ManagedType", string.Empty, string.Empty, typeof(string), x => !string.IsNullOrWhiteSpace(x as string), TestPropertyAttributes.Hidden, typeof(TestCase));

public static TestProperty TestCaseExplicitProperty { get; } =
TestProperty.Register("XunitTestCaseExplicit", "xUnit.net Test Case Explicit Flag", typeof(bool), typeof(VsTestRunner));

Expand Down Expand Up @@ -208,8 +214,7 @@ async Task DiscoverTests<TVisitor>(
var assemblyDisplayName = Path.GetFileNameWithoutExtension(assembly.AssemblyFileName);
var diagnosticMessageSink = new DiagnosticMessageSink(logger, assemblyDisplayName, assembly.Configuration.DiagnosticMessagesOrDefault, assembly.Configuration.InternalDiagnosticMessagesOrDefault);

await using var sourceInformationProvider = new VisualStudioSourceInformationProvider(assembly.AssemblyFileName, diagnosticMessageSink);
await using var controller = XunitFrontController.Create(assembly, sourceInformationProvider, diagnosticMessageSink);
await using var controller = XunitFrontController.Create(assembly, null, diagnosticMessageSink);
if (controller is null)
return;

Expand Down Expand Up @@ -511,8 +516,7 @@ async Task RunTestsInAssembly(
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, testProcessLauncher);
await using var controller = XunitFrontController.Create(runInfo.Assembly, null, diagnosticSink, testProcessLauncher);
if (controller is null)
return;

Expand Down
Loading

0 comments on commit dd3ab46

Please sign in to comment.