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

Added support for diagnostic suppressors #2182

Merged
merged 7 commits into from
Jun 30, 2021
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
added test for analyzer suppressors
  • Loading branch information
filipw committed Jun 28, 2021
commit bff730182b673e4a38e8f52f84ce7f06fa1e3b8d
26 changes: 26 additions & 0 deletions tests/OmniSharp.MSBuild.Tests/ProjectWithAnalyzersTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,32 @@ public async Task WhenNewAnalyzerReferenceIsAdded_ThenAutomaticallyUseItWithoutR
}
}

[Fact]
public async Task WhenProjectIsLoadedThenItRespectsDiagnosticSuppressors()
{
using (var testProject = await TestAssets.Instance.GetTestProjectAsync("TwoProjectsWithAnalyzerSuppressor"))
using (var host = CreateMSBuildTestHost(testProject.Directory, configurationData: TestHelpers.GetConfigurationDataWithAnalyzerConfig(roslynAnalyzersEnabled: true)))
{
var project = host.Workspace.CurrentSolution.Projects.First(p => p.Name == "App");

// by default Stylecop reported diagnostics should be:
// - The file header is missing or not located at the top of the file. [App] SA1633
// - Elements should be documented [App] SA1600
// - Element 'Program' should declare an access modifier [App] SA1400
// - Element 'Main' should declare an access modifier [App] SA1400
// However, SA1200 should be suppressed

var diagnostics = await host.RequestCodeCheckAsync(Path.Combine(testProject.Directory, "App", "Program.cs"));

Assert.NotEmpty(diagnostics.QuickFixes);

Assert.Contains(diagnostics.QuickFixes.OfType<DiagnosticLocation>(), x => x.Id == "SA1633" && x.LogLevel == "Warning");
Assert.Contains(diagnostics.QuickFixes.OfType<DiagnosticLocation>(), x => x.Id == "SA1600" && x.LogLevel == "Warning");
Assert.Contains(diagnostics.QuickFixes.OfType<DiagnosticLocation>(), x => x.Id == "SA1400" && x.LogLevel == "Warning");
Assert.DoesNotContain(diagnostics.QuickFixes.OfType<DiagnosticLocation>(), x => x.Id == "SA1200");
}
}

private string ModifyXmlFileInPlace(string file, Action<XDocument> docUpdateAction)
{
var xmlFile = XDocument.Load(file);
Expand Down