diff --git a/StyleCop.Analyzers/StyleCop.Analyzers.Test/Helpers/DiagnosticVerifier.Helper.cs b/StyleCop.Analyzers/StyleCop.Analyzers.Test/Helpers/DiagnosticVerifier.Helper.cs index 2186a287a..d5b471109 100644 --- a/StyleCop.Analyzers/StyleCop.Analyzers.Test/Helpers/DiagnosticVerifier.Helper.cs +++ b/StyleCop.Analyzers/StyleCop.Analyzers.Test/Helpers/DiagnosticVerifier.Helper.cs @@ -64,10 +64,22 @@ protected static async Task> GetSortedDiagnosticsFrom projects.Add(document.Project); } + var supportedDiagnosticsSpecificOptions = new Dictionary(); + foreach (var diagnostic in analyzer.SupportedDiagnostics) + { + // make sure the analyzers we are testing are enabled + supportedDiagnosticsSpecificOptions[diagnostic.Id] = ReportDiagnostic.Default; + } + var diagnostics = ImmutableArray.CreateBuilder(); foreach (var project in projects) { - var compilation = await project.GetCompilationAsync(cancellationToken).ConfigureAwait(false); + // update the project compilation options + var modifiedSpecificDiagnosticOptions = project.CompilationOptions.SpecificDiagnosticOptions.SetItems(supportedDiagnosticsSpecificOptions); + var modifiedCompilationOptions = project.CompilationOptions.WithSpecificDiagnosticOptions(modifiedSpecificDiagnosticOptions); + var processedProject = project.WithCompilationOptions(modifiedCompilationOptions); + + var compilation = await processedProject.GetCompilationAsync(cancellationToken).ConfigureAwait(false); var compilationWithAnalyzers = compilation.WithAnalyzers(ImmutableArray.Create(analyzer), null, cancellationToken); var compilerDiagnostics = compilation.GetDiagnostics(cancellationToken); var compilerErrors = compilerDiagnostics.Where(i => i.Severity == DiagnosticSeverity.Error);