forked from dotnet/roslyn
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ensure that StructuredAnalyzerConfigOptions contain the diagnostic se…
…verity configuration key-values Existing DiagnosticDescriptorExtensions helper methods rely on these key-value pairs being part of the project analyzer config options, and they seem to have been broken by recent code refactoring that added StructuredAnalyzerConfigOptions. I am also adding a new GetEffectiveSeverity extension method, which is needed by dotnet#58835
- Loading branch information
Showing
3 changed files
with
109 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
src/Workspaces/CoreTest/Options/DiagnosticSeverityOptionsTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Microsoft.CodeAnalysis.Shared.Extensions; | ||
using Microsoft.CodeAnalysis.Test.Utilities; | ||
using Microsoft.CodeAnalysis.Text; | ||
using Roslyn.Test.Utilities; | ||
using Xunit; | ||
using static Microsoft.CodeAnalysis.UnitTests.SolutionTestHelpers; | ||
|
||
namespace Microsoft.CodeAnalysis.UnitTests.Options | ||
{ | ||
[UseExportProvider] | ||
[Trait(Traits.Feature, Traits.Features.Workspace)] | ||
public class DiagnosticSeverityOptionsTests : TestBase | ||
{ | ||
[Theory] | ||
[InlineData("dotnet_diagnostic.ID1000.severity = error")] | ||
[InlineData("dotnet_analyzer_diagnostic.severity = error")] | ||
public async Task TestGetEffectiveSeverityFromProjectOptions(string editorConfigEntry) | ||
{ | ||
using var workspace = CreateWorkspace(); | ||
|
||
var projectId = ProjectId.CreateNewId(); | ||
var project = workspace.CurrentSolution | ||
.AddProject(projectId, "proj1", "proj1.dll", LanguageNames.CSharp) | ||
.AddDocument(DocumentId.CreateNewId(projectId), "goo.cs", SourceText.From("public class Goo { }", Encoding.UTF8, SourceHashAlgorithms.Default), filePath: @"z:\\goo.cs") | ||
.Projects.Single(); | ||
|
||
var analyzerConfigText = $@" | ||
[*.cs] | ||
{editorConfigEntry} | ||
"; | ||
project = project.AddAnalyzerConfigDocument(".editorconfig", SourceText.From(analyzerConfigText), filePath: @"z:\\.editorconfig").Project; | ||
|
||
workspace.TryApplyChanges(project.Solution); | ||
|
||
var document = project.Documents.Single(); | ||
var tree = await document.GetSyntaxTreeAsync(); | ||
var analyzerConfigOptions = project.AnalyzerOptions.AnalyzerConfigOptionsProvider.GetOptions(tree); | ||
|
||
var descriptor = new DiagnosticDescriptor("ID1000", "Title", "Message", "Category", DiagnosticSeverity.Warning, isEnabledByDefault: true); | ||
Assert.Equal(ReportDiagnostic.Error, descriptor.GetEffectiveSeverity(analyzerConfigOptions)); | ||
|
||
var compilation = await project.GetCompilationAsync(); | ||
Assert.Equal(ReportDiagnostic.Error, descriptor.GetEffectiveSeverity(compilation.Options, tree, project.AnalyzerOptions)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters