-
-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
+semver:minor - Rework Matrix Generator & Source Generated Types insi…
…de `DataGeneratorMetadata` (#1651) * Generate source information for type, method, properties and parameters * MatrixDataSourceAttribute * Analyzer * Release tags * Fix seed * Fix attribute writer * Re-add proj reference
- Loading branch information
Showing
71 changed files
with
4,191 additions
and
5,603 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
changelog: | ||
exclude: | ||
labels: | ||
- ignore-for-release | ||
categories: | ||
- title: Breaking Changes 🛠 | ||
labels: | ||
- Semver-Major | ||
- breaking-change | ||
- breaking | ||
- title: 🏕 Changes | ||
labels: | ||
- '*' | ||
exclude: | ||
labels: | ||
- dependencies | ||
- title: 👒 Dependencies | ||
labels: | ||
- dependencies |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
using NUnit.Framework; | ||
using Verifier = TUnit.Analyzers.Tests.Verifiers.CSharpAnalyzerVerifier<TUnit.Analyzers.MatrixAnalyzer>; | ||
|
||
namespace TUnit.Analyzers.Tests; | ||
|
||
public class MatrixDataSourceAnalyzerTests | ||
{ | ||
[Test] | ||
public async Task Class_No_Error() | ||
{ | ||
await Verifier | ||
.VerifyAnalyzerAsync( | ||
""" | ||
using TUnit.Core; | ||
[MatrixDataSource] | ||
public class MyClass | ||
{ | ||
public MyClass( | ||
[Matrix(1, 2, 3)] int value, | ||
[Matrix(true, false)] bool value2 | ||
) | ||
{ | ||
} | ||
[Test] | ||
public void MyTest() | ||
{ | ||
} | ||
} | ||
""" | ||
); | ||
} | ||
|
||
[Test] | ||
public async Task Class_Missing_Attribute_Error() | ||
{ | ||
await Verifier | ||
.VerifyAnalyzerAsync( | ||
""" | ||
using TUnit.Core; | ||
public class {|#0:MyClass|} | ||
{ | ||
public MyClass( | ||
[Matrix(1, 2, 3)] int value, | ||
[Matrix(true, false)] bool value2 | ||
) | ||
{ | ||
} | ||
[Test] | ||
public void MyTest() | ||
{ | ||
} | ||
} | ||
""", | ||
Verifier.Diagnostic(Rules.MatrixDataSourceAttributeRequired) | ||
.WithLocation(0) | ||
); | ||
} | ||
|
||
|
||
[Test] | ||
public async Task Method_No_Error() | ||
{ | ||
await Verifier | ||
.VerifyAnalyzerAsync( | ||
""" | ||
using TUnit.Core; | ||
public class MyClass | ||
{ | ||
[MatrixDataSource] | ||
[Test] | ||
public void MyTest( | ||
[Matrix(1, 2, 3)] int value, | ||
[Matrix(true, false)] bool value2 | ||
) | ||
{ | ||
} | ||
} | ||
""" | ||
); | ||
} | ||
|
||
[Test] | ||
public async Task Method_Missing_Attribute_Error() | ||
{ | ||
await Verifier | ||
.VerifyAnalyzerAsync( | ||
""" | ||
using TUnit.Core; | ||
public class MyClass | ||
{ | ||
[Test] | ||
public void {|#0:MyTest|}( | ||
[Matrix(1, 2, 3)] int value, | ||
[Matrix(true, false)] bool value2 | ||
) | ||
{ | ||
} | ||
} | ||
""", | ||
|
||
Verifier.Diagnostic(Rules.MatrixDataSourceAttributeRequired) | ||
.WithLocation(0) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
using System.Collections.Immutable; | ||
using Microsoft.CodeAnalysis; | ||
using Microsoft.CodeAnalysis.Diagnostics; | ||
using TUnit.Analyzers.Extensions; | ||
|
||
namespace TUnit.Analyzers; | ||
|
||
[DiagnosticAnalyzer(LanguageNames.CSharp)] | ||
public class MatrixAnalyzer : ConcurrentDiagnosticAnalyzer | ||
{ | ||
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics { get; } = | ||
ImmutableArray.Create( | ||
Rules.MatrixDataSourceAttributeRequired); | ||
|
||
protected override void InitializeInternal(AnalysisContext context) | ||
{ | ||
context.RegisterSymbolAction(AnalyzeMethod, SymbolKind.Method); | ||
context.RegisterSymbolAction(AnalyzeClass, SymbolKind.NamedType); | ||
} | ||
|
||
private void AnalyzeClass(SymbolAnalysisContext context) | ||
{ | ||
if (context.Symbol is not INamedTypeSymbol namedTypeSymbol) | ||
{ | ||
return; | ||
} | ||
|
||
if (!namedTypeSymbol.IsTestClass(context.Compilation)) | ||
{ | ||
return; | ||
} | ||
|
||
CheckMatrixErrors(context, namedTypeSymbol.GetAttributes(), namedTypeSymbol.InstanceConstructors.FirstOrDefault()?.Parameters ?? ImmutableArray<IParameterSymbol>.Empty); | ||
} | ||
|
||
private void AnalyzeMethod(SymbolAnalysisContext context) | ||
{ | ||
if (context.Symbol is not IMethodSymbol methodSymbol) | ||
{ | ||
return; | ||
} | ||
|
||
if (!methodSymbol.IsTestMethod(context.Compilation)) | ||
{ | ||
return; | ||
} | ||
|
||
CheckMatrixErrors(context, methodSymbol.GetAttributes(), methodSymbol.Parameters); | ||
} | ||
|
||
private void CheckMatrixErrors(SymbolAnalysisContext context, ImmutableArray<AttributeData> attributes, | ||
ImmutableArray<IParameterSymbol> parameters) | ||
{ | ||
if (!parameters.Any(x => x.HasMatrixAttribute(context.Compilation))) | ||
{ | ||
return; | ||
} | ||
|
||
if (!attributes.Any(x => x.IsMatrixDataSourceAttribute(context.Compilation))) | ||
{ | ||
context.ReportDiagnostic( | ||
Diagnostic.Create(Rules.MatrixDataSourceAttributeRequired, | ||
context.Symbol.Locations.FirstOrDefault()) | ||
); | ||
} | ||
} | ||
|
||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.