From 0db321a7c5ec31bcbec5abdd986178bcb73900af Mon Sep 17 00:00:00 2001 From: Meir Blachman Date: Fri, 13 Sep 2024 13:59:02 +0300 Subject: [PATCH 1/3] chore: update dependencies --- src/Directory.Packages.props | 31 +++++++++---------- ...luentAssertionAnalyzerDocsGenerator.csproj | 1 - 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/src/Directory.Packages.props b/src/Directory.Packages.props index a0fb042..5188f22 100644 --- a/src/Directory.Packages.props +++ b/src/Directory.Packages.props @@ -3,28 +3,27 @@ true - - - + + - + - - - + + + - - - + + + - - - + + + - - + + - + \ No newline at end of file diff --git a/src/FluentAssertions.Analyzers.FluentAssertionAnalyzerDocsGenerator/FluentAssertions.Analyzers.FluentAssertionAnalyzerDocsGenerator.csproj b/src/FluentAssertions.Analyzers.FluentAssertionAnalyzerDocsGenerator/FluentAssertions.Analyzers.FluentAssertionAnalyzerDocsGenerator.csproj index 7bfd7b9..2d12763 100644 --- a/src/FluentAssertions.Analyzers.FluentAssertionAnalyzerDocsGenerator/FluentAssertions.Analyzers.FluentAssertionAnalyzerDocsGenerator.csproj +++ b/src/FluentAssertions.Analyzers.FluentAssertionAnalyzerDocsGenerator/FluentAssertions.Analyzers.FluentAssertionAnalyzerDocsGenerator.csproj @@ -6,7 +6,6 @@ - From aa0dae22cf2ecf81a929ce7506f09fd6f823e927 Mon Sep 17 00:00:00 2001 From: Meir Blachman Date: Fri, 13 Sep 2024 14:12:48 +0300 Subject: [PATCH 2/3] chore: update dependencies --- .../TestAttributes.cs | 48 ++++++++++++------- .../Tips/CollectionTests.cs | 18 ++++--- 2 files changed, 40 insertions(+), 26 deletions(-) diff --git a/src/FluentAssertions.Analyzers.Tests/TestAttributes.cs b/src/FluentAssertions.Analyzers.Tests/TestAttributes.cs index c43a275..23af005 100644 --- a/src/FluentAssertions.Analyzers.Tests/TestAttributes.cs +++ b/src/FluentAssertions.Analyzers.Tests/TestAttributes.cs @@ -26,14 +26,10 @@ public class AssertionDiagnosticAttribute : Attribute, ITestDataSource { public string Assertion { get; } - public bool Ignore { get; } - - public AssertionDiagnosticAttribute(string assertion, bool ignore = false) => (Assertion, Ignore) = (assertion, ignore); + public AssertionDiagnosticAttribute(string assertion) => Assertion = assertion; public IEnumerable GetData(MethodInfo methodInfo) { - if (Ignore) yield break; - foreach (var assertion in TestCasesInputUtils.GetTestCases(Assertion)) { yield return new object[] { assertion }; @@ -43,20 +39,24 @@ public IEnumerable GetData(MethodInfo methodInfo) public string GetDisplayName(MethodInfo methodInfo, object[] data) => $"{methodInfo.Name}(\"{data[0]}\")"; } +[AttributeUsage(AttributeTargets.Method, AllowMultiple = true)] +public class IgnoreAssertionDiagnosticAttribute : Attribute +{ + public string Assertion { get; } + + public IgnoreAssertionDiagnosticAttribute(string assertion) => Assertion = assertion; +} + [AttributeUsage(AttributeTargets.Method, AllowMultiple = true)] public class AssertionCodeFixAttribute : Attribute, ITestDataSource { public string OldAssertion { get; } public string NewAssertion { get; } - public bool Ignore { get; } - - public AssertionCodeFixAttribute(string oldAssertion, string newAssertion, bool ignore = false) => (OldAssertion, NewAssertion, Ignore) = (oldAssertion, newAssertion, ignore); + public AssertionCodeFixAttribute(string oldAssertion, string newAssertion) => (OldAssertion, NewAssertion) = (oldAssertion, newAssertion); public IEnumerable GetData(MethodInfo methodInfo) { - if (Ignore) yield break; - foreach (var (oldAssertion, newAssertion) in TestCasesInputUtils.GetTestCases(OldAssertion, NewAssertion)) { yield return new object[] { oldAssertion, newAssertion }; @@ -66,6 +66,15 @@ public IEnumerable GetData(MethodInfo methodInfo) public string GetDisplayName(MethodInfo methodInfo, object[] data) => $"{methodInfo.Name}(\"old: {data[0]}\", new: {data[1]}\")"; } +[AttributeUsage(AttributeTargets.Method, AllowMultiple = true)] +public class IgnoreAssertionCodeFixAttribute : Attribute +{ + public string OldAssertion { get; } + public string NewAssertion { get; } + + public IgnoreAssertionCodeFixAttribute(string oldAssertion, string newAssertion) => (OldAssertion, NewAssertion) = (oldAssertion, newAssertion); +} + [AttributeUsage(AttributeTargets.Method, AllowMultiple = true)] public class AssertionMethodCodeFixAttribute : Attribute, ITestDataSource { @@ -73,15 +82,11 @@ public class AssertionMethodCodeFixAttribute : Attribute, ITestDataSource public string OldAssertion { get; } public string NewAssertion { get; } - public bool Ignore { get; } - - public AssertionMethodCodeFixAttribute(string methodArguments, string oldAssertion, string newAssertion, bool ignore = false) - => (MethodArguments, OldAssertion, NewAssertion, Ignore) = (methodArguments, oldAssertion, newAssertion, ignore); + public AssertionMethodCodeFixAttribute(string methodArguments, string oldAssertion, string newAssertion) + => (MethodArguments, OldAssertion, NewAssertion) = (methodArguments, oldAssertion, newAssertion); public IEnumerable GetData(MethodInfo methodInfo) { - if (Ignore) yield break; - foreach (var (oldAssertion, newAssertion) in TestCasesInputUtils.GetTestCases(OldAssertion, NewAssertion)) { yield return new object[] { MethodArguments, oldAssertion, newAssertion }; @@ -91,6 +96,17 @@ public IEnumerable GetData(MethodInfo methodInfo) public string GetDisplayName(MethodInfo methodInfo, object[] data) => $"{methodInfo.Name}(\"arguments\":{data[0]}, \"old: {data[1]}\", new: {data[2]}\")"; } +[AttributeUsage(AttributeTargets.Method, AllowMultiple = true)] +public class IgnoreAssertionMethodCodeFixAttribute : Attribute +{ + public string MethodArguments { get; } + public string OldAssertion { get; } + public string NewAssertion { get; } + + public IgnoreAssertionMethodCodeFixAttribute(string methodArguments, string oldAssertion, string newAssertion) + => (MethodArguments, OldAssertion, NewAssertion) = (methodArguments, oldAssertion, newAssertion); +} + public static class TestCasesInputUtils { private static readonly string Empty = string.Empty; diff --git a/src/FluentAssertions.Analyzers.Tests/Tips/CollectionTests.cs b/src/FluentAssertions.Analyzers.Tests/Tips/CollectionTests.cs index 98f5cbb..8048c5b 100644 --- a/src/FluentAssertions.Analyzers.Tests/Tips/CollectionTests.cs +++ b/src/FluentAssertions.Analyzers.Tests/Tips/CollectionTests.cs @@ -185,10 +185,10 @@ public class CollectionTests public void CollectionShouldNotContainProperty_WhereShouldBeEmpty_TestAnalyzer(string assertion) => VerifyCSharpDiagnosticCodeBlock(assertion, DiagnosticMetadata.CollectionShouldNotContainProperty_WhereShouldBeEmpty); [DataTestMethod] - [AssertionDiagnostic("actual.Should().OnlyContain(x => !x.BooleanProperty{0});", ignore: true)] - [AssertionDiagnostic("actual.AsEnumerable().Should().OnlyContain(x => !x.BooleanProperty{0}).And.ToString();", ignore: true)] - [AssertionDiagnostic("actual.ToArray().Should().OnlyContain(x => !x.BooleanProperty{0}).And.ToString();", ignore: true)] - [AssertionDiagnostic("actual.ToList().Should().OnlyContain(x => !x.BooleanProperty{0}).And.ToString();", ignore: true)] + [IgnoreAssertionDiagnostic("actual.Should().OnlyContain(x => !x.BooleanProperty{0});")] + [IgnoreAssertionDiagnostic("actual.AsEnumerable().Should().OnlyContain(x => !x.BooleanProperty{0}).And.ToString();")] + [IgnoreAssertionDiagnostic("actual.ToArray().Should().OnlyContain(x => !x.BooleanProperty{0}).And.ToString();")] + [IgnoreAssertionDiagnostic("actual.ToList().Should().OnlyContain(x => !x.BooleanProperty{0}).And.ToString();")] [Implemented] public void CollectionShouldNotContainProperty_ShouldOnlyContainNot_TestAnalyzer(string assertion) => VerifyCSharpDiagnosticCodeBlock(assertion, DiagnosticMetadata.CollectionShouldNotContainProperty_ShouldOnlyContainNot); @@ -199,20 +199,18 @@ public class CollectionTests [AssertionCodeFix( oldAssertion: "actual.Where(x => x.BooleanProperty).Should().BeEmpty({0});", newAssertion: "actual.Should().NotContain(x => x.BooleanProperty{0});")] - [AssertionCodeFix( + [IgnoreAssertionCodeFix( oldAssertion: "actual.Should().OnlyContain(x => !x.BooleanProperty{0});", - newAssertion: "actual.Should().NotContain(x => x.BooleanProperty{0});", - ignore: true)] + newAssertion: "actual.Should().NotContain(x => x.BooleanProperty{0});")] [AssertionCodeFix( oldAssertion: "actual.AsEnumerable().Any(x => x.BooleanProperty).Should().BeFalse({0}).And.ToString();", newAssertion: "actual.AsEnumerable().Should().NotContain(x => x.BooleanProperty{0}).And.ToString();")] [AssertionCodeFix( oldAssertion: "actual.AsEnumerable().Where(x => x.BooleanProperty).Should().BeEmpty({0}).And.ToString();", newAssertion: "actual.AsEnumerable().Should().NotContain(x => x.BooleanProperty{0}).And.ToString();")] - [AssertionCodeFix( + [IgnoreAssertionCodeFix( oldAssertion: "actual.AsEnumerable().Should().OnlyContain(x => !x.BooleanProperty{0}).And.ToString();", - newAssertion: "actual.AsEnumerable().Should().NotContain(x => x.BooleanProperty{0}).And.ToString();", - ignore: true)] + newAssertion: "actual.AsEnumerable().Should().NotContain(x => x.BooleanProperty{0}).And.ToString();")] [Implemented] public void CollectionShouldNotContainProperty_TestCodeFix(string oldAssertion, string newAssertion) => VerifyCSharpFixCodeBlock(oldAssertion, newAssertion); From 7bde90173bf328a45a2259c028ae8c97bb700beb Mon Sep 17 00:00:00 2001 From: Meir Blachman Date: Fri, 13 Sep 2024 16:05:23 +0300 Subject: [PATCH 3/3] chore: update dependencies --- src/FluentAssertions.Analyzers.Tests/Tips/CollectionTests.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/FluentAssertions.Analyzers.Tests/Tips/CollectionTests.cs b/src/FluentAssertions.Analyzers.Tests/Tips/CollectionTests.cs index 8048c5b..20310a3 100644 --- a/src/FluentAssertions.Analyzers.Tests/Tips/CollectionTests.cs +++ b/src/FluentAssertions.Analyzers.Tests/Tips/CollectionTests.cs @@ -184,7 +184,8 @@ public class CollectionTests [Implemented] public void CollectionShouldNotContainProperty_WhereShouldBeEmpty_TestAnalyzer(string assertion) => VerifyCSharpDiagnosticCodeBlock(assertion, DiagnosticMetadata.CollectionShouldNotContainProperty_WhereShouldBeEmpty); - [DataTestMethod] + // TODO: all test cases are ignored + // [DataTestMethod] [IgnoreAssertionDiagnostic("actual.Should().OnlyContain(x => !x.BooleanProperty{0});")] [IgnoreAssertionDiagnostic("actual.AsEnumerable().Should().OnlyContain(x => !x.BooleanProperty{0}).And.ToString();")] [IgnoreAssertionDiagnostic("actual.ToArray().Should().OnlyContain(x => !x.BooleanProperty{0}).And.ToString();")]