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

Add composite analyzer to test all analyzers #128

Merged
merged 1 commit into from
Jun 25, 2024

Conversation

rjmurillo
Copy link
Owner

@rjmurillo rjmurillo commented Jun 25, 2024

Adds new type CompositeAnalyzer that inherits from DiagnosticAnalyzer. This new analyzer uses reflection to load all types in the Moq.Analyzers assembly that derive from DiagnosticAnalyzer, are not abstract, and are classes.

The intended use is for diagnostic purposes

using Verifier = Moq.Analyzers.Test.Helpers.AnalyzerVerifier<Moq.Analyzers.Test.CompositeAnalyzer>;

namespace Moq.Analyzers.Test;

public class FooAnalyzerTests
{
    public static IEnumerable<object[]> TestData()
    {
        return new object[][]
        {
            ["""new Mock<TestClass>(MockBehavior.Strict).Object.TaskAsync();"""],
        }.WithNamespaces().WithReferenceAssemblyGroups();
    }

    [Theory]
    [MemberData(nameof(TestData))]
    public async Task Bar(string referenceAssemblyGroup, string @namespace, string mock)
    {
        await Verifier.VerifyAnalyzerAsync(
            $$"""
              {{@namespace}}

              public class TestClass
              {
                  public virtual Task TaskAsync() => Task.CompletedTask;
              }

              internal class UnitTest
              {
                  private void Test()
                  {
                      {{mock}}
                  }
              }
              """,
            referenceAssemblyGroup);
    }
}

Copy link

Coverage summary from Codacy

See diff coverage on Codacy

Coverage variation Diff coverage
+0.00% (target: -1.00%) (target: 95.00%)
Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (9b41015) 460 425 92.39%
Head commit (8e7511c) 460 (+0) 425 (+0) 92.39% (+0.00%)

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#128) 0 0 ∅ (not applicable)

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

See your quality gate settings    Change summary preferences


🚀 Don’t miss a bit, follow what’s new on Codacy.

Codacy stopped sending the deprecated coverage status on June 5th, 2024. Learn more

@rjmurillo rjmurillo added this to the 0.2.0 milestone Jun 25, 2024
@rjmurillo rjmurillo requested a review from MattKotsenas June 25, 2024 22:12
@rjmurillo rjmurillo marked this pull request as ready for review June 25, 2024 22:15
@rjmurillo rjmurillo enabled auto-merge (squash) June 25, 2024 22:15
@rjmurillo rjmurillo merged commit 8e5fab4 into main Jun 25, 2024
7 checks passed
@rjmurillo rjmurillo deleted the feature/add-composite-analyzer-for-test branch June 25, 2024 23:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants