Skip to content

Commit

Permalink
Unskip NRT suppression tests (#28308)
Browse files Browse the repository at this point in the history
Closes #27895
  • Loading branch information
roji committed Jun 24, 2022
1 parent d42e736 commit 781ca24
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 17 deletions.
2 changes: 1 addition & 1 deletion eng/Versions.props
Expand Up @@ -26,6 +26,6 @@
<MicrosoftExtensionsLoggingVersion>7.0.0-preview.6.22319.5</MicrosoftExtensionsLoggingVersion>
</PropertyGroup>
<PropertyGroup Label="Other dependencies">
<MicrosoftCodeAnalysisVersion>4.1.0</MicrosoftCodeAnalysisVersion>
<MicrosoftCodeAnalysisVersion>4.2.0</MicrosoftCodeAnalysisVersion>
</PropertyGroup>
</Project>
Expand Up @@ -12,7 +12,7 @@ namespace Microsoft.EntityFrameworkCore;
public sealed class UninitializedDbSetDiagnosticSuppressor : DiagnosticSuppressor
{
private static readonly SuppressionDescriptor SuppressUninitializedDbSetRule = new(
id: "SPR1001",
id: "EFSPR1001",
suppressedDiagnosticId: "CS8618",
justification: AnalyzerStrings.UninitializedDbSetWarningSuppressionJustification);

Expand Down Expand Up @@ -70,7 +70,7 @@ public override void ReportSuppressions(SuppressionAnalysisContext context)
if (propertySymbol.Type.OriginalDefinition.Equals(dbSetTypeSymbol, SymbolEqualityComparer.Default)
&& InheritsFrom(propertySymbol.ContainingType, dbContextTypeSymbol))
{
context.ReportSuppression(Suppression.Create(SupportedSuppressions[0], diagnostic));
context.ReportSuppression(Suppression.Create(SuppressUninitializedDbSetRule, diagnostic));
}

static bool InheritsFrom(ITypeSymbol typeSymbol, ITypeSymbol baseTypeSymbol)
Expand Down
Expand Up @@ -7,6 +7,7 @@
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Text;
using Microsoft.Extensions.DependencyModel;
using CompilationOptions = Microsoft.CodeAnalysis.CompilationOptions;

namespace Microsoft.EntityFrameworkCore.TestUtilities;

Expand Down Expand Up @@ -59,11 +60,13 @@ protected async Task<Diagnostic[]> GetDiagnosticsFullSourceAsync(string source,
var analyzer = CreateDiagnosticAnalyzer();
var compilationWithAnalyzers
= compilation
.WithOptions(
compilation.Options.WithSpecificDiagnosticOptions(
compilation.Options.SpecificDiagnosticOptions
.AddRange(analyzer.SupportedDiagnostics.ToDictionary(d => d.Id, d => ReportDiagnostic.Default))))
.WithAnalyzers(ImmutableArray.Create(analyzer));
.WithAnalyzers(ImmutableArray.Create(analyzer),
new CompilationWithAnalyzersOptions(
new AnalyzerOptions(new()),
onAnalyzerException: null,
concurrentAnalysis: false,
logAnalyzerExecutionTime: false,
reportSuppressedDiagnostics: true));

var diagnostics = analyzerDiagnosticsOnly
? await compilationWithAnalyzers.GetAnalyzerDiagnosticsAsync()
Expand Down
@@ -1,11 +1,8 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Threading.Tasks;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.EntityFrameworkCore.TestUtilities;
using Xunit;

namespace Microsoft.EntityFrameworkCore;

Expand Down Expand Up @@ -165,9 +162,7 @@ public class Blog
var diagnostic = Assert.Single(await GetDiagnosticsFullSourceAsync(source));

Assert.Equal("CS8618", diagnostic.Id);

// Suppression does work, but not in tests because of #27895
Assert.False(diagnostic.IsSuppressed);
Assert.True(diagnostic.IsSuppressed);
}

[ConditionalFact]
Expand Down Expand Up @@ -195,9 +190,7 @@ public class Blog
diagnostic =>
{
Assert.Equal("CS8618", diagnostic.Id);
// Suppression does work, but not in tests because of #27895
Assert.False(diagnostic.IsSuppressed);
Assert.True(diagnostic.IsSuppressed);
});
}

Expand Down

0 comments on commit 781ca24

Please sign in to comment.