Exemple #1
0
        private static async Task AssertNoCompilerErrorsAsync(CodeFixProvider codeFix, Solution fixedSolution)
        {
            var diagnostics = await Analyze.GetDiagnosticsAsync(fixedSolution).ConfigureAwait(false);

            var introducedDiagnostics = diagnostics
                                        .SelectMany(x => x)
                                        .Where(IsIncluded)
                                        .ToArray();

            if (introducedDiagnostics.Select(x => x.Id)
                .Except(DiagnosticSettings.AllowedErrorIds())
                .Any())
            {
                var errorBuilder = StringBuilderPool.Borrow();
                errorBuilder.AppendLine($"{codeFix} introduced syntax error{(introducedDiagnostics.Length > 1 ? "s" : string.Empty)}.");
                foreach (var introducedDiagnostic in introducedDiagnostics)
                {
                    var errorInfo = await introducedDiagnostic.ToStringAsync(fixedSolution).ConfigureAwait(false);

                    errorBuilder.AppendLine($"{errorInfo}");
                }

                errorBuilder.AppendLine("First source file with error is:");
                var sources = await Task.WhenAll(fixedSolution.Projects.SelectMany(p => p.Documents).Select(d => CodeReader.GetStringFromDocumentAsync(d, Formatter.Annotation, CancellationToken.None)));

                var lineSpan = introducedDiagnostics.First().Location.GetMappedLineSpan();
                var match    = sources.SingleOrDefault(x => CodeReader.FileName(x) == lineSpan.Path);
                errorBuilder.Append(match);
                errorBuilder.AppendLine();
                throw AssertException.Create(errorBuilder.Return());
            }
        }
Exemple #2
0
 /// <summary>
 /// Resets <see cref="SuppressedDiagnostics"/> to <see cref="DiagnosticSettings.AllowedErrorIds()"/>
 /// </summary>
 public static void ResetSuppressedDiagnostics()
 {
     SuppressedDiagnostics.Clear();
     SuppressedDiagnostics.AddRange(DiagnosticSettings.AllowedErrorIds());
 }
 /// <summary>
 /// Check the solution for compiler errors and warnings, uses:
 /// DiagnosticSettings.AllowedErrorIds()
 /// DiagnosticSettings.AllowedDiagnostics().
 /// </summary>
 public static void NoCompilerErrors(Solution solution)
 {
     NoCompilerErrors(solution, DiagnosticSettings.AllowedErrorIds(), DiagnosticSettings.AllowedDiagnostics());
 }
        /// <summary>
        /// Check the solution for compiler errors and warnings, uses:
        /// DiagnosticSettings.AllowedErrorIds()
        /// DiagnosticSettings.AllowedDiagnostics().
        /// </summary>
        public static void NoCompilerErrors(IEnumerable <MetadataReference> metadataReferences, params string[] code)
        {
            var solution = CodeFactory.CreateSolution(code, metadataReferences);

            NoCompilerErrors(solution, DiagnosticSettings.AllowedErrorIds(), DiagnosticSettings.AllowedDiagnostics());
        }
Exemple #5
0
 /// <summary>
 /// Check the solution for compiler errors and warnings, uses:
 /// DiagnosticSettings.AllowedErrorIds()
 /// DiagnosticSettings.AllowedDiagnostics()
 /// </summary>
 public static Task NoCompilerErrorsAsync(Solution solution)
 {
     return(NoCompilerErrorsAsync(solution, DiagnosticSettings.AllowedErrorIds(), DiagnosticSettings.AllowedDiagnostics()));
 }
Exemple #6
0
 /// <summary>
 /// Check the solution for compiler errors and warnings, uses:
 /// DiagnosticSettings.AllowedErrorIds()
 /// DiagnosticSettings.AllowedDiagnostics()
 /// </summary>
 public static void NoCompilerErrors(Solution solution)
 {
     NoCompilerErrorsAsync(solution, DiagnosticSettings.AllowedErrorIds(), DiagnosticSettings.AllowedDiagnostics()).GetAwaiter().GetResult();
 }
Exemple #7
0
        /// <summary>
        /// Check the solution for compiler errors and warnings, uses:
        /// DiagnosticSettings.AllowedErrorIds()
        /// DiagnosticSettings.AllowedDiagnostics()
        /// </summary>
        public static void NoCompilerErrors(IReadOnlyList <MetadataReference> metadataReferences, params string[] code)
        {
            var solution = CodeFactory.CreateSolution(code, metadataReferences);

            NoCompilerErrorsAsync(solution, DiagnosticSettings.AllowedErrorIds(), DiagnosticSettings.AllowedDiagnostics()).GetAwaiter().GetResult();
        }
 private static void NoDiagnosticsOrErrors(Analyze.DiagnosticsAndErrors diagnosticsAndErrors)
 {
     NoDiagnostics(diagnosticsAndErrors.AnalyzerDiagnostics);
     NoCompilerErrors(diagnosticsAndErrors.Errors, DiagnosticSettings.AllowedErrorIds(), DiagnosticSettings.AllowedDiagnostics());
 }