Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix MSTEST0014 FP with arrays #2857

Merged
merged 2 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading