using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; using System; using System.Collections.Immutable; namespace Misaki.HighPerformance.Analyzer.Test { internal static class CSharpVerifierHelper { /// /// By default, the compiler reports diagnostics for nullable reference types at /// , and the analyzer test framework defaults to only validating /// diagnostics at . This map contains all compiler diagnostic IDs /// related to nullability mapped to , which is then used to enable all /// of these warnings for default validation during analyzer and code fix tests. /// internal static ImmutableDictionary NullableWarnings { get; } = GetNullableWarningsFromCompiler(); private static ImmutableDictionary GetNullableWarningsFromCompiler() { string[] args = { "/warnaserror:nullable" }; var commandLineArguments = CSharpCommandLineParser.Default.Parse(args, baseDirectory: Environment.CurrentDirectory, sdkDirectory: Environment.CurrentDirectory); var nullableWarnings = commandLineArguments.CompilationOptions.SpecificDiagnosticOptions; // Workaround for https://github.com/dotnet/roslyn/issues/41610 nullableWarnings = nullableWarnings .SetItem("CS8632", ReportDiagnostic.Error) .SetItem("CS8669", ReportDiagnostic.Error); return nullableWarnings; } } }