DiffPlexReporter.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. // Licensed to the .NET Foundation under one or more agreements.
  2. // The .NET Foundation licenses this file to you under the MIT License.
  3. // See the LICENSE file in the project root for more information.
  4. namespace Tests.System.Interactive.ApiApprovals;
  5. internal static class DiffPlexReporter
  6. {
  7. public static Task Report(string receivedFile, string verifiedFile, string? message)
  8. {
  9. #if (!DEBUG)
  10. var receivedText = File.ReadAllText(receivedFile);
  11. var verifiedText = File.ReadAllText(verifiedFile);
  12. var diffBuilder = new InlineDiffBuilder(new Differ());
  13. var diff = diffBuilder.BuildDiffModel(verifiedText, receivedText);
  14. foreach (var line in diff.Lines)
  15. {
  16. if (line.Type == ChangeType.Unchanged) continue;
  17. var prefix = " ";
  18. switch (line.Type)
  19. {
  20. case ChangeType.Inserted:
  21. prefix = "+ ";
  22. break;
  23. case ChangeType.Deleted:
  24. prefix = "- ";
  25. break;
  26. }
  27. Console.WriteLine("{0}{1}", prefix, line.Text);
  28. }
  29. #endif
  30. return Task.CompletedTask;
  31. }
  32. }