Skip to content

Commit

Permalink
Report EnC warning when entry point is changed (#73565)
Browse files Browse the repository at this point in the history
  • Loading branch information
tmat authored May 18, 2024
1 parent 61aa5c8 commit 3dfab18
Show file tree
Hide file tree
Showing 33 changed files with 755 additions and 420 deletions.
42 changes: 41 additions & 1 deletion src/Compilers/Test/Core/Assert/AssertEx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,14 @@ public static string GetAssertMessage<T>(

var expectedString = string.Join(itemSeparator, expected.Take(10).Select(itemInspector));
var actualString = string.Join(itemSeparator, actual.Select(itemInspector));
var diffString = DiffUtil.DiffReport(expected, actual, itemSeparator, comparer, itemInspector);

if (DifferOnlyInWhitespace(expectedString, actualString))
{
expectedString = VisualizeWhitespace(expectedString);
actualString = VisualizeWhitespace(actualString);
diffString = VisualizeWhitespace(diffString);
}

var message = new StringBuilder();

Expand All @@ -693,7 +701,7 @@ public static string GetAssertMessage<T>(
message.AppendLine("Actual:");
message.AppendLine(actualString);
message.AppendLine("Differences:");
message.AppendLine(DiffUtil.DiffReport(expected, actual, itemSeparator, comparer, itemInspector));
message.AppendLine(diffString);

if (TryGenerateExpectedSourceFileAndGetDiffLink(actualString, expected.Count(), expectedValueSourcePath, expectedValueSourceLine, out var link))
{
Expand All @@ -703,6 +711,38 @@ public static string GetAssertMessage<T>(
return message.ToString();
}

private static bool DifferOnlyInWhitespace(IEnumerable<char> expected, IEnumerable<char> actual)
=> expected.Where(c => !char.IsWhiteSpace(c)).SequenceEqual(actual.Where(c => !char.IsWhiteSpace(c)));

private static string VisualizeWhitespace(string str)
{
var result = new StringBuilder(str.Length);

var i = 0;
while (i < str.Length)
{
var c = str[i++];
if (c == '\r' && i < str.Length && str[i] == '\n')
{
result.Append("␍␊\r\n");
i++;
}
else
{
result.Append(c switch
{
' ' => "·",
'\t' => "",
'\r' => "\r",
'\n' => "\n",
_ => c,
});
}
}

return result.ToString();
}

public static string GetAssertMessage<T>(
ReadOnlySpan<T> expected,
ReadOnlySpan<T> actual,
Expand Down
Loading

0 comments on commit 3dfab18

Please sign in to comment.