Skip to content

Commit

Permalink
Update for v3 0.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
bradwilson committed Jul 6, 2024
1 parent 50dec19 commit fec8d66
Show file tree
Hide file tree
Showing 28 changed files with 527 additions and 177 deletions.
1 change: 1 addition & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ dotnet_diagnostic.CA1000.severity = none # Do not declare static members on ge
dotnet_diagnostic.CA1002.severity = none # Do not expose generic lists
dotnet_diagnostic.CA1014.severity = none # Mark assemblies with CLSCompliantAttribute
dotnet_diagnostic.CA1034.severity = none # Do not nest types
dotnet_diagnostic.CA1050.severity = none # Declare types in namespaces
dotnet_diagnostic.CA1303.severity = none # Do not pass literals as localized parameters
dotnet_diagnostic.CA1707.severity = none # Remove the underscores from type name
dotnet_diagnostic.CA1720.severity = none # Identifier contains type name
Expand Down
6 changes: 3 additions & 3 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="NSubstitute" Version="5.1.0" />
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
<PackageReference Include="xunit.assert.source" Version="2.8.2-pre.9" />
<PackageReference Include="xunit.core" Version="2.8.2-pre.9" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2-pre.5" />
<PackageReference Include="xunit.assert.source" Version="2.8.2-pre.19" />
<PackageReference Include="xunit.core" Version="2.8.2-pre.19" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2-pre.7" />
</ItemGroup>

</When>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Composition;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis;
Expand Down Expand Up @@ -29,6 +30,13 @@ public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context)
if (methodDeclaration is null)
return;

var diagnostic = context.Diagnostics.FirstOrDefault();
if (diagnostic is null)
return;

if (!diagnostic.Properties.TryGetValue(Constants.Properties.DataAttributeTypeName, out var dataAttributeTypeName) || dataAttributeTypeName is null)
return;

context.RegisterCodeFix(
CodeAction.Create(
"Mark as [Theory]",
Expand All @@ -44,7 +52,7 @@ public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context)
Key_RemoveDataAttributes,
context.Document,
methodDeclaration.AttributeLists,
Constants.Types.Xunit.Sdk.DataAttribute
dataAttributeTypeName
),
context.Diagnostics
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Composition;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CodeFixes;
Expand All @@ -25,13 +26,20 @@ public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context)
if (methodDeclaration is null)
return;

var diagnostic = context.Diagnostics.FirstOrDefault();
if (diagnostic is null)
return;

if (!diagnostic.Properties.TryGetValue(Constants.Properties.DataAttributeTypeName, out var dataAttributeTypeName) || dataAttributeTypeName is null)
return;

context.RegisterCodeFix(
new RemoveAttributesOfTypeCodeAction(
"Remove data attributes",
Key_RemoveDataAttributes,
context.Document,
methodDeclaration.AttributeLists,
Constants.Types.Xunit.Sdk.DataAttribute
dataAttributeTypeName
),
context.Diagnostics
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public async Task V3SupportedTypes(string attribute)
using Xunit.v3;
{attribute} public class TestClass {{
public TestClass(_ITestOutputHelper _1, ITestContextAccessor _2) {{ }}
public TestClass(ITestOutputHelper _1, ITestContextAccessor _2) {{ }}
[Fact] public void TestMethod() {{ }}
}}";
Expand Down
16 changes: 8 additions & 8 deletions src/xunit.analyzers.tests/Utility/CodeAnalyzerHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ static CodeAnalyzerHelper()
new PackageIdentity("System.Collections.Immutable", "1.6.0"),
new PackageIdentity("System.Threading.Tasks.Extensions", "4.5.4"),
new PackageIdentity("xunit.abstractions", "2.0.3"),
new PackageIdentity("xunit.assert", "2.8.2-pre.9"),
new PackageIdentity("xunit.core", "2.8.2-pre.9")
new PackageIdentity("xunit.assert", "2.8.2-pre.19"),
new PackageIdentity("xunit.core", "2.8.2-pre.19")
)
);

Expand All @@ -51,7 +51,7 @@ static CodeAnalyzerHelper()
new PackageIdentity("System.Collections.Immutable", "1.6.0"),
new PackageIdentity("System.Threading.Tasks.Extensions", "4.5.4"),
new PackageIdentity("xunit.abstractions", "2.0.3"),
new PackageIdentity("xunit.runner.utility", "2.8.2-pre.9")
new PackageIdentity("xunit.runner.utility", "2.8.2-pre.19")
)
);

