Skip to content

Commit

Permalink
Fix MSTEST0014 FP with arrays (#2857)
Browse files Browse the repository at this point in the history
  • Loading branch information
Evangelink committed May 16, 2024
1 parent 03eb3e8 commit 4ca86ba
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ private static void AnalyzeAttribute(SymbolAnalysisContext context, AttributeDat
// on the one argument case. Check if we match either of the array argument constructors
// and expand the array argument if we do.
ImmutableArray<TypedConstant> constructorArguments = attribute.ConstructorArguments;
if (constructorArguments[0].Kind is TypedConstantKind.Array && !constructorArguments[0].IsNull)
if (attribute.AttributeConstructor?.Parameters.FirstOrDefault()?.IsParams == true)
{
constructorArguments = constructorArguments[0].Values;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -542,4 +542,25 @@ public void TestSomething(

await VerifyCS.VerifyAnalyzerAsync(code);
}

public async Task Issue2856_ArraysInDataRow_NoDiagnostic()
{
string code = """
using Microsoft.VisualStudio.TestTools.UnitTesting;

[TestClass]
public class MyTestClass
{
[TestMethod]
[DataRow(new int[] { })]
[DataRow(new int[] { 11 })]
[DataRow(new int[] { 11, 1337, 12 })]
public void ItemsTest(int[] input)
{
}
}
""";

await VerifyCS.VerifyAnalyzerAsync(code);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ MSTest.Analyzers.UnitTests.MSTest.Analyzers.Test.ClassInitializeShouldBeValidAna
MSTest.Analyzers.UnitTests.MSTest.Analyzers.Test.ClassInitializeShouldBeValidAnalyzerTests.WhenClassInitializeReturnTypeIsNotValid_Diagnostic()
MSTest.Analyzers.UnitTests.MSTest.Analyzers.Test.ClassInitializeShouldBeValidAnalyzerTests.WhenClassInitializeReturnTypeIsValid_NoDiagnostic()
MSTest.Analyzers.UnitTests.MSTest.Analyzers.Test.DataRowShouldBeValidAnalyzerTests.DefaultArguments()
MSTest.Analyzers.UnitTests.MSTest.Analyzers.Test.DataRowShouldBeValidAnalyzerTests.Issue2856_ArraysInDataRow_NoDiagnostic()
MSTest.Analyzers.UnitTests.MSTest.Analyzers.Test.DataRowShouldBeValidAnalyzerTests.Testfx_2606_NullArgumentForArray()
MSTest.Analyzers.UnitTests.MSTest.Analyzers.Test.DataRowShouldBeValidAnalyzerTests.WhenDataRowHasArgumentMismatchWithTestMethod_Diagnostic()
MSTest.Analyzers.UnitTests.MSTest.Analyzers.Test.DataRowShouldBeValidAnalyzerTests.WhenDataRowHasArgumentMismatchWithTestMethod2_Diagnostic()
Expand Down

0 comments on commit 4ca86ba

Please sign in to comment.