diff --git a/eng/Versions.props b/eng/Versions.props index b64b741468b2c..d74eaa5cbeb55 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -56,7 +56,7 @@ 1.2.4 0.13.0 0.13.0 - 1.4.4 + 1.5.0 0.9.2 2.2.0 6.1.0.5902 diff --git a/src/Compilers/Test/Core/Assert/AssertEx.cs b/src/Compilers/Test/Core/Assert/AssertEx.cs index 4034034204bf9..10d6b8dadda69 100644 --- a/src/Compilers/Test/Core/Assert/AssertEx.cs +++ b/src/Compilers/Test/Core/Assert/AssertEx.cs @@ -16,6 +16,7 @@ using System.Runtime.CompilerServices; using System.Text; using DiffPlex; +using DiffPlex.Chunkers; using DiffPlex.DiffBuilder; using DiffPlex.DiffBuilder.Model; using Microsoft.CodeAnalysis.Test.Utilities; @@ -28,6 +29,10 @@ namespace Roslyn.Test.Utilities /// public static class AssertEx { + private static readonly IChunker s_lineChunker = new LineChunker(); + private static readonly IChunker s_lineEndingsPreservingChunker = new LineEndingsPreservingChunker(); + private static readonly InlineDiffBuilder s_diffBuilder = new InlineDiffBuilder(new Differ()); + #region AssertEqualityComparer private class AssertEqualityComparer : IEqualityComparer @@ -242,30 +247,35 @@ public static void EqualOrDiff(string expected, string actual, string message = return; } - var diffBuilder = new InlineDiffBuilder(new Differ()); - var diff = diffBuilder.BuildDiffModel(expected, actual, ignoreWhitespace: false); + var diff = s_diffBuilder.BuildDiffModel(expected, actual, ignoreWhitespace: false, ignoreCase: false, s_lineChunker); var messageBuilder = new StringBuilder(); messageBuilder.AppendLine( string.IsNullOrEmpty(message) ? "Actual and expected values differ. Expected shown in baseline of diff:" : message); + if (!diff.Lines.Any(line => line.Type == ChangeType.Inserted || line.Type == ChangeType.Deleted)) + { + // We have a failure only caused by line ending differences; recalculate with line endings visible + diff = s_diffBuilder.BuildDiffModel(expected, actual, ignoreWhitespace: false, ignoreCase: false, s_lineEndingsPreservingChunker); + } + foreach (var line in diff.Lines) { switch (line.Type) { case ChangeType.Inserted: - messageBuilder.Append("+"); + messageBuilder.Append('+'); break; case ChangeType.Deleted: - messageBuilder.Append("-"); + messageBuilder.Append('-'); break; default: - messageBuilder.Append(" "); + messageBuilder.Append(' '); break; } - messageBuilder.AppendLine(line.Text); + messageBuilder.AppendLine(line.Text.Replace("\r", "").Replace("\n", "")); } Assert.True(false, messageBuilder.ToString());