Expand All @@ -61,9 +61,9 @@ static CodeAnalyzerHelper()
new PackageIdentity("Microsoft.Extensions.Primitives", "8.0.0"),
new PackageIdentity("System.Threading.Tasks.Extensions", "4.5.4"),
new PackageIdentity("System.Text.Json", "8.0.0"),
new PackageIdentity("xunit.v3.assert", "0.1.1-pre.445"),
new PackageIdentity("xunit.v3.common", "0.1.1-pre.445"),
new PackageIdentity("xunit.v3.extensibility.core", "0.1.1-pre.445")
new PackageIdentity("xunit.v3.assert", "0.2.0-pre.4"),
new PackageIdentity("xunit.v3.common", "0.2.0-pre.4"),
new PackageIdentity("xunit.v3.extensibility.core", "0.2.0-pre.4")
)
);

Expand All @@ -73,8 +73,8 @@ static CodeAnalyzerHelper()
new PackageIdentity("Microsoft.Extensions.Primitives", "8.0.0"),
new PackageIdentity("System.Threading.Tasks.Extensions", "4.5.4"),
new PackageIdentity("System.Text.Json", "8.0.0"),
new PackageIdentity("xunit.v3.common", "0.1.1-pre.445"),
new PackageIdentity("xunit.v3.runner.utility", "0.1.1-pre.445")
new PackageIdentity("xunit.v3.common", "0.2.0-pre.4"),
new PackageIdentity("xunit.v3.runner.utility", "0.2.0-pre.4")
)
);
}
Expand Down
12 changes: 6 additions & 6 deletions src/xunit.analyzers.tests/xunit.analyzers.tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
<PackageDownload Include="System.Collections.Immutable" Version="[1.6.0]" Condition=" '$(TargetFramework)' == 'net472' " />
<PackageDownload Include="System.Text.Json" Version="[8.0.0]" />
<PackageDownload Include="System.Threading.Tasks.Extensions" Version="[4.5.4]" />
<PackageDownload Include="xunit.assert" Version="[2.8.2-pre.9]" />
<PackageDownload Include="xunit.runner.utility" Version="[2.8.2-pre.9]" />
<PackageDownload Include="xunit.v3.assert" Version="[0.1.1-pre.445]" />
<PackageDownload Include="xunit.v3.common" Version="[0.1.1-pre.445]" />
<PackageDownload Include="xunit.v3.extensibility.core" Version="[0.1.1-pre.445]" />
<PackageDownload Include="xunit.v3.runner.utility" Version="[0.1.1-pre.445]" />
<PackageDownload Include="xunit.assert" Version="[2.8.2-pre.19]" />
<PackageDownload Include="xunit.runner.utility" Version="[2.8.2-pre.19]" />
<PackageDownload Include="xunit.v3.assert" Version="[0.2.0-pre.4]" />
<PackageDownload Include="xunit.v3.common" Version="[0.2.0-pre.4]" />
<PackageDownload Include="xunit.v3.extensibility.core" Version="[0.2.0-pre.4]" />
<PackageDownload Include="xunit.v3.runner.utility" Version="[0.2.0-pre.4]" />

