diff --git a/src/BenchmarkDotNet.Analyzers/AnalyzerHelper.cs b/src/BenchmarkDotNet.Analyzers/AnalyzerHelper.cs index ee0f3fd842..ebfd4a09a1 100644 --- a/src/BenchmarkDotNet.Analyzers/AnalyzerHelper.cs +++ b/src/BenchmarkDotNet.Analyzers/AnalyzerHelper.cs @@ -36,7 +36,7 @@ public static bool AttributeListsContainAttribute(INamedTypeSymbol? attributeTyp continue; } - if (attributeSyntaxTypeSymbol.Equals(attributeTypeSymbol)) + if (SymbolEqualityComparer.Default.Equals(attributeSyntaxTypeSymbol, attributeTypeSymbol)) { return true; } @@ -56,7 +56,7 @@ public static bool AttributeListContainsAttribute(INamedTypeSymbol? attributeTyp return false; } - return attributeList.Any(ad => ad.AttributeClass != null && ad.AttributeClass.Equals(attributeTypeSymbol)); + return attributeList.Any(ad => SymbolEqualityComparer.Default.Equals(ad.AttributeClass, attributeTypeSymbol)); } public static ImmutableArray GetAttributes(string attributeName, Compilation compilation, SyntaxList attributeLists, SemanticModel semanticModel) @@ -81,7 +81,7 @@ public static ImmutableArray GetAttributes(INamedTypeSymbol? at continue; } - if (attributeSyntaxTypeSymbol.Equals(attributeTypeSymbol)) + if (SymbolEqualityComparer.Default.Equals(attributeSyntaxTypeSymbol, attributeTypeSymbol)) { attributesBuilder.Add(attributeSyntax); } @@ -118,7 +118,8 @@ public static void Deconstruct(this KeyValuePair tuple, out T1 k } public static Location GetLocation(this AttributeData attributeData) - => attributeData.ApplicationSyntaxReference.SyntaxTree.GetLocation(attributeData.ApplicationSyntaxReference.Span); + => attributeData.ApplicationSyntaxReference?.SyntaxTree.GetLocation(attributeData.ApplicationSyntaxReference.Span) + ?? Location.None; public static bool IsAssignable(TypedConstant constant, ExpressionSyntax expression, ITypeSymbol targetType, Compilation compilation) { @@ -165,8 +166,8 @@ public static ExpressionSyntax GetAttributeParamsArgumentExpression(this Attribu { Debug.Assert(index >= 0); // Properties must come after constructor arguments, so we don't need to worry about it here. - var attrSyntax = (AttributeSyntax) attributeData.ApplicationSyntaxReference.GetSyntax(); - var args = attrSyntax.ArgumentList.Arguments; + var attrSyntax = (AttributeSyntax)attributeData.ApplicationSyntaxReference!.GetSyntax(); + var args = attrSyntax.ArgumentList!.Arguments; Debug.Assert(args is { Count: > 0 }); var maybeArrayExpression = args[0].Expression; @@ -174,7 +175,7 @@ public static ExpressionSyntax GetAttributeParamsArgumentExpression(this Attribu if (maybeArrayExpression is CollectionExpressionSyntax collectionExpressionSyntax) { Debug.Assert(index < collectionExpressionSyntax.Elements.Count); - return ((ExpressionElementSyntax) collectionExpressionSyntax.Elements[index]).Expression; + return ((ExpressionElementSyntax)collectionExpressionSyntax.Elements[index]).Expression; } #endif diff --git a/src/BenchmarkDotNet.Analyzers/Attributes/ArgumentsAttributeAnalyzer.cs b/src/BenchmarkDotNet.Analyzers/Attributes/ArgumentsAttributeAnalyzer.cs index 9618f5f944..b19d348997 100644 --- a/src/BenchmarkDotNet.Analyzers/Attributes/ArgumentsAttributeAnalyzer.cs +++ b/src/BenchmarkDotNet.Analyzers/Attributes/ArgumentsAttributeAnalyzer.cs @@ -46,7 +46,7 @@ public class ArgumentsAttributeAnalyzer : DiagnosticAnalyzer "Usage", DiagnosticSeverity.Error, isEnabledByDefault: true, - description: AnalyzerHelper.GetResourceString(nameof(BenchmarkDotNetAnalyzerResources.Attributes_ArgumentsAttribute_MustHaveMatchingValueType_Description))); + description: AnalyzerHelper.GetResourceString(nameof(BenchmarkDotNetAnalyzerResources.Attributes_ArgumentsAttribute_RequiresParameters_Description))); public override ImmutableArray SupportedDiagnostics => new DiagnosticDescriptor[] { @@ -95,15 +95,15 @@ private static void AnalyzeMethodSymbol(SymbolAnalysisContext context) var argumentsSourceAttributes = new List(); foreach (var attr in methodSymbol.GetAttributes()) { - if (attr.AttributeClass.Equals(benchmarkAttributeTypeSymbol)) + if (SymbolEqualityComparer.Default.Equals(attr.AttributeClass, benchmarkAttributeTypeSymbol)) { hasBenchmarkAttribute = true; } - else if (attr.AttributeClass.Equals(argumentsAttributeTypeSymbol)) + else if (SymbolEqualityComparer.Default.Equals(attr.AttributeClass, argumentsAttributeTypeSymbol)) { argumentsAttributes.Add(attr); } - else if (attr.AttributeClass.Equals(argumentsSourceAttributeTypeSymbol)) + else if (SymbolEqualityComparer.Default.Equals(attr.AttributeClass, argumentsSourceAttributeTypeSymbol)) { argumentsSourceAttributes.Add(attr); } @@ -150,10 +150,10 @@ private static void AnalyzeMethodSymbol(SymbolAnalysisContext context) } else { - var syntax = (AttributeSyntax) attr.ApplicationSyntaxReference.GetSyntax(); + var syntax = (AttributeSyntax)attr.ApplicationSyntaxReference!.GetSyntax(); AnalyzeAssignableValueType( attr.ConstructorArguments[0], - syntax.ArgumentList.Arguments[0].Expression, + syntax.ArgumentList!.Arguments[0].Expression, methodSymbol.Parameters[0].Type ); } @@ -200,7 +200,7 @@ void AnalyzeAssignableValueType(TypedConstant value, ExpressionSyntax expression expression.GetLocation(), expression.ToString(), parameterType.ToDisplayString(), - value.IsNull ? "null" : value.Type.ToDisplayString()) + value.IsNull ? "null" : value.Type!.ToDisplayString()) ); } } diff --git a/src/BenchmarkDotNet.Analyzers/Attributes/GeneralParameterAttributesAnalyzer.cs b/src/BenchmarkDotNet.Analyzers/Attributes/GeneralParameterAttributesAnalyzer.cs index fea9dddcfd..ad97483215 100644 --- a/src/BenchmarkDotNet.Analyzers/Attributes/GeneralParameterAttributesAnalyzer.cs +++ b/src/BenchmarkDotNet.Analyzers/Attributes/GeneralParameterAttributesAnalyzer.cs @@ -138,9 +138,9 @@ private static void Analyze(SyntaxNodeAnalysisContext context) if (attributeSyntaxTypeSymbol == null || attributeSyntaxTypeSymbol.TypeKind == TypeKind.Error || - (!attributeSyntaxTypeSymbol.Equals(paramsAttributeTypeSymbol) - && !attributeSyntaxTypeSymbol.Equals(paramsSourceAttributeTypeSymbol) - && !attributeSyntaxTypeSymbol.Equals(paramsAllValuesAttributeTypeSymbol))) + (!SymbolEqualityComparer.Default.Equals(attributeSyntaxTypeSymbol, paramsAttributeTypeSymbol) + && !SymbolEqualityComparer.Default.Equals(attributeSyntaxTypeSymbol, paramsSourceAttributeTypeSymbol) + && !SymbolEqualityComparer.Default.Equals(attributeSyntaxTypeSymbol, paramsAllValuesAttributeTypeSymbol))) { return; } @@ -153,10 +153,10 @@ private static void Analyze(SyntaxNodeAnalysisContext context) ImmutableArray declaredAttributes; bool fieldOrPropertyIsPublic; - Location fieldConstModifierLocation = null; - Location fieldReadonlyModifierLocation = null; + Location? fieldConstModifierLocation = null; + Location? fieldReadonlyModifierLocation = null; string fieldOrPropertyIdentifier; - Location propertyInitAccessorKeywordLocation = null; + Location? propertyInitAccessorKeywordLocation = null; Location fieldOrPropertyIdentifierLocation; bool propertyIsMissingAssignableSetter = false; DiagnosticDescriptor fieldOrPropertyCannotHaveMoreThanOneParameterAttributeAppliedDiagnosticRule; @@ -186,11 +186,11 @@ private static void Analyze(SyntaxNodeAnalysisContext context) #if CODE_ANALYSIS_3_8 var propertyInitAccessorIndex = propertyDeclarationSyntax.AccessorList?.Accessors.IndexOf(SyntaxKind.InitAccessorDeclaration); - propertyInitAccessorKeywordLocation = propertyInitAccessorIndex >= 0 ? propertyDeclarationSyntax.AccessorList.Accessors[propertyInitAccessorIndex.Value].Keyword.GetLocation() : null; + propertyInitAccessorKeywordLocation = propertyInitAccessorIndex >= 0 ? propertyDeclarationSyntax.AccessorList!.Accessors[propertyInitAccessorIndex.Value].Keyword.GetLocation() : null; #endif var propertySetAccessorIndex = propertyDeclarationSyntax.AccessorList?.Accessors.IndexOf(SyntaxKind.SetAccessorDeclaration); - propertyIsMissingAssignableSetter = !propertySetAccessorIndex.HasValue || propertySetAccessorIndex.Value < 0 || propertyDeclarationSyntax.AccessorList.Accessors[propertySetAccessorIndex.Value].Modifiers.Any(); + propertyIsMissingAssignableSetter = !propertySetAccessorIndex.HasValue || propertySetAccessorIndex.Value < 0 || propertyDeclarationSyntax.AccessorList!.Accessors[propertySetAccessorIndex.Value].Modifiers.Any(); fieldOrPropertyIdentifierLocation = propertyDeclarationSyntax.Identifier.GetLocation(); fieldOrPropertyCannotHaveMoreThanOneParameterAttributeAppliedDiagnosticRule = MutuallyExclusiveOnPropertyRule; @@ -203,9 +203,9 @@ private static void Analyze(SyntaxNodeAnalysisContext context) AnalyzeFieldOrPropertySymbol( context, - paramsAttributeTypeSymbol, - paramsSourceAttributeTypeSymbol, - paramsAllValuesAttributeTypeSymbol, + paramsAttributeTypeSymbol!, + paramsSourceAttributeTypeSymbol!, + paramsAllValuesAttributeTypeSymbol!, declaredAttributes, fieldOrPropertyIsPublic, fieldConstModifierLocation, @@ -222,9 +222,9 @@ private static void Analyze(SyntaxNodeAnalysisContext context) private static void AnalyzeFieldOrPropertySymbol( SyntaxNodeAnalysisContext context, - INamedTypeSymbol? paramsAttributeTypeSymbol, - INamedTypeSymbol? paramsSourceAttributeTypeSymbol, - INamedTypeSymbol? paramsAllValuesAttributeTypeSymbol, + INamedTypeSymbol paramsAttributeTypeSymbol, + INamedTypeSymbol paramsSourceAttributeTypeSymbol, + INamedTypeSymbol paramsAllValuesAttributeTypeSymbol, ImmutableArray declaredAttributes, bool fieldOrPropertyIsPublic, Location? fieldConstModifierLocation, @@ -238,14 +238,14 @@ private static void AnalyzeFieldOrPropertySymbol( AttributeSyntax attributeSyntax, SyntaxNode attributeTarget) { - ImmutableArray applicableParameterAttributeTypeSymbols = new INamedTypeSymbol[] - { + ImmutableArray applicableParameterAttributeTypeSymbols = + [ paramsAttributeTypeSymbol, paramsSourceAttributeTypeSymbol, paramsAllValuesAttributeTypeSymbol - }.ToImmutableArray(); + ]; - var parameterAttributeTypeSymbols = new HashSet(); + var parameterAttributeTypeSymbols = new HashSet(SymbolEqualityComparer.Default); foreach (var declaredAttributeSyntax in declaredAttributes) { @@ -254,7 +254,7 @@ private static void AnalyzeFieldOrPropertySymbol( { foreach (var applicableParameterAttributeTypeSymbol in applicableParameterAttributeTypeSymbols) { - if (declaredAttributeTypeSymbol.Equals(applicableParameterAttributeTypeSymbol)) + if (SymbolEqualityComparer.Default.Equals(declaredAttributeTypeSymbol, applicableParameterAttributeTypeSymbol)) { if (!parameterAttributeTypeSymbols.Add(applicableParameterAttributeTypeSymbol)) { @@ -406,7 +406,7 @@ private static void AnalyzeParamsSourceWriteOnlyProperty( return; } - var referencedMember = targetType.GetMembers(sourceName).FirstOrDefault(); + var referencedMember = targetType.GetMembers(sourceName!).FirstOrDefault(); if (referencedMember is IPropertySymbol propertySymbol && propertySymbol.SetMethod != null && propertySymbol.GetMethod == null) diff --git a/src/BenchmarkDotNet.Analyzers/Attributes/ParamsAllValuesAttributeAnalyzer.cs b/src/BenchmarkDotNet.Analyzers/Attributes/ParamsAllValuesAttributeAnalyzer.cs index 3f637f5613..3896fdfd79 100644 --- a/src/BenchmarkDotNet.Analyzers/Attributes/ParamsAllValuesAttributeAnalyzer.cs +++ b/src/BenchmarkDotNet.Analyzers/Attributes/ParamsAllValuesAttributeAnalyzer.cs @@ -60,7 +60,7 @@ private static void Analyze(SyntaxNodeAnalysisContext context) var paramsAllValuesAttributeTypeSymbol = GetParamsAllValuesAttributeTypeSymbol(context.Compilation); var attributeSyntaxTypeSymbol = context.SemanticModel.GetTypeInfo(attributeSyntax).Type; - if (attributeSyntaxTypeSymbol == null || !attributeSyntaxTypeSymbol.Equals(paramsAllValuesAttributeTypeSymbol)) + if (!SymbolEqualityComparer.Default.Equals(attributeSyntaxTypeSymbol, paramsAllValuesAttributeTypeSymbol)) { return; } @@ -111,7 +111,7 @@ private static void AnalyzeFieldOrPropertyTypeSyntax(SyntaxNodeAnalysisContext c return; } - if (fieldOrPropertyTypeSymbol.GetAttributes().Any(ad => ad.AttributeClass != null && ad.AttributeClass.Equals(flagsAttributeTypeSymbol))) + if (fieldOrPropertyTypeSymbol.GetAttributes().Any(ad => SymbolEqualityComparer.Default.Equals(ad.AttributeClass, flagsAttributeTypeSymbol))) { context.ReportDiagnostic(Diagnostic.Create(NotAllowedOnFlagsEnumPropertyOrFieldTypeRule, fieldOrPropertyTypeSyntax.GetLocation(), fieldOrPropertyTypeSymbol.ToString())); } diff --git a/src/BenchmarkDotNet.Analyzers/Attributes/ParamsAttributeAnalyzer.cs b/src/BenchmarkDotNet.Analyzers/Attributes/ParamsAttributeAnalyzer.cs index fd8c3b389c..9e5423a4bc 100644 --- a/src/BenchmarkDotNet.Analyzers/Attributes/ParamsAttributeAnalyzer.cs +++ b/src/BenchmarkDotNet.Analyzers/Attributes/ParamsAttributeAnalyzer.cs @@ -61,7 +61,7 @@ public override void Initialize(AnalysisContext analysisContext) private void Analyze(SymbolAnalysisContext context) { - ITypeSymbol fieldOrPropertyType = context.Symbol switch + ITypeSymbol? fieldOrPropertyType = context.Symbol switch { IFieldSymbol fieldSymbol => fieldSymbol.Type, IPropertySymbol propertySymbol => propertySymbol.Type, @@ -74,7 +74,7 @@ private void Analyze(SymbolAnalysisContext context) var paramsAttributeTypeSymbol = GetParamsAttributeTypeSymbol(context.Compilation); var attrs = context.Symbol.GetAttributes(); - var paramsAttributes = attrs.Where(attr => attr.AttributeClass.Equals(paramsAttributeTypeSymbol)).ToImmutableArray(); + var paramsAttributes = attrs.Where(attr => SymbolEqualityComparer.Default.Equals(attr.AttributeClass, paramsAttributeTypeSymbol)).ToImmutableArray(); if (paramsAttributes.Length != 1) { // Don't analyze zero or multiple [Params] (multiple is not legal and already handled by GeneralParameterAttributesAnalyzer). @@ -93,10 +93,10 @@ private void Analyze(SymbolAnalysisContext context) // [Params(null)] if (attr.ConstructorArguments[0].IsNull) { - var syntax = (AttributeSyntax) attr.ApplicationSyntaxReference.GetSyntax(); + var syntax = (AttributeSyntax)attr.ApplicationSyntaxReference!.GetSyntax(); AnalyzeAssignableValueType( attr.ConstructorArguments[0], - syntax.ArgumentList.Arguments[0].Expression, + syntax.ArgumentList!.Arguments[0].Expression, fieldOrPropertyType ); return; @@ -140,7 +140,7 @@ void AnalyzeAssignableValueType(TypedConstant value, ExpressionSyntax expression expression.GetLocation(), expression.ToString(), parameterType.ToDisplayString(), - value.IsNull ? "null" : value.Type.ToDisplayString()) + value.IsNull ? "null" : value.Type!.ToDisplayString()) ); } } diff --git a/src/BenchmarkDotNet.Analyzers/BenchmarkDotNet.Analyzers.csproj b/src/BenchmarkDotNet.Analyzers/BenchmarkDotNet.Analyzers.csproj index 647308d606..66d475e342 100644 --- a/src/BenchmarkDotNet.Analyzers/BenchmarkDotNet.Analyzers.csproj +++ b/src/BenchmarkDotNet.Analyzers/BenchmarkDotNet.Analyzers.csproj @@ -14,11 +14,11 @@ $(DefineConstants);CODE_ANALYSIS_3_8 $(DefineConstants);CODE_ANALYSIS_4_8 $(DefineConstants);CODE_ANALYSIS_5_0 - - $(NoWarn);RS1024;RS2007 + $(NoWarn);RS2007 $(NoWarn);RS2002 + enable diff --git a/src/BenchmarkDotNet.Analyzers/BenchmarkDotNetAnalyzerResources.Designer.cs b/src/BenchmarkDotNet.Analyzers/BenchmarkDotNetAnalyzerResources.Designer.cs index 4f7ea289bc..8bd42ac17b 100644 --- a/src/BenchmarkDotNet.Analyzers/BenchmarkDotNetAnalyzerResources.Designer.cs +++ b/src/BenchmarkDotNet.Analyzers/BenchmarkDotNetAnalyzerResources.Designer.cs @@ -1,4 +1,4 @@ -//------------------------------------------------------------------------------ +//------------------------------------------------------------------------------ // // This code was generated by a tool. // Runtime Version:4.0.30319.42000 @@ -132,6 +132,15 @@ internal static string Attributes_ArgumentsAttribute_RequiresBenchmarkAttribute_ } } + /// + /// Looks up a localized string similar to The values passed to an [Arguments] must have parameter(s). + /// + internal static string Attributes_ArgumentsAttribute_RequiresParameters_Description { + get { + return ResourceManager.GetString("Attributes_ArgumentsAttribute_RequiresParameters_Description", resourceCulture); + } + } + /// /// Looks up a localized string similar to Method {0} has no parameters. /// diff --git a/src/BenchmarkDotNet.Analyzers/BenchmarkDotNetAnalyzerResources.resx b/src/BenchmarkDotNet.Analyzers/BenchmarkDotNetAnalyzerResources.resx index b3095e42cd..5ba7f21797 100644 --- a/src/BenchmarkDotNet.Analyzers/BenchmarkDotNetAnalyzerResources.resx +++ b/src/BenchmarkDotNet.Analyzers/BenchmarkDotNetAnalyzerResources.resx @@ -385,4 +385,7 @@ Either add the [ArgumentsSource] or [Arguments] attribute(s) or remove the param Method {0} has no parameters + + The values passed to an [Arguments] must have parameter(s) + \ No newline at end of file diff --git a/src/BenchmarkDotNet.Analyzers/BenchmarkRunner/RunAnalyzer.cs b/src/BenchmarkDotNet.Analyzers/BenchmarkRunner/RunAnalyzer.cs index efcb46a2a2..ab25cbf3b1 100644 --- a/src/BenchmarkDotNet.Analyzers/BenchmarkRunner/RunAnalyzer.cs +++ b/src/BenchmarkDotNet.Analyzers/BenchmarkRunner/RunAnalyzer.cs @@ -108,7 +108,7 @@ private static void Analyze(SyntaxNodeAnalysisContext context) var classMemberAccessTypeSymbol = context.SemanticModel.GetTypeInfo(identifierNameSyntax).Type; if (classMemberAccessTypeSymbol is null || classMemberAccessTypeSymbol.TypeKind == TypeKind.Error - || !classMemberAccessTypeSymbol.Equals(benchmarkRunnerTypeSymbol)) + || !SymbolEqualityComparer.Default.Equals(classMemberAccessTypeSymbol, benchmarkRunnerTypeSymbol)) { return; } @@ -202,7 +202,7 @@ bool HasBenchmarkAttribute() { if (attributeData.AttributeClass != null) { - if (attributeData.AttributeClass.Equals(benchmarkAttributeTypeSymbol)) + if (SymbolEqualityComparer.Default.Equals(attributeData.AttributeClass, benchmarkAttributeTypeSymbol)) { return true; } diff --git a/src/BenchmarkDotNet.Analyzers/General/BenchmarkClassAnalyzer.cs b/src/BenchmarkDotNet.Analyzers/General/BenchmarkClassAnalyzer.cs index a2b414da43..08d93b77cb 100644 --- a/src/BenchmarkDotNet.Analyzers/General/BenchmarkClassAnalyzer.cs +++ b/src/BenchmarkDotNet.Analyzers/General/BenchmarkClassAnalyzer.cs @@ -208,11 +208,11 @@ private static void AnalyzeClassDeclaration(SyntaxNodeAnalysisContext context) continue; } - if (attributeSyntaxTypeSymbol.Equals(benchmarkAttributeTypeSymbol)) + if (SymbolEqualityComparer.Default.Equals(attributeSyntaxTypeSymbol, benchmarkAttributeTypeSymbol)) { benchmarkAttributeUsages.Add(attributeSyntax); } - else if (attributeSyntaxTypeSymbol.Equals(benchmarkCategoryAttributeTypeSymbol)) + else if (SymbolEqualityComparer.Default.Equals(attributeSyntaxTypeSymbol, benchmarkCategoryAttributeTypeSymbol)) { if (attributeSyntax.ArgumentList is { Arguments.Count: 1 }) { @@ -355,7 +355,7 @@ private static void AnalyzeClassDeclaration(SyntaxNodeAnalysisContext context) { if (benchmarkCategories.Count > 0 && benchmarkAttributeUsages[0].ArgumentList != null) { - foreach (var attributeArgumentSyntax in benchmarkAttributeUsages[0].ArgumentList.Arguments) + foreach (var attributeArgumentSyntax in benchmarkAttributeUsages[0].ArgumentList!.Arguments) { if (attributeArgumentSyntax.NameEquals != null && attributeArgumentSyntax.NameEquals.Name.Identifier.ValueText == "Baseline") { @@ -381,7 +381,7 @@ private static void AnalyzeClassDeclaration(SyntaxNodeAnalysisContext context) { if (benchmarkAttributeUsages[0].ArgumentList != null) { - foreach (var attributeArgumentSyntax in benchmarkAttributeUsages[0].ArgumentList.Arguments) + foreach (var attributeArgumentSyntax in benchmarkAttributeUsages[0].ArgumentList!.Arguments) { if (attributeArgumentSyntax.NameEquals != null && attributeArgumentSyntax.NameEquals.Name.Identifier.ValueText == "Baseline") { @@ -453,11 +453,11 @@ private static void AnalyzeClassDeclaration(SyntaxNodeAnalysisContext context) foreach (var attribute in methodAttributes) { - if (attribute.AttributeClass.Equals(benchmarkAttributeTypeSymbol)) + if (SymbolEqualityComparer.Default.Equals(attribute.AttributeClass, benchmarkAttributeTypeSymbol)) { benchmarkAttributeUsages.Add(attribute); } - else if (attribute.AttributeClass.Equals(benchmarkCategoryAttributeTypeSymbol)) + else if (SymbolEqualityComparer.Default.Equals(attribute.AttributeClass, benchmarkCategoryAttributeTypeSymbol)) { foreach (var benchmarkCategoriesArray in attribute.ConstructorArguments) { @@ -550,7 +550,7 @@ private static void AnalyzeAttributeSyntax(SyntaxNodeAnalysisContext context) var benchmarkCategoryAttributeTypeSymbol = GetBenchmarkCategoryAttributeTypeSymbol(context.Compilation); var attributeTypeSymbol = context.SemanticModel.GetTypeInfo(attributeSyntax).Type; - if (attributeTypeSymbol != null && attributeTypeSymbol.Equals(benchmarkCategoryAttributeTypeSymbol)) + if (SymbolEqualityComparer.Default.Equals(attributeTypeSymbol, benchmarkCategoryAttributeTypeSymbol)) { if (attributeSyntax.ArgumentList is { Arguments.Count: 1 }) { diff --git a/tests/BenchmarkDotNet.Analyzers.Tests/AnalyzerTests/Attributes/ArgumentsAttributeAnalyzerTests.cs b/tests/BenchmarkDotNet.Analyzers.Tests/AnalyzerTests/Attributes/ArgumentsAttributeAnalyzerTests.cs index 52b4cf8b7a..092a15a334 100644 --- a/tests/BenchmarkDotNet.Analyzers.Tests/AnalyzerTests/Attributes/ArgumentsAttributeAnalyzerTests.cs +++ b/tests/BenchmarkDotNet.Analyzers.Tests/AnalyzerTests/Attributes/ArgumentsAttributeAnalyzerTests.cs @@ -29,7 +29,7 @@ public class BenchmarkClass {{emptyArgumentsAttributeUsage}} public void {{benchmarkMethodName}}() { - + } } """; @@ -97,7 +97,7 @@ public class BenchmarkClass [{{string.Join("]\n[", ArgumentAttributeUsages.Take(argumentAttributeUsagesListLength))}}] public void BenchmarkMethod() { - + } } """; @@ -113,13 +113,13 @@ public async Task A_method_with_at_least_one_arguments_attribute_but_no_benchmar { var testCode = /* lang=c#-test */ $$""" using BenchmarkDotNet.Attributes; - + public class BenchmarkClass { {{string.Join("\n", ArgumentAttributeUsages.Take(argumentAttributeUsagesListLength).Select((a, i) => $"[{{|#{i}:{a}|}}]"))}} public void BenchmarkMethod() { - + } } """; @@ -159,7 +159,7 @@ public class BenchmarkClass [Benchmark] public void BenchmarkMethod() { - + } } """; @@ -207,7 +207,7 @@ public class BenchmarkClass {{argumentsAttributeUsage}} public void {{benchmarkMethodName}}(string a) { - + } } """; @@ -232,7 +232,7 @@ public class BenchmarkClass {{argumentsAttributeUsage}} public void {{benchmarkMethodName}}(string a) { - + } } """; @@ -384,7 +384,7 @@ public class BenchmarkClass [Benchmark] public void BenchmarkMethod() { - + } } """; @@ -408,7 +408,7 @@ public class BenchmarkClass [{{dummyAttributeUsage}}{{string.Format(scalarValuesContainerAttributeArgument, "42")}}] public void BenchmarkMethod(int a) { - + } } """; @@ -435,7 +435,7 @@ public class BenchmarkClass [{{dummyAttributeUsage}}{{string.Format(scalarValuesContainerAttributeArgument, "42")}}] public void BenchmarkMethod(int a) { - + } } """; @@ -460,7 +460,7 @@ public class BenchmarkClass {{argumentsAttributeUsage}} public void BenchmarkMethod(string a) { - + } } """; @@ -487,7 +487,7 @@ public class BenchmarkClass """)}}] public void BenchmarkMethod({{parameters}}) { - + } } """; @@ -510,7 +510,7 @@ public class BenchmarkClass [{{dummyAttributeUsage}}{{string.Format(scalarValuesContainerAttributeArgument, "dummy_literal, true")}}] public void BenchmarkMethod(byte a, bool b) { - + } } """; @@ -537,7 +537,7 @@ public class BenchmarkClass [{{dummyAttributeUsage}}{{string.Format(scalarValuesContainerAttributeArgument, "typeof(int), typeof(dummy_literal)")}}] public void BenchmarkMethod(System.Type a, System.Type b) { - + } } """; @@ -567,7 +567,7 @@ public class BenchmarkClass [{{dummyAttributeUsage}}{{string.Format(scalarValuesContainerAttributeArgument, valueAndType.Value1)}}] public void BenchmarkMethod({{valueAndType.Value2}} a) { - + } } """; @@ -597,7 +597,7 @@ public class BenchmarkClass [{{dummyAttributeUsage}}{{string.Format(scalarValuesContainerAttributeArgument, "DummyEnumInDifferentNamespace.Value1")}}] public void BenchmarkMethod(DummyEnumInDifferentNamespace{{(isNullable ? "?" : "")}} a) { - + } } """; @@ -618,7 +618,7 @@ public async Task Providing_expected_enum_value_type_using_not_fully_qualified_n { var testCode = /* lang=c#-test */ $$""" using BenchmarkDotNet.Attributes; - + namespace DifferentNamespace; public class BenchmarkClass @@ -627,7 +627,7 @@ public class BenchmarkClass [{{dummyAttributeUsage}}{{string.Format(scalarValuesContainerAttributeArgument, "DummyEnumInDifferentNamespace.Value1")}}] public void BenchmarkMethod(DummyEnumInDifferentNamespace{{(isNullable ? "?" : "")}} a) { - + } } """; @@ -648,7 +648,7 @@ public async Task Providing_expected_enum_value_type_array_using_not_fully_quali { var testCode = /* lang=c#-test */ $$""" using DifferentNamespace; - + using BenchmarkDotNet.Attributes; public class BenchmarkClass @@ -656,7 +656,7 @@ public class BenchmarkClass [{{dummyAttributeUsage}}{{string.Format(arrayValuesContainerAttributeArgument, "DummyEnumInDifferentNamespace.Value1", $"DummyEnumInDifferentNamespace{(isNullable ? "?" : "")}")}}] public void BenchmarkMethod(DummyEnumInDifferentNamespace{{(isNullable ? "?" : "")}} a) { - + } } """; @@ -686,7 +686,7 @@ public class BenchmarkClass [{{dummyAttributeUsage}}{{string.Format(arrayValuesContainerAttributeArgument, "DummyEnumInDifferentNamespace.Value1", $"DummyEnumInDifferentNamespace{(isNullable ? "?" : "")}")}}] public void BenchmarkMethod(DummyEnumInDifferentNamespace{{(isNullable ? "?" : "")}} a) { - + } } """; @@ -708,7 +708,7 @@ public async Task Providing_expected_type_using_not_fully_qualified_name_located { var testCode = /* lang=c#-test */ $$""" using BenchmarkDotNet.Attributes; - + namespace DifferentNamespace; public class BenchmarkClass @@ -717,7 +717,7 @@ public class BenchmarkClass [{{dummyAttributeUsage}}{{string.Format(scalarValuesContainerAttributeArgument, valueAndType.Value1)}}] public void BenchmarkMethod({{valueAndType.Value2}} a) { - + } } """; @@ -737,7 +737,7 @@ public async Task Providing_expected_type_using_not_fully_qualified_name_located { var testCode = /* lang=c#-test */ $$""" using DifferentNamespace; - + using BenchmarkDotNet.Attributes; public class BenchmarkClass @@ -746,7 +746,7 @@ public class BenchmarkClass [{{dummyAttributeUsage}}{{string.Format(scalarValuesContainerAttributeArgument, valueAndType.Value1)}}] public void BenchmarkMethod({{valueAndType.Value2}} a) { - + } } """; @@ -774,7 +774,7 @@ public class BenchmarkClass [{{dummyAttributeUsage}}{{string.Format(scalarValuesContainerAttributeArgument, $"{(explicitCast ? $"({integerValueAndType.Value2})" : "")}{integerValueAndType.Value1}")}}] public void BenchmarkMethod({{integerValueAndType.Value2}} a) { - + } } """; @@ -825,7 +825,7 @@ public async Task Providing_expected_constant_value_type_should_not_trigger_diag public class BenchmarkClass { {{(useLocalConstant ? $"private const {valueAndType.Value2} _x = {(useConstantFromOtherClass ? "Constants.Value" : valueAndType.Value1!)};" : "")}} - + [Benchmark] [{{dummyAttributeUsage}}{{string.Format(scalarValuesContainerAttributeArgument, useLocalConstant ? "_x" : useConstantFromOtherClass ? "Constants.Value" : valueAndType.Value1!)}}] public void BenchmarkMethod({{valueAndType.Value2}} a) @@ -860,7 +860,7 @@ public async Task Providing_expected_null_reference_constant_value_type_should_n public class BenchmarkClass { {{(useLocalConstant ? $"private const {type}? _x = {(useConstantFromOtherClass ? "Constants.Value" : "null")};" : "")}} - + [Benchmark] [{{dummyAttributeUsage}}{{string.Format(scalarValuesContainerAttributeArgument, useLocalConstant ? "_x" : useConstantFromOtherClass ? "Constants.Value" : "null")}}] public void BenchmarkMethod({{type}} a) @@ -896,7 +896,7 @@ public class BenchmarkClass [{{dummyAttributeUsage}}{{string.Format(scalarValuesContainerAttributeArgument, value)}}] public void BenchmarkMethod(int a) { - + } } """; @@ -921,7 +921,7 @@ public class BenchmarkClass [{{dummyAttributeUsage}}{{string.Format(scalarValuesContainerAttributeArgument, "new[] { 0, 1, 2 }")}}] public void BenchmarkMethod(System.Span a) { - + } } """; @@ -947,7 +947,7 @@ public class BenchmarkClass [{{dummyAttributeUsage}}{{string.Format(scalarValuesContainerAttributeArgument, "43, \"test2\"")}}] public void BenchmarkMethod(unkown a, string b) { - + } } """; @@ -977,7 +977,7 @@ public class BenchmarkClass [{{dummyAttributeUsage}}{{string.Format(scalarValuesContainerAttributeArgument, $"{{|#0:{valueAndType.Value1}|}}")}}] public void BenchmarkMethod({{expectedArgumentType}} a) { - + } } """; @@ -1007,7 +1007,7 @@ public async Task Providing_an_unexpected_or_not_implicitly_convertible_constant public class BenchmarkClass { {{(useLocalConstant ? $"private const {valueAndType.Value2} _x = {(useConstantFromOtherClass ? "Constants.Value" : valueAndType.Value1)};" : "")}} - + [Benchmark] [{{dummyAttributeUsage}}{{string.Format(scalarValuesContainerAttributeArgument, $"{{|#0:{(useLocalConstant ? "_x" : useConstantFromOtherClass ? "Constants.Value" : valueAndType.Value1)}|}}")}}] public void BenchmarkMethod({{expectedArgumentType}} a) @@ -1073,7 +1073,7 @@ public class BenchmarkClass [{{dummyAttributeUsage}}{{string.Format(scalarValuesContainerAttributeArgument, "{|#0:new[] { 0, 1, 2 }|}")}}] public void BenchmarkMethod({{expectedArgumentType}} a) { - + } } """; diff --git a/tests/BenchmarkDotNet.Analyzers.Tests/AnalyzerTests/Attributes/GeneralArgumentAttributesAnalyzerTests.cs b/tests/BenchmarkDotNet.Analyzers.Tests/AnalyzerTests/Attributes/GeneralArgumentAttributesAnalyzerTests.cs index 70028faa80..b91f933d15 100644 --- a/tests/BenchmarkDotNet.Analyzers.Tests/AnalyzerTests/Attributes/GeneralArgumentAttributesAnalyzerTests.cs +++ b/tests/BenchmarkDotNet.Analyzers.Tests/AnalyzerTests/Attributes/GeneralArgumentAttributesAnalyzerTests.cs @@ -22,14 +22,14 @@ public async Task A_method_with_parameters_annotated_with_an_argumentssource_or_ { var testCode = /* lang=c#-test */ $$""" using BenchmarkDotNet.Attributes; - + public class BenchmarkClass { [Benchmark] [{{attributeUsage}}] public void BenchmarkMethod(int a, string b) { - + } } """; @@ -50,7 +50,7 @@ public class BenchmarkClass { public void BenchmarkMethod({{string.Join(", ", Parameters.Take(parametersListLength))}}) { - + } } """; @@ -75,7 +75,7 @@ public class BenchmarkClass [ArgumentsSource("test")] public void {{benchmarkMethodName}}({|#0:{{string.Join(", ", Parameters.Take(parametersListLength))}}|}) { - + } } """; @@ -99,7 +99,7 @@ public class BenchmarkClass [Benchmark] public void {{benchmarkMethodName}}({|#0:{{string.Join(", ", Parameters.Take(parametersListLength))}}|}) { - + } } """; diff --git a/tests/BenchmarkDotNet.Analyzers.Tests/AnalyzerTests/Attributes/ParamsAttributeAnalyzerTests.cs b/tests/BenchmarkDotNet.Analyzers.Tests/AnalyzerTests/Attributes/ParamsAttributeAnalyzerTests.cs index 69cd77b962..832d889fba 100644 --- a/tests/BenchmarkDotNet.Analyzers.Tests/AnalyzerTests/Attributes/ParamsAttributeAnalyzerTests.cs +++ b/tests/BenchmarkDotNet.Analyzers.Tests/AnalyzerTests/Attributes/ParamsAttributeAnalyzerTests.cs @@ -474,7 +474,7 @@ public async Task Providing_expected_constant_value_type_should_not_trigger_diag public class BenchmarkClass { {{(useLocalConstant ? $"private const {valueAndType.Value2} _x = {(useConstantFromOtherClass ? "Constants.Value" : valueAndType.Value1!)};" : "")}} - + [{{dummyAttributeUsage}}Params({{string.Format(scalarValuesContainerAttributeArgument, useLocalConstant ? "_x" : useConstantFromOtherClass ? "Constants.Value" : valueAndType.Value1!)}})] public {{valueAndType.Value2}} {{fieldOrPropertyDeclaration}} } @@ -507,7 +507,7 @@ public async Task Providing_expected_null_reference_constant_value_type_should_n public class BenchmarkClass { {{(useLocalConstant ? $"private const {type}? _x = {(useConstantFromOtherClass ? "Constants.Value" : "null")};" : "")}} - + [{{dummyAttributeUsage}}Params({{string.Format(scalarValuesContainerAttributeArgument, useLocalConstant ? "_x" : useConstantFromOtherClass ? "Constants.Value" : "null")}})] public {{type}}? {{fieldOrPropertyDeclaration}} } @@ -691,7 +691,7 @@ public async Task Providing_an_unexpected_or_not_implicitly_convertible_constant public class BenchmarkClass { {{(useLocalConstant ? $"private const {valueAndType.Value2} _x = {(useConstantFromOtherClass ? "Constants.Value" : valueAndType.Value1)};" : "")}} - + [{{dummyAttributeUsage}}Params({{string.Format(scalarValuesContainerAttributeArgument, $"{{|#0:{(useLocalConstant ? "_x" : useConstantFromOtherClass ? "Constants.Value" : valueAndType.Value1)}|}}")}})] public {{expectedFieldOrPropertyType}} {{fieldOrPropertyDeclaration}} } diff --git a/tests/BenchmarkDotNet.Analyzers.Tests/AnalyzerTests/BenchmarkRunner/RunAnalyzerTests.cs b/tests/BenchmarkDotNet.Analyzers.Tests/AnalyzerTests/BenchmarkRunner/RunAnalyzerTests.cs index 01f35bff30..58654f84af 100644 --- a/tests/BenchmarkDotNet.Analyzers.Tests/AnalyzerTests/BenchmarkRunner/RunAnalyzerTests.cs +++ b/tests/BenchmarkDotNet.Analyzers.Tests/AnalyzerTests/BenchmarkRunner/RunAnalyzerTests.cs @@ -75,23 +75,23 @@ public static void Main(string[] args) { const string benchmarkClassDocument = /* lang=c#-test */ $$""" using BenchmarkDotNet.Attributes; - + public class {{classWithOneBenchmarkMethodName}} { [Benchmark] public void BenchmarkMethod() { - + } - + public void BenchmarkMethod2() { - + } - + private void BenchmarkMethod3() { - + } } """; @@ -124,7 +124,7 @@ public static void Main(string[] args) { const string benchmarkClassDocument = /* lang=c#-test */ $$""" using BenchmarkDotNet.Attributes; - + public class {{classWithOneBenchmarkMethodName}} : BenchmarkClassAncestor1 { } @@ -152,15 +152,15 @@ public void BenchmarkMethod() { } - + public void BenchmarkMethod2() { } - + private void BenchmarkMethod3() { - + } } """; @@ -183,7 +183,7 @@ public async Task Invoking_with_a_generic_type_argument_class_having_at_least_on var testCode = /* lang=c#-test */ $$""" using BenchmarkDotNet.Running; - + public class Program { public static void Main(string[] args) { @@ -220,15 +220,15 @@ public void BenchmarkMethod() { } - + public void BenchmarkMethod2() { } - + private void BenchmarkMethod3() { - + } } """; @@ -264,7 +264,7 @@ public static void Main(string[] args) { const string benchmarkClassDocument = /* lang=c#-test */ $$""" using BenchmarkDotNet.Attributes; - + public class {{classWithOneBenchmarkMethodName}} : BenchmarkClassAncestor1 { } @@ -295,15 +295,15 @@ public void BenchmarkMethod() { } - + public void BenchmarkMethod2() { } - + private void BenchmarkMethod3() { - + } } """; @@ -331,7 +331,7 @@ public async Task Invoking_with_a_generic_type_argument_class_having_no_public_m var testCode = /* lang=c#-test */ $$""" using BenchmarkDotNet.Running; - + public class Program { public static void Main(string[] args) { @@ -367,10 +367,10 @@ public void BenchmarkMethod() { } - + private void BenchmarkMethod2() { - + } } """; @@ -395,7 +395,7 @@ public async Task Invoking_with_type_argument_class_having_no_public_method_anno var testCode = /* lang=c#-test */ $$""" using BenchmarkDotNet.Running; - + public class Program { public static void Main(string[] args) { @@ -409,7 +409,7 @@ public class {{classWithOneBenchmarkMethodName}} { public void BenchmarkMethod() { - + } } """; @@ -446,17 +446,17 @@ public class Program public static void Main(string[] args) { BenchmarkRunner.Run{{invocationExpression}}; } - + private class {{benchmarkClassName}} : BenchmarkClassAncestor1 { } - + private class BenchmarkClassAncestor1 : BenchmarkClassAncestor2 { [Benchmark] public void BenchmarkMethod() { - + } } } @@ -464,7 +464,7 @@ public void BenchmarkMethod() const string benchmarkClassAncestor2Document = /* lang=c#-test */ """ using BenchmarkDotNet.Attributes; - + public class BenchmarkClassAncestor2 { } @@ -490,19 +490,19 @@ public async Task Invoking_with_a_nonpublic_class_containing_at_least_one_method var testCode = /* lang=c#-test */ $$""" using BenchmarkDotNet.Attributes; using BenchmarkDotNet.Running; - + public class Program { public static void Main(string[] args) { BenchmarkRunner.Run{{invocationExpression}}; } - + {{nonPublicClassAccessModifier}}class {{benchmarkClassName}} { [Benchmark] public void BenchmarkMethod() { - + } } } @@ -532,7 +532,7 @@ public static void Main(string[] args) { BenchmarkRunner.Run{{invocationExpression}}; } } - + file class {{benchmarkClassName}} { [Benchmark] @@ -567,7 +567,7 @@ public async Task Invoking_with_a_sealed_benchmark_class_should_trigger_diagnost var testCode = /* lang=c#-test */ $$""" using BenchmarkDotNet.Running; - + public class Program { public static void Main(string[] args) { @@ -578,13 +578,13 @@ public static void Main(string[] args) { const string benchmarkClassDocument = /* lang=c#-test */ $$""" using BenchmarkDotNet.Attributes; - + public sealed class {{benchmarkClassName}} { [Benchmark] public void BenchmarkMethod() { - + } } """; @@ -609,7 +609,7 @@ public async Task Invoking_with_an_abstract_benchmark_class_should_trigger_diagn var testCode = /* lang=c#-test */ $$""" using BenchmarkDotNet.Running; - + public class Program { public static void Main(string[] args) { @@ -620,13 +620,13 @@ public static void Main(string[] args) { const string benchmarkClassDocument = /* lang=c#-test */ $$""" using BenchmarkDotNet.Attributes; - + public abstract class {{benchmarkClassName}} { [Benchmark] public void BenchmarkMethod() { - + } } """; @@ -654,7 +654,7 @@ public async Task Invoking_with_a_generic_class_annotated_with_at_least_one_gene var testCode = /* lang=c#-test */ $$""" using BenchmarkDotNet.Running; - + public class Program { public static void Main(string[] args) { @@ -669,14 +669,14 @@ public static void Main(string[] args) { var benchmarkClassDocument = /* lang=c#-test */ $$""" using BenchmarkDotNet.Attributes; - + {{genericTypeArgumentsAttributeUsages}} public class BenchmarkClass<{{typeParameters}}> : BenchmarkClassAncestor1<{{typeParameters}}> { {{benchmarkAttributeUsage}} public void BenchmarkMethod() { - + } } """; @@ -684,19 +684,19 @@ public void BenchmarkMethod() var benchmarkClassAncestor1Document = /* lang=c#-test */ $$""" public {{abstractModifier}}class BenchmarkClassAncestor1<{{typeParameters}}> : BenchmarkClassAncestor2<{{typeParameters}}> { - + } """; var benchmarkClassAncestor2Document = /* lang=c#-test */ $$""" using BenchmarkDotNet.Attributes; - + public {{abstractModifier}}class BenchmarkClassAncestor2<{{typeParameters}}> { - + {{benchmarkAttributeUsage}} public void BenchmarkMethod() { - + } } """; @@ -722,7 +722,7 @@ public async Task Invoking_with_a_nongeneric_class_that_inherits_from_a_generic_ var testCode = /* lang=c#-test */ $$""" using BenchmarkDotNet.Running; - + public class Program { public static void Main(string[] args) { @@ -733,10 +733,10 @@ public static void Main(string[] args) { var benchmarkClassDocument = /* lang=c#-test */ $$""" using BenchmarkDotNet.Attributes; - + public class {{benchmarkClassName}} : BenchmarkClassAncestor<{{string.Join(", ", GenericTypeArguments.Take(typeParametersListLength))}}> { - + } """; var benchmarkClassAncestorDocument = /* lang=c#-test */ $$""" @@ -744,11 +744,11 @@ public class {{benchmarkClassName}} : BenchmarkClassAncestor<{{string.Join(", ", public {{abstractModifier}}class BenchmarkClassAncestor<{{string.Join(", ", TypeParameters.Take(typeParametersListLength))}}> { - + {{benchmarkAttributeUsage}} public void BenchmarkMethod() { - + } } """; @@ -798,15 +798,15 @@ public void BenchmarkMethod() { } - + public void BenchmarkMethod2() { } - + private void BenchmarkMethod3() { - + } } """; @@ -835,7 +835,7 @@ public async Task Invoking_with_a_generic_class_not_annotated_with_a_generictype var testCode = /* lang=c#-test */ $$""" using BenchmarkDotNet.Running; - + public class Program { public static void Main(string[] args) { @@ -846,13 +846,13 @@ public static void Main(string[] args) { var benchmarkClassDocument = /* lang=c#-test */ $$""" using BenchmarkDotNet.Attributes; - + public class {{benchmarkClassName}}<{{typeParameters}}> : BenchmarkClassAncestor1<{{typeParameters}}> { {{benchmarkAttributeUsage}} public void BenchmarkMethod() { - + } } """; @@ -860,7 +860,7 @@ public void BenchmarkMethod() var benchmarkClassAncestor1Document = /* lang=c#-test */ $$""" public {{abstractModifier}}class BenchmarkClassAncestor1<{{typeParameters}}> : BenchmarkClassAncestor2<{{typeParameters}}> { - + } """; @@ -874,7 +874,7 @@ public void BenchmarkMethod() {{benchmarkAttributeUsage}} public void BenchmarkMethod() { - + } } """; diff --git a/tests/BenchmarkDotNet.Analyzers.Tests/AnalyzerTests/General/BenchmarkClassAnalyzerTests.cs b/tests/BenchmarkDotNet.Analyzers.Tests/AnalyzerTests/General/BenchmarkClassAnalyzerTests.cs index 9f341b1160..6ebb4d9798 100644 --- a/tests/BenchmarkDotNet.Analyzers.Tests/AnalyzerTests/General/BenchmarkClassAnalyzerTests.cs +++ b/tests/BenchmarkDotNet.Analyzers.Tests/AnalyzerTests/General/BenchmarkClassAnalyzerTests.cs @@ -7,6 +7,7 @@ using Xunit; namespace BenchmarkDotNet.Analyzers.Tests.AnalyzerTests.General; + public class BenchmarkClassAnalyzerTests { public class General : AnalyzerTestFixture @@ -288,10 +289,10 @@ public void BenchmarkMethod() { } - + public void NonBenchmarkMethod() { - + } } """; @@ -336,13 +337,13 @@ public async Task Nongeneric_method_annotated_with_benchmark_attribute_should_no { const string testCode = /* lang=c#-test */ """ using BenchmarkDotNet.Attributes; - + public class BenchmarkClass { [Benchmark] public void NonGenericBenchmarkMethod() { - + } } """; @@ -421,10 +422,10 @@ public void BenchmarkMethod() { } - + public void NonBenchmarkMethod() { - + } } """; @@ -441,13 +442,13 @@ public async Task Static_class_containing_at_least_one_method_annotated_with_ben const string testCode = /* lang=c#-test */ $$""" using BenchmarkDotNet.Attributes; - + public {|#0:static|} class {{benchmarkClassName}} { [Benchmark] public static void BenchmarkMethod() { - + } } """; @@ -474,7 +475,7 @@ public async Task Providing_a_non_null_single_argument_should_not_trigger_diagno { var testCode = /* lang=c#-test */ $$""" [assembly: BenchmarkDotNet.Attributes.BenchmarkCategory({{(useConstantFromOtherClass ? "Constants.Value" : "\"test\"")}})] - + public class BenchmarkClass : BenchmarkClassAncestor1 { } @@ -484,17 +485,17 @@ public class BenchmarkClass : BenchmarkClassAncestor1 var benchmarkClassAncestor1Document = /* lang=c#-test */ $$""" using BenchmarkDotNet.Attributes; - + {{benchmarkCategoryAttributeUsage}} public {{abstractModifier}}class BenchmarkClassAncestor1 { {{(useLocalConstant ? $"private const string _x = {(useConstantFromOtherClass ? "Constants.Value" : "\"test\"")};" : "")}} - + {{benchmarkCategoryAttributeUsage}} {{benchmarkAttributeUsage}} public void BenchmarkMethod() { - + } } """; @@ -514,7 +515,7 @@ public async Task Providing_an_empty_array_argument_should_not_trigger_diagnosti { var testCode = /* lang=c#-test */ $$""" [assembly: BenchmarkDotNet.Attributes.BenchmarkCategory{{emptyBenchmarkCategoryAttributeArgument}}] - + public class BenchmarkClass : BenchmarkClassAncestor1 { } @@ -522,7 +523,7 @@ public class BenchmarkClass : BenchmarkClassAncestor1 var benchmarkClassAncestor1Document = /* lang=c#-test */ $$""" using BenchmarkDotNet.Attributes; - + [BenchmarkCategory{{emptyBenchmarkCategoryAttributeArgument}}] public {{abstractModifier}}class BenchmarkClassAncestor1 { @@ -530,7 +531,7 @@ public class BenchmarkClass : BenchmarkClassAncestor1 {{benchmarkAttributeUsage}} public void BenchmarkMethod() { - + } } """; @@ -559,7 +560,7 @@ public async Task Providing_an_array_argument_containing_one_or_more_null_values var testCode = /* lang=c#-test */ $$""" [assembly: BenchmarkDotNet.Attributes.BenchmarkCategory({{assemblyLevelAttributeValues}})] - + public class BenchmarkClass : BenchmarkClassAncestor1 { } @@ -574,7 +575,7 @@ public class BenchmarkClass : BenchmarkClassAncestor1 var benchmarkClassAncestor1Document = /* lang=c#-test */ $$""" using BenchmarkDotNet.Attributes; - + [BenchmarkCategory({{classAndMethodAttributeLevelValues}})] public {{abstractModifier}}class BenchmarkClassAncestor1 { @@ -582,12 +583,12 @@ public class BenchmarkClass : BenchmarkClassAncestor1 private const string _xNull = {(useConstantsFromOtherClass ? "Constants.Value1" : "null")}; private const string _xValue = {(useConstantsFromOtherClass ? "Constants.Value2" : "\"test\"")}; """ : "")}} - + [BenchmarkCategory({{classAndMethodAttributeLevelValues}})] {{benchmarkAttributeUsage}} public void BenchmarkMethod() { - + } } """; @@ -608,7 +609,7 @@ public async Task Providing_a_null_single_argument_should_trigger_diagnostic( { var testCode = /* lang=c#-test */ $$""" [assembly: BenchmarkDotNet.Attributes.BenchmarkCategory({|#0:{{(useConstantFromOtherClass ? "Constants.Value" : "null")}}|})] - + public class BenchmarkClass : BenchmarkClassAncestor1 { } @@ -616,17 +617,17 @@ public class BenchmarkClass : BenchmarkClassAncestor1 var benchmarkClassAncestor1Document = /* lang=c#-test */ $$""" using BenchmarkDotNet.Attributes; - + [BenchmarkCategory({|#1:{{(useLocalConstant ? "_x" : useConstantFromOtherClass ? "Constants.Value" : "null")}}|})] public {{abstractModifier}}class BenchmarkClassAncestor1 { {{(useLocalConstant ? $"private const string _x = {(useConstantFromOtherClass ? "Constants.Value" : "null")};" : "")}} - + [BenchmarkCategory({|#2:{{(useLocalConstant ? "_x" : useConstantFromOtherClass ? "Constants.Value" : "null")}}|})] {{benchmarkAttributeUsage}} public void BenchmarkMethod() { - + } } """; @@ -668,24 +669,24 @@ public async Task Class_with_only_one_benchmark_method_marked_as_baseline_should { var testCode = /* lang=c#-test */ $$""" using BenchmarkDotNet.Attributes; - + public class BenchmarkClass : BenchmarkClassAncestor1 { {{(useLocalConstants ? $""" private const bool _xTrue = {(useConstantsFromOtherClass ? "Constants.Value1" : "true")}; private const bool _xFalse = {(useConstantsFromOtherClass ? "Constants.Value2" : useInvalidFalseValue ? "dummy" : "false")}; """ : "")}} - + [Benchmark(Baseline = {{(useLocalConstants ? "_xTrue" : useConstantsFromOtherClass ? "Constants.Value1" : "true")}})] public void BaselineBenchmarkMethod() { - + } - + [Benchmark] public void NonBaselineBenchmarkMethod1() { - + } } """; @@ -708,21 +709,21 @@ public void NonBaselineBenchmarkMethod1() public {{abstractModifier}}class BenchmarkClassAncestor3 { {{(useLocalConstants ? $"private const bool _xFalse = {(useConstantsFromOtherClass ? "Constants.Value2" : useInvalidFalseValue ? "dummy" : "false")};" : "")}} - + [Benchmark(Baseline = {{(useLocalConstants ? "_xFalse" : useConstantsFromOtherClass ? "Constants.Value2" : useInvalidFalseValue ? "dummy" : "false")}})] public void NonBaselineBenchmarkMethod2() { } - + public void BenchmarkMethod2() { } - + private void BenchmarkMethod3() { - + } } """; @@ -752,24 +753,24 @@ public async Task Class_with_duplicated_benchmark_attribute_usages_per_method_sh var testCode = /* lang=c#-test */ $$""" using BenchmarkDotNet.Attributes; - + public class BenchmarkClass : BenchmarkClassAncestor1 { {{(useLocalConstants ? $""" private const bool _xTrue = {(useConstantsFromOtherClass ? "Constants.Value1" : "true")}; private const bool _xFalse = {(useConstantsFromOtherClass ? "Constants.Value2" : "false")}; """ : "")}} - + {{baselineBenchmarkAttributeUsages}} public void BaselineBenchmarkMethod() { - + } - + [Benchmark] public void NonBaselineBenchmarkMethod1() { - + } } """; @@ -792,21 +793,21 @@ public void NonBaselineBenchmarkMethod1() public {{abstractModifier}}class BenchmarkClassAncestor3 { {{(useLocalConstants ? $"private const bool _xFalse = {(useConstantsFromOtherClass ? "Constants.Value2" : "false")};" : "")}} - + {{baselineBenchmarkAttributeUsages}} public void NonBaselineBenchmarkMethod2() { } - + public void BenchmarkMethod2() { } - + private void BenchmarkMethod3() { - + } } """; @@ -835,17 +836,17 @@ public async Task Class_with_no_benchmark_methods_marked_as_baseline_should_not_ public class BenchmarkClass : BenchmarkClassAncestor1 { {{(useLocalConstant ? $"private const bool _xFalse = {(useConstantFromOtherClass ? "Constants.Value" : useInvalidFalseValue ? "dummy" : "false")};" : "")}} - + [Benchmark] public void NonBaselineBenchmarkMethod1() { } - + [Benchmark] public void NonBaselineBenchmarkMethod2() { - + } } """; @@ -891,23 +892,23 @@ public async Task Class_with_more_than_one_benchmark_method_marked_as_baseline_p var testCode = /* lang=c#-test */ $$""" using BenchmarkDotNet.Attributes; - + public class BenchmarkClass : BenchmarkClassAncestor1 { {{(useLocalConstants ? $""" private const bool _xTrue = {(useConstantsFromOtherClass ? "Constants.Value1" : "true")}; private const bool _xFalse = {(useConstantsFromOtherClass ? "Constants.Value2" : "false")}; """ : "")}} - + [BenchmarkCategory({{string.Format(valuesContainer, """ null, "test", null, "TEST", "test2" """)}})] {{baselineBenchmarkAttributeUsage}} public void BaselineBenchmarkMethod1() { - + } - + [BenchmarkCategory({{string.Format(valuesContainer, "null, null")}})] [BenchmarkCategory({{string.Format(valuesContainer, """ @@ -919,32 +920,32 @@ public void BaselineBenchmarkMethod1() {{baselineBenchmarkAttributeUsage}} public void BaselineBenchmarkMethod2() { - + } - + [BenchmarkCategory("Category1")] {{nonBaselineBenchmarkAttributeUsage}} public void NonBaselineBenchmarkMethod1() { - + } - + [BenchmarkCategory("Category1")] public void DummyMethod() { - + } - + [Benchmark] public void NonBaselineBenchmarkMethod2() { - + } - + {{nonBaselineBenchmarkAttributeUsage}} public void NonBaselineBenchmarkMethod3() { - + } } """; @@ -961,7 +962,7 @@ public void NonBaselineBenchmarkMethod3() public {{abstractModifier}}class BenchmarkClassAncestor2 { {{(useLocalConstants ? $"private const bool _xTrue = {(useConstantsFromOtherClass ? "Constants.Value1" : "true")};" : "")}} - + [BenchmarkCategory({{string.Format(valuesContainer, "null, null")}})] [BenchmarkCategory({{string.Format(valuesContainer, """ "test", null @@ -998,49 +999,49 @@ public async Task Class_with_more_than_one_benchmark_method_marked_as_baseline_s var testCode = /* lang=c#-test */ $$""" using BenchmarkDotNet.Attributes; - + public class BenchmarkClass : BenchmarkClassAncestor1 { {{(useLocalConstants ? $""" private const bool _xTrue = {(useConstantsFromOtherClass ? "Constants.Value1" : "true")}; private const bool _xFalse = {(useConstantsFromOtherClass ? "Constants.Value2" : "false")}; """ : "")}} - + {{string.Format(baselineBenchmarkAttributeUsageWithLocationMarker, 0)}} public void BaselineBenchmarkMethod1() { - + } - + {{(useDuplicateInSameClass ? string.Format(baselineBenchmarkAttributeUsageWithLocationMarker, 1) : "")}} public void BaselineBenchmarkMethod2() { - + } - + [BenchmarkCategory("Category1")] {{nonBaselineBenchmarkAttributeUsage}} public void NonBaselineBenchmarkMethod1() { - + } - + [BenchmarkCategory("Category1")] public void DummyMethod() { - + } - + [Benchmark] public void NonBaselineBenchmarkMethod2() { - + } - + {{nonBaselineBenchmarkAttributeUsage}} public void NonBaselineBenchmarkMethod3() { - + } } """; @@ -1057,7 +1058,7 @@ public void NonBaselineBenchmarkMethod3() public {{abstractModifier}}class BenchmarkClassAncestor2 { {{(useLocalConstants ? $"private const bool _xTrue = {(useConstantsFromOtherClass ? "Constants.Value1" : "true")};" : "")}} - + {{baselineBenchmarkAttributeUsage}} public void BaselineBenchmarkMethod3() { @@ -1096,51 +1097,51 @@ public async Task Class_with_more_than_one_benchmark_method_marked_as_baseline_w var testCode = /* lang=c#-test */ $$""" using BenchmarkDotNet.Attributes; - + public class BenchmarkClass : BenchmarkClassAncestor1 { {{(useLocalConstants ? $""" private const bool _xTrue = {(useConstantsFromOtherClass ? "Constants.Value1" : "true")}; private const bool _xFalse = {(useConstantsFromOtherClass ? "Constants.Value2" : "false")}; """ : "")}} - + {{emptyBenchmarkCategoryAttributeUsages}} {{string.Format(baselineBenchmarkAttributeUsageWithLocationMarker, 0)}} public void BaselineBenchmarkMethod1() { - + } - + {{emptyBenchmarkCategoryAttributeUsages}} {{(useDuplicateInSameClass ? string.Format(baselineBenchmarkAttributeUsageWithLocationMarker, 1) : "")}} public void BaselineBenchmarkMethod2() { - + } - + [BenchmarkCategory("Category1")] {{nonBaselineBenchmarkAttributeUsage}} public void NonBaselineBenchmarkMethod1() { - + } - + [BenchmarkCategory("Category1")] public void DummyMethod() { - + } - + [Benchmark] public void NonBaselineBenchmarkMethod2() { - + } - + {{nonBaselineBenchmarkAttributeUsage}} public void NonBaselineBenchmarkMethod3() { - + } } """; @@ -1157,7 +1158,7 @@ public void NonBaselineBenchmarkMethod3() public {{abstractModifier}}class BenchmarkClassAncestor2 { {{(useLocalConstants ? $"private const bool _xTrue = {(useConstantsFromOtherClass ? "Constants.Value1" : "true")};" : "")}} - + {{emptyBenchmarkCategoryAttributeUsages}} {{baselineBenchmarkAttributeUsage}} public void BaselineBenchmarkMethod3() @@ -1205,24 +1206,24 @@ public async Task Class_with_only_one_benchmark_method_marked_as_baseline_should { var testCode = /* lang=c#-test */ $$""" using BenchmarkDotNet.Attributes; - + public class BenchmarkClass : BenchmarkClassAncestor1 { {{(useLocalConstants ? $""" private const bool _xTrue = {(useConstantsFromOtherClass ? "Constants.Value1" : "true")}; private const bool _xFalse = {(useConstantsFromOtherClass ? "Constants.Value2" : useInvalidFalseValue ? "dummy" : "false")}; """ : "")}} - + [Benchmark(Baseline = {{(useLocalConstants ? "_xTrue" : useConstantsFromOtherClass ? "Constants.Value1" : "true")}})] public void BaselineBenchmarkMethod() { - + } - + [Benchmark] public void NonBaselineBenchmarkMethod1() { - + } } """; @@ -1245,21 +1246,21 @@ public void NonBaselineBenchmarkMethod1() public {{abstractModifier}}class BenchmarkClassAncestor3 { {{(useLocalConstants ? $"private const bool _xFalse = {(useConstantsFromOtherClass ? "Constants.Value2" : useInvalidFalseValue ? "dummy" : "false")};" : "")}} - + [Benchmark(Baseline = {{(useLocalConstants ? "_xFalse" : useConstantsFromOtherClass ? "Constants.Value2" : useInvalidFalseValue ? "dummy" : "false")}})] public void NonBaselineBenchmarkMethod2() { } - + public void BenchmarkMethod2() { } - + private void BenchmarkMethod3() { - + } } """; @@ -1284,58 +1285,58 @@ public async Task Class_with_only_one_benchmark_method_marked_as_baseline_per_un { var testCode = /* lang=c#-test */ $$""" using BenchmarkDotNet.Attributes; - + public class BenchmarkClass : BenchmarkClassAncestor1 { {{(useLocalConstants ? $""" private const bool _xTrue = {(useConstantsFromOtherClass ? "Constants.Value1" : "true")}; private const bool _xFalse = {(useConstantsFromOtherClass ? "Constants.Value2" : useInvalidFalseValue ? "dummy" : "false")}; """ : "")}} - + [Benchmark(Baseline = {{(useLocalConstants ? "_xTrue" : useConstantsFromOtherClass ? "Constants.Value1" : "true")}})] public void BaselineBenchmarkMethod() { - + } - + [BenchmarkCategory("Category1")] [Benchmark(Baseline = {{(useLocalConstants ? "_xTrue" : useConstantsFromOtherClass ? "Constants.Value1" : "true")}})] public void BaselineBenchmarkMethod() { - + } - + [BenchmarkCategory("Category2")] [Benchmark(Baseline = {{(useLocalConstants ? "_xTrue" : useConstantsFromOtherClass ? "Constants.Value1" : "true")}})] public void BaselineBenchmarkMethod() { - + } - + [BenchmarkCategory("Category1")] [Benchmark(Baseline = {{(useLocalConstants ? "_xFalse" : useConstantsFromOtherClass ? "Constants.Value2" : useInvalidFalseValue ? "dummy" : "false")}})] public void BaselineBenchmarkMethod() { - + } - + [BenchmarkCategory("Category2")] [Benchmark] public void BaselineBenchmarkMethod() { - + } - + [Benchmark] public void NonBaselineBenchmarkMethod1() { - + } - + [Benchmark(Baseline = {{(useLocalConstants ? "_xFalse" : useConstantsFromOtherClass ? "Constants.Value2" : useInvalidFalseValue ? "dummy" : "false")}})] public void NonBaselineBenchmarkMethod2() { - + } } """; @@ -1382,17 +1383,17 @@ public async Task Class_with_no_benchmark_methods_marked_as_baseline_should_not_ public class BenchmarkClass : BenchmarkClassAncestor1 { {{(useLocalConstant ? $"private const bool _xFalse = {(useConstantFromOtherClass ? "Constants.Value" : useInvalidFalseValue ? "dummy" : "false")};" : "")}} - + [Benchmark] public void NonBaselineBenchmarkMethod1() { } - + [Benchmark] public void NonBaselineBenchmarkMethod2() { - + } } """; @@ -1438,49 +1439,49 @@ public async Task Class_with_more_than_one_benchmark_method_marked_as_baseline_s var testCode = /* lang=c#-test */ $$""" using BenchmarkDotNet.Attributes; - + public class BenchmarkClass : BenchmarkClassAncestor1 { {{(useLocalConstants ? $""" private const bool _xTrue = {(useConstantsFromOtherClass ? "Constants.Value1" : "true")}; private const bool _xFalse = {(useConstantsFromOtherClass ? "Constants.Value2" : "false")}; """ : "")}} - + {{baselineBenchmarkAttributeUsage}} public void BaselineBenchmarkMethod1() { - + } - + {{(useDuplicateInSameClass ? baselineBenchmarkAttributeUsage : "")}} public void BaselineBenchmarkMethod2() { - + } - + [BenchmarkCategory("Category1")] {{nonBaselineBenchmarkAttributeUsage}} public void NonBaselineBenchmarkMethod1() { - + } - + [BenchmarkCategory("Category1")] public void DummyMethod() { - + } - + [Benchmark] public void NonBaselineBenchmarkMethod2() { - + } - + {{nonBaselineBenchmarkAttributeUsage}} public void NonBaselineBenchmarkMethod3() { - + } } """; @@ -1497,7 +1498,7 @@ public void NonBaselineBenchmarkMethod3() public {{abstractModifier}}class BenchmarkClassAncestor2 { {{(useLocalConstants ? $"private const bool _xTrue = {(useConstantsFromOtherClass ? "Constants.Value1" : "true")};" : "")}} - + {{baselineBenchmarkAttributeUsage}} public void BaselineBenchmarkMethod3() { @@ -1528,51 +1529,51 @@ public async Task Class_with_more_than_one_benchmark_method_marked_as_baseline_w var testCode = /* lang=c#-test */ $$""" using BenchmarkDotNet.Attributes; - + public class BenchmarkClass : BenchmarkClassAncestor1 { {{(useLocalConstants ? $""" private const bool _xTrue = {(useConstantsFromOtherClass ? "Constants.Value1" : "true")}; private const bool _xFalse = {(useConstantsFromOtherClass ? "Constants.Value2" : "false")}; """ : "")}} - + {{emptyBenchmarkCategoryAttributeUsages}} {{baselineBenchmarkAttributeUsage}} public void BaselineBenchmarkMethod1() { - + } - + {{emptyBenchmarkCategoryAttributeUsages}} {{(useDuplicateInSameClass ? baselineBenchmarkAttributeUsage : "")}} public void BaselineBenchmarkMethod2() { - + } - + [BenchmarkCategory("Category1")] {{nonBaselineBenchmarkAttributeUsage}} public void NonBaselineBenchmarkMethod1() { - + } - + [BenchmarkCategory("Category1")] public void DummyMethod() { - + } - + [Benchmark] public void NonBaselineBenchmarkMethod2() { - + } - + {{nonBaselineBenchmarkAttributeUsage}} public void NonBaselineBenchmarkMethod3() { - + } } """; @@ -1589,7 +1590,7 @@ public void NonBaselineBenchmarkMethod3() public {{abstractModifier}}class BenchmarkClassAncestor2 { {{(useLocalConstants ? $"private const bool _xTrue = {(useConstantsFromOtherClass ? "Constants.Value1" : "true")};" : "")}} - + {{emptyBenchmarkCategoryAttributeUsages}} {{baselineBenchmarkAttributeUsage}} public void BaselineBenchmarkMethod3() @@ -1621,21 +1622,21 @@ public async Task Class_with_more_than_one_benchmark_method_marked_as_baseline_p var testCode = /* lang=c#-test */ $$""" using BenchmarkDotNet.Attributes; - + public class BenchmarkClass : BenchmarkClassAncestor1 { {{(useLocalConstants ? $""" private const bool _xTrue = {(useConstantsFromOtherClass ? "Constants.Value1" : "true")}; private const bool _xFalse = {(useConstantsFromOtherClass ? "Constants.Value2" : "false")}; """ : "")}} - + [BenchmarkCategory({{string.Format(valuesContainer, $""" null, {invalidCategoryStringValue}, null, "TEST", "test2" """)}})] {{baselineBenchmarkAttributeUsage}} public void BaselineBenchmarkMethod1() { - + } [BenchmarkCategory({{string.Format(valuesContainer, "null, null")}})] @@ -1648,32 +1649,32 @@ public void BaselineBenchmarkMethod1() {{(useDuplicateInSameClass ? baselineBenchmarkAttributeUsage : "")}} public void BaselineBenchmarkMethod2() { - + } - + [BenchmarkCategory("Category1")] {{nonBaselineBenchmarkAttributeUsage}} public void NonBaselineBenchmarkMethod1() { - + } - + [BenchmarkCategory("Category1")] public void DummyMethod() { - + } - + [Benchmark] public void NonBaselineBenchmarkMethod2() { - + } - + {{nonBaselineBenchmarkAttributeUsage}} public void NonBaselineBenchmarkMethod3() { - + } } """; @@ -1690,7 +1691,7 @@ public void NonBaselineBenchmarkMethod3() public {{abstractModifier}}class BenchmarkClassAncestor2 { {{(useLocalConstants ? $"private const bool _xTrue = {(useConstantsFromOtherClass ? "Constants.Value1" : "true")};" : "")}} - + [BenchmarkCategory({{string.Format(valuesContainer, "null, null")}})] [BenchmarkCategory({{string.Format(valuesContainer, $"{invalidCategoryStringValue}, null")}})] [BenchmarkCategory({{string.Format(valuesContainer, """ @@ -1727,23 +1728,23 @@ public async Task Class_with_more_than_one_benchmark_method_marked_as_baseline_p var testCode = /* lang=c#-test */ $$""" using BenchmarkDotNet.Attributes; - + public class BenchmarkClass : BenchmarkClassAncestor1 { {{(useLocalConstants ? $""" private const bool _xTrue = {(useConstantsFromOtherClass ? "Constants.Value1" : "true")}; private const bool _xFalse = {(useConstantsFromOtherClass ? "Constants.Value2" : "false")}; """ : "")}} - + [BenchmarkCategory({{string.Format(valuesContainer, """ null, "test", null, "TEST", "test2" """)}})] {{string.Format(baselineBenchmarkAttributeUsageWithLocationMarker, 0)}} public void BaselineBenchmarkMethod1() { - + } - + [BenchmarkCategory({{string.Format(valuesContainer, "null, null")}})] [BenchmarkCategory({{string.Format(valuesContainer, """ "test", null @@ -1754,32 +1755,32 @@ public void BaselineBenchmarkMethod1() {{(useDuplicateInSameClass ? string.Format(baselineBenchmarkAttributeUsageWithLocationMarker, 1) : "")}} public void BaselineBenchmarkMethod2() { - + } - + [BenchmarkCategory("Category1")] {{nonBaselineBenchmarkAttributeUsage}} public void NonBaselineBenchmarkMethod1() { - + } - + [BenchmarkCategory("Category1")] public void DummyMethod() { - + } - + [Benchmark] public void NonBaselineBenchmarkMethod2() { - + } - + {{nonBaselineBenchmarkAttributeUsage}} public void NonBaselineBenchmarkMethod3() { - + } } """; @@ -1796,7 +1797,7 @@ public void NonBaselineBenchmarkMethod3() public {{abstractModifier}}class BenchmarkClassAncestor2 { {{(useLocalConstants ? $"private const bool _xTrue = {(useConstantsFromOtherClass ? "Constants.Value1" : "true")};" : "")}} - + [BenchmarkCategory({{string.Format(valuesContainer, "null, null")}})] [BenchmarkCategory({{string.Format(valuesContainer, """ "test", null diff --git a/tests/BenchmarkDotNet.Analyzers.Tests/Fixtures/AnalyzerTestFixture.cs b/tests/BenchmarkDotNet.Analyzers.Tests/Fixtures/AnalyzerTestFixture.cs index 7b3cd39fe6..ba8c7c4124 100644 --- a/tests/BenchmarkDotNet.Analyzers.Tests/Fixtures/AnalyzerTestFixture.cs +++ b/tests/BenchmarkDotNet.Analyzers.Tests/Fixtures/AnalyzerTestFixture.cs @@ -187,7 +187,7 @@ protected void ReferenceDummyAttribute() public class DummyAttribute : Attribute { - + } """ );