private void RunWithDiagnosticAnnotations(string bicepText, Func <IDiagnostic, bool> filterFunc, OnCompileErrors onCompileErrors, Action <IEnumerable <IDiagnostic> > assertAction) { using (AssertionScope scope = new AssertionScope()) { scope.AddReportable("bicep code", bicepText); var result = CompilationHelper.Compile(bicepText); result.Should().NotHaveDiagnosticsWithCodes(new[] { LinterAnalyzer.LinterRuleInternalError }, "There should never be linter LinterRuleInternalError errors"); if (onCompileErrors == OnCompileErrors.Fail) { var compileErrors = result.Diagnostics.Where(d => d.Level == DiagnosticLevel.Error); DiagnosticAssertions.DoWithDiagnosticAnnotations( result.Compilation.SourceFileGrouping.EntryPoint, compileErrors, diags => diags.Should().HaveCount(0)); } IDiagnostic[] diagnosticsMatchingCode = result.Diagnostics.Where(filterFunc).ToArray(); DiagnosticAssertions.DoWithDiagnosticAnnotations( result.Compilation.SourceFileGrouping.EntryPoint, result.Diagnostics.Where(filterFunc), assertAction); } }
private void DoWithDiagnosticAnnotations(string text, Func <IDiagnostic, bool> filterFunc, Action <IEnumerable <IDiagnostic> > assertAction) { var result = CompilationHelper.Compile(text); result.Should().NotHaveDiagnosticsWithCodes(new [] { LinterAnalyzer.FailedRuleCode }, "There should never be linter FailedRuleCode errors"); DiagnosticAssertions.DoWithDiagnosticAnnotations( result.Compilation.SourceFileGrouping.EntryPoint, result.Diagnostics.Where(filterFunc), assertAction); }