/// <summary> /// Verifies that <paramref name="code"/> produces no diagnostics when analyzed with <paramref name="analyzer"/>. /// </summary> /// <param name="analyzer">The analyzer.</param> /// <param name="code">The code to analyze.</param> public static void Valid(DiagnosticAnalyzer analyzer, IReadOnlyList <string> code) { var sln = CodeFactory.CreateSolution(code, CodeFactory.DefaultCompilationOptions(analyzer, SuppressedDiagnostics), MetadataReferences); var diagnosticsAndErrors = Analyze.GetDiagnosticsAndErrors(analyzer, sln); NoDiagnosticsOrErrors(diagnosticsAndErrors); }
/// <summary> /// Verifies that <paramref name="code"/> produces no diagnostics when analyzed with <paramref name="analyzer"/>. /// </summary> /// <param name="analyzer">The analyzer.</param> /// <param name="code">The code to analyze.</param> /// <param name="compilationOptions">The <see cref="CSharpCompilationOptions"/> to use.</param> /// <param name="metadataReferences">The metadata references to use when compiling.</param> public static void Valid(DiagnosticAnalyzer analyzer, IReadOnlyList <string> code, CSharpCompilationOptions compilationOptions, IEnumerable <MetadataReference> metadataReferences) { var sln = CodeFactory.CreateSolution(code, compilationOptions, metadataReferences); var diagnosticsAndErrors = Analyze.GetDiagnosticsAndErrors(analyzer, sln); NoDiagnosticsOrErrors(diagnosticsAndErrors); }
/// <summary> /// Verifies that <paramref name="code"/> produces no diagnostics when analyzed with <paramref name="analyzer"/>. /// </summary> /// <param name="analyzer">The analyzer.</param> /// <param name="descriptor">The expected diagnostic.</param> /// <param name="code"> /// The code to create the solution from. /// Can be a .cs, .csproj or .sln file. /// </param> public static void Valid(DiagnosticAnalyzer analyzer, DiagnosticDescriptor descriptor, FileInfo code) { VerifyAnalyzerSupportsDiagnostic(analyzer, descriptor); var sln = CodeFactory.CreateSolution(code, CodeFactory.DefaultCompilationOptions(analyzer, descriptor, SuppressedDiagnostics), MetadataReferences); var diagnosticsAndErrors = Analyze.GetDiagnosticsAndErrors(analyzer, sln); NoDiagnosticsOrErrors(diagnosticsAndErrors); }
/// <summary> /// Verifies that <paramref name="code"/> produces no diagnostics when analyzed with <paramref name="analyzer"/>. /// </summary> /// <param name="analyzer">The analyzer.</param> /// <param name="descriptors">The expected diagnostic.</param> /// <param name="code">The code to analyze.</param> public static void Valid(DiagnosticAnalyzer analyzer, IReadOnlyList <DiagnosticDescriptor> descriptors, params string[] code) { VerifyAnalyzerSupportsDiagnostics(analyzer, descriptors); var sln = CodeFactory.CreateSolution(code, CodeFactory.DefaultCompilationOptions(analyzer, descriptors, SuppressedDiagnostics), MetadataReferences); var diagnosticsAndErrors = Analyze.GetDiagnosticsAndErrors(analyzer, sln); NoDiagnosticsOrErrors(diagnosticsAndErrors); }
/// <summary> /// Verifies that <paramref name="code"/> produces no diagnostics when analyzed with <paramref name="analyzer"/>. /// </summary> /// <param name="analyzer">The analyzer.</param> /// <param name="code">The code to analyze.</param> /// <param name="compilationOptions">The <see cref="CSharpCompilationOptions"/> to use.</param> /// <param name="metadataReferences">The metadata references to use when compiling.</param> public static void Valid(DiagnosticAnalyzer analyzer, string code, CSharpCompilationOptions compilationOptions = null, IEnumerable <MetadataReference> metadataReferences = null) { var sln = CodeFactory.CreateSolution( code, compilationOptions ?? CodeFactory.DefaultCompilationOptions(analyzer, SuppressedDiagnostics), metadataReferences ?? MetadataReferences); var diagnosticsAndErrors = Analyze.GetDiagnosticsAndErrors(analyzer, sln); NoDiagnosticsOrErrors(diagnosticsAndErrors); }
/// <summary> /// Verifies that <paramref name="solution"/> produces no diagnostics when analyzed with <paramref name="analyzer"/>. /// </summary> /// <param name="analyzer">The <see cref="DiagnosticAnalyzer"/> to check <paramref name="solution"/> with.</param> /// <param name="solution">The <see cref="Solution"/> for which no errors or warnings are expected.</param> public static void Valid(DiagnosticAnalyzer analyzer, Solution solution) { var diagnosticsAndErrors = Analyze.GetDiagnosticsAndErrors(analyzer, solution); NoDiagnosticsOrErrors(diagnosticsAndErrors); }