Skip to content

Commit

Permalink
Update tests to account for test SDK behavior changes
Browse files Browse the repository at this point in the history
  • Loading branch information
sharwell committed Jun 23, 2023
1 parent 1fa5f82 commit 7366919
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/Test.Utilities/CSharpCodeFixVerifier`2+Test.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the MIT license. See License.txt in the project root for license information.

using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Net;
using Analyzer.Utilities.Extensions;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CodeFixes;
using Microsoft.CodeAnalysis.CSharp;
Expand Down Expand Up @@ -59,6 +61,20 @@ protected override CompilationOptions CreateCompilationOptions()
compilationOptions.SpecificDiagnosticOptions.SetItems(NullableWarnings));
}

protected override ImmutableArray<(Project project, Diagnostic diagnostic)> SortDistinctDiagnostics(IEnumerable<(Project project, Diagnostic diagnostic)> diagnostics)
{
var baseResult = base.SortDistinctDiagnostics(diagnostics);
if (typeof(DiagnosticSuppressor).IsAssignableFrom(typeof(TAnalyzer)))
{
// Include suppressed diagnostics when testing diagnostic suppressors
return baseResult;
}

// Treat suppressed diagnostics as non-existent. Normally this wouldn't be necessary, but some of the
// tests include diagnostics reported in code wrapped in '#pragma warning disable'.
return baseResult.WhereAsArray(diagnostic => !diagnostic.diagnostic.IsSuppressed);
}

protected override ParseOptions CreateParseOptions()
{
return ((CSharpParseOptions)base.CreateParseOptions()).WithLanguageVersion(LanguageVersion);
Expand Down
17 changes: 17 additions & 0 deletions src/Test.Utilities/VisualBasicCodeFixVerifier`2+Test.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the MIT license. See License.txt in the project root for license information.

using System.Collections.Generic;
using System.Collections.Immutable;
using Analyzer.Utilities.Extensions;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CodeFixes;
using Microsoft.CodeAnalysis.Diagnostics;
Expand All @@ -26,6 +29,20 @@ protected override ParseOptions CreateParseOptions()
{
return ((VisualBasicParseOptions)base.CreateParseOptions()).WithLanguageVersion(LanguageVersion);
}

protected override ImmutableArray<(Project project, Diagnostic diagnostic)> SortDistinctDiagnostics(IEnumerable<(Project project, Diagnostic diagnostic)> diagnostics)
{
var baseResult = base.SortDistinctDiagnostics(diagnostics);
if (typeof(DiagnosticSuppressor).IsAssignableFrom(typeof(TAnalyzer)))
{
// Include suppressed diagnostics when testing diagnostic suppressors
return baseResult;
}

// Treat suppressed diagnostics as non-existent. Normally this wouldn't be necessary, but some of the
// tests include diagnostics reported in code wrapped in '#Disable Warning'.
return baseResult.WhereAsArray(diagnostic => !diagnostic.diagnostic.IsSuppressed);
}
}
}
}

0 comments on commit 7366919

Please sign in to comment.