<!-- Download packages referenced by CodeAnalysisNetAnalyzers -->
<PackageDownload Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="[9.0.0-preview.24216.2]" />
Expand Down
59 changes: 52 additions & 7 deletions src/xunit.analyzers/Utility/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ public static class Properties
{
public const string ArgumentValue = nameof(ArgumentValue);
public const string AssertMethodName = nameof(AssertMethodName);
public const string DataAttributeTypeName = nameof(DataAttributeTypeName);
public const string DeclaringType = nameof(DeclaringType);
public const string IgnoreCase = nameof(IgnoreCase);
public const string IsStatic = nameof(IsStatic);
Expand Down Expand Up @@ -125,15 +126,59 @@ public static class System

public static class Xunit
{
public const string AssemblyFixtureAttribute_V3 = "Xunit.AssemblyFixtureAttribute";
public const string Assert = "Xunit.Assert";
public const string ClassDataAttribute = "Xunit.ClassDataAttribute";
public const string CollectionAttribute = "Xunit.CollectionAttribute";
public const string CollectionDefinitionAttribute = "Xunit.CollectionDefinitionAttribute";
public const string DataAttribute_V2 = "Xunit.Sdk.DataAttribute";
public const string DataAttribute_V3 = "Xunit.v3.DataAttribute";
public const string FactAttribute = "Xunit.FactAttribute";
public const string LongLivedMarshalByRefObject = "Xunit.LongLivedMarshalByRefObject";
public const string IAssemblyInfo_V2 = "Xunit.Abstractions.IAssemblyInfo";
public const string IAsyncLifetime = "Xunit.IAsyncLifetime";
public const string IAttributeInfo_V2 = "Xunit.Abstractions.IAttributeInfo";
public const string IClassFixtureOfT = "Xunit.IClassFixture`1";
public const string ICollectionFixtureOfT = "Xunit.ICollectionFixture`1";
public const string IMessageSink_V2 = "Xunit.Abstractions.IMessageSink";
public const string IMessageSink_V3 = "Xunit.Sdk.IMessageSink";
public const string IMessageSinkMessage_V2 = "Xunit.Abstractions.IMessageSinkMessage";
public const string IMethodInfo_V2 = "Xunit.Abstractions.IMethodInfo";
public const string IParameterInfo_V2 = "Xunit.Abstractions.IParameterInfo";
public const string InlineDataAttribute = "Xunit.InlineDataAttribute";
public const string ISourceInformation_V2 = "Xunit.Abstractions.ISourceInformation";
public const string ISourceInformationProvider_V2 = "Xunit.Abstractions.ISourceInformationProvider";
public const string ISourceInformationProvider_V3 = "Xunit.Runner.Common.ISourceInformationProvider";
public const string ITest_V2 = "Xunit.Abstractions.ITest";
public const string ITest_V3 = "Xunit.Sdk.ITest";
public const string ITestAssembly_V2 = "Xunit.Abstractions.ITestAssembly";
public const string ITestAssembly_V3 = "Xunit.Sdk.ITestAssembly";
public const string ITestCase_V2 = "Xunit.Abstractions.ITestCase";
public const string ITestCase_V3 = "Xunit.Sdk.ITestCase";
public const string ITestClass_V2 = "Xunit.Abstractions.ITestClass";
public const string ITestClass_V3 = "Xunit.Sdk.ITestClass";
public const string ITestCollection_V2 = "Xunit.Abstractions.ITestCollection";
public const string ITestCollection_V3 = "Xunit.Sdk.ITestCollection";
public const string ITestContextAccessor_V3 = "Xunit.ITestContextAccessor";
public const string ITestFramework_V2 = "Xunit.Abstractions.ITestFramework";
public const string ITestFramework_V3 = "Xunit.v3.ITestFramework";
public const string ITestFrameworkDiscoverer_V2 = "Xunit.Abstractions.ITestFrameworkDiscoverer";
public const string ITestFrameworkDiscoverer_V3 = "Xunit.v3.ITestFrameworkDiscoverer";
public const string ITestFrameworkExecutor_V2 = "Xunit.Abstractions.ITestFrameworkExecutor";
public const string ITestFrameworkExecutor_V3 = "Xunit.v3.ITestFrameworkExecutor";
public const string ITestMethod_V2 = "Xunit.Abstractions.ITestMethod";
public const string ITestMethod_V3 = "Xunit.Sdk.ITestMethod";
public const string ITestOutputHelper_V2 = "Xunit.Abstractions.ITestOutputHelper";
public const string ITestOutputHelper_V3 = "Xunit.ITestOutputHelper";
public const string ITheoryDataRow_V3 = "Xunit.ITheoryDataRow";
public const string ITypeInfo_V2 = "Xunit.Abstractions.ITypeInfo";
public const string IXunitSerializable_V2 = "Xunit.Abstractions.IXunitSerializable";
public const string IXunitSerializable_V3 = "Xunit.Sdk.IXunitSerializable";
public const string LongLivedMarshalByRefObject_Execution_V2 = "Xunit.LongLivedMarshalByRefObject";
public const string LongLivedMarshalByRefObject_RunnerUtility = "Xunit.Sdk.LongLivedMarshalByRefObject";
public const string MemberDataAttribute = "Xunit.MemberDataAttribute";
public const string TheoryAttribute = "Xunit.TheoryAttribute";

public static class Sdk
{
public const string DataAttribute = "Xunit.Sdk.DataAttribute";
public const string LongLivedMarshalByRefObject = "Xunit.Sdk.LongLivedMarshalByRefObject";
}
public const string TheoryData = "Xunit.TheoryData";
public const string TheoryDataRow_V3 = "Xunit.TheoryDataRow";
}
}
}
38 changes: 38 additions & 0 deletions src/xunit.analyzers/Utility/EmptyAbstractionsContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using System;
using Microsoft.CodeAnalysis;

namespace Xunit.Analyzers;

public class EmptyAbstractionsContext : IAbstractionsContext
{
EmptyAbstractionsContext()
{ }

public static EmptyAbstractionsContext Instance { get; } = new();

public INamedTypeSymbol? IMessageSinkType => null;

public INamedTypeSymbol? ISourceInformationProviderType => null;

public INamedTypeSymbol? ITestAssemblyType => null;

public INamedTypeSymbol? ITestCaseType => null;

public INamedTypeSymbol? ITestClassType => null;

public INamedTypeSymbol? ITestCollectionType => null;

public INamedTypeSymbol? ITestFrameworkDiscovererType => null;

public INamedTypeSymbol? ITestFrameworkExecutorType => null;

public INamedTypeSymbol? ITestFrameworkType => null;

public INamedTypeSymbol? ITestMethodType => null;

public INamedTypeSymbol? ITestType => null;

public INamedTypeSymbol? IXunitSerializableType => null;

public Version Version => new();
}
3 changes: 3 additions & 0 deletions src/xunit.analyzers/Utility/EmptyRunnerUtilityContext.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using Microsoft.CodeAnalysis;

namespace Xunit.Analyzers;

Expand All @@ -9,6 +10,8 @@ public class EmptyRunnerUtilityContext : IRunnerUtilityContext

public static EmptyRunnerUtilityContext Instance { get; } = new();

public INamedTypeSymbol? LongLivedMarshalByRefObjectType => null;

public string Platform => "N/A";

public Version Version { get; } = new();
Expand Down
76 changes: 76 additions & 0 deletions src/xunit.analyzers/Utility/IAbstractionsContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
using System;
using Microsoft.CodeAnalysis;

namespace Xunit.Analyzers;

/// <summary>
/// Context with information from <c>xunit.abstractions</c> (in v2) or <c>xunit.v3.common</c> or <c>xunit.v3.core</c> (in v3).
/// The types here are the ones common to both.
/// </summary>
public interface IAbstractionsContext
{
/// <summary>
/// Gets a reference to type <c>IMessageSink</c>, if available.
/// </summary>
INamedTypeSymbol? IMessageSinkType { get; }

/// <summary>
/// Gets a reference to type <c>ISourceInformationProvider</c>, if available.
/// </summary>
INamedTypeSymbol? ISourceInformationProviderType { get; }

/// <summary>
/// Gets a reference to type <c>ITestAssembly</c>, if available.
/// </summary>
INamedTypeSymbol? ITestAssemblyType { get; }

/// <summary>
/// Gets a reference to type <c>ITestCase</c>, if available.
/// </summary>
INamedTypeSymbol? ITestCaseType { get; }

/// <summary>
/// Gets a reference to type <c>ITestClass</c>, if available.
/// </summary>
INamedTypeSymbol? ITestClassType { get; }

/// <summary>
/// Gets a reference to type <c>ITestCollection</c>, if available.
/// </summary>
INamedTypeSymbol? ITestCollectionType { get; }

/// <summary>
/// Gets a reference to type <c>ITestFrameworkDiscoverer</c>, if available.
/// </summary>
INamedTypeSymbol? ITestFrameworkDiscovererType { get; }

/// <summary>
/// Gets a reference to type <c>ITestFrameworkExecutor</c>, if available.
/// </summary>
INamedTypeSymbol? ITestFrameworkExecutorType { get; }

/// <summary>
/// Gets a reference to type <c>ITestFramework</c>, if available.
/// </summary>
INamedTypeSymbol? ITestFrameworkType { get; }

/// <summary>
/// Gets a reference to type <c>ITestMethod</c>, if available.
/// </summary>
INamedTypeSymbol? ITestMethodType { get; }

/// <summary>
/// Gets a reference to type <c>ITest</c>, if available.
/// </summary>
INamedTypeSymbol? ITestType { get; }

/// <summary>
/// Gets a reference to type <c>IXunitSerializable</c>, if available.
/// </summary>
INamedTypeSymbol? IXunitSerializableType { get; }

/// <summary>
/// Gets the version number of the <c>xunit.abstractions</c> or <c>xunit.v3.common</c> assembly.
/// </summary>
public Version Version { get; }
}
Loading

0 comments on commit fec8d66

Please sign in to comment.