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

AnalyzerTest.IsSubjectToExclusion constrains DiagnosticsID #535

Closed
ladeak opened this issue May 29, 2020 · 2 comments · Fixed by #569
Closed

AnalyzerTest.IsSubjectToExclusion constrains DiagnosticsID #535

ladeak opened this issue May 29, 2020 · 2 comments · Fixed by #569
Labels
Area-MS.CA.Testing Microsoft.CodeAnalysis.Testing fixed question

Comments

@ladeak
Copy link

ladeak commented May 29, 2020

Visual Studio Community Version 16.6.0 C# Analyzer templates test package uses new packages (version 1.0.1-beta1.*):

Microsoft.CodeAnalysis.CSharp.Analyzer.Testing.MSTest
Microsoft.CodeAnalysis.CSharp.CodeFix.Testing.MSTest
Microsoft.CodeAnalysis.CSharp.CodeRefactoring.Testing.MSTest

The test packages seem to require the Analyzer ID to start with "AD", otherwise AanyzerTests.VerifyDiagnosticsAsync seems to exclude the expected diagnostics:

            var expectedResults = expected
                .Where(x => !IsSubjectToExclusion(x, sources))
                .Select(x => IsInSourceFile(x, sources) ? x.WithLineOffset(1) : x)
                .ToArray();

Stacktrace:

Microsoft.CodeAnalysis.Analyzer.Testing.dll!Microsoft.CodeAnalysis.Testing.AnalyzerTest<Microsoft.CodeAnalysis.Testing.Verifiers.MSTestVerifier>.VerifyGeneratedCodeDiagnosticsAsync(System.Collections.Immutable.ImmutableArray<Microsoft.CodeAnalysis.Diagnostics.DiagnosticAnalyzer> analyzers, (string filename, Microsoft.CodeAnalysis.Text.SourceText content)[] sources, (string filename, Microsoft.CodeAnalysis.Text.SourceText content)[] additionalFiles, Microsoft.CodeAnalysis.Testing.ProjectState[] additionalProjects, Microsoft.CodeAnalysis.MetadataReference[] additionalMetadataReferences, Microsoft.CodeAnalysis.Testing.DiagnosticResult[] expected, Microsoft.CodeAnalysis.Testing.IVerifier verifier, System.Threading.CancellationToken cancellationToken) Line 257	C#
Microsoft.CodeAnalysis.Analyzer.Testing.dll!Microsoft.CodeAnalysis.Testing.AnalyzerTest<Microsoft.CodeAnalysis.Testing.Verifiers.MSTestVerifier>.VerifyDiagnosticsAsync((string filename, Microsoft.CodeAnalysis.Text.SourceText content)[] sources, (string filename, Microsoft.CodeAnalysis.Text.SourceText content)[] additionalFiles, Microsoft.CodeAnalysis.Testing.ProjectState[] additionalProjects, Microsoft.CodeAnalysis.MetadataReference[] additionalMetadataReferences, Microsoft.CodeAnalysis.Testing.DiagnosticResult[] expected, Microsoft.CodeAnalysis.Testing.IVerifier verifier, System.Threading.CancellationToken cancellationToken) Line 238	C#
Microsoft.CodeAnalysis.CodeFix.Testing.dll!Microsoft.CodeAnalysis.Testing.CodeFixTest<Microsoft.CodeAnalysis.Testing.Verifiers.MSTestVerifier>.RunAsync(System.Threading.CancellationToken cancellationToken) Line 226	C#
Microsoft.CodeAnalysis.CodeFix.Testing.dll!Microsoft.CodeAnalysis.Testing.CodeFixVerifier<ConvertNxUnitAnalyzer.ConvertNxUnitAnalyzerAnalyzer, ConvertNxUnitAnalyzer.ConvertNxUnitAnalyzerCodeFixProvider, Microsoft.CodeAnalysis.CSharp.Testing.CSharpCodeFixTest<ConvertNxUnitAnalyzer.ConvertNxUnitAnalyzerAnalyzer, ConvertNxUnitAnalyzer.ConvertNxUnitAnalyzerCodeFixProvider, Microsoft.CodeAnalysis.Testing.Verifiers.MSTestVerifier>, Microsoft.CodeAnalysis.Testing.Verifiers.MSTestVerifier>.VerifyCodeFixAsync(string source, Microsoft.CodeAnalysis.Testing.DiagnosticResult[] expected, string fixedSource) Line 81	C#
Microsoft.CodeAnalysis.CodeFix.Testing.dll!Microsoft.CodeAnalysis.Testing.CodeFixVerifier<ConvertNxUnitAnalyzer.ConvertNxUnitAnalyzerAnalyzer, ConvertNxUnitAnalyzer.ConvertNxUnitAnalyzerCodeFixProvider, Microsoft.CodeAnalysis.CSharp.Testing.CSharpCodeFixTest<ConvertNxUnitAnalyzer.ConvertNxUnitAnalyzerAnalyzer, ConvertNxUnitAnalyzer.ConvertNxUnitAnalyzerCodeFixProvider, Microsoft.CodeAnalysis.Testing.Verifiers.MSTestVerifier>, Microsoft.CodeAnalysis.Testing.Verifiers.MSTestVerifier>.VerifyCodeFixAsync(string source, Microsoft.CodeAnalysis.Testing.DiagnosticResult expected, string fixedSource) Line 61	C#
@sharwell
Copy link
Member

The test packages seem to require the Analyzer ID to start with "AD", otherwise AanyzerTests.VerifyDiagnosticsAsync seems to exclude the expected diagnostics ...

This code is part of VerifyGeneratedCodeDiagnosticsAsync, where the following comment is automatically added to the top of the file:

// <auto-generated>

When this file is present, analyzer diagnostics are generally expected to not be reported because users will not be able to fix them. For additional details and the available approaches to resolve this, see #422 (comment).

@sharwell sharwell added question Area-MS.CA.Testing Microsoft.CodeAnalysis.Testing labels Jun 25, 2020
@sharwell
Copy link
Member

sharwell commented Aug 7, 2020

This was fixed by #569. If the analyzer calls ConfigureGeneratedCodeAnalysis, then the expected test result will adhere to that configuration without needing to specify TestBehaviors.SkipGeneratedCodeCheck.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-MS.CA.Testing Microsoft.CodeAnalysis.Testing fixed question
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants