Skip to content

Commit

Permalink
Better assert message for AllSetupAndCleanupMethodRunsTest
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreyAkinshin committed May 31, 2023
1 parent adf72c1 commit b1baa71
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
Expand Up @@ -60,7 +60,7 @@ public void AllSetupAndCleanupMethodRunsTest()
var actualLogLines = GetActualLogLines(summary);
foreach (string line in actualLogLines)
Output.WriteLine(line);
Assert.Equal(expectedLogLines, actualLogLines);
SmartAssert.Equal(expectedLogLines, actualLogLines);
}

public class AllSetupAndCleanupAttributeBenchmarks
Expand Down
31 changes: 31 additions & 0 deletions tests/BenchmarkDotNet.Tests/XUnit/SmartAssert.cs
@@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace BenchmarkDotNet.Tests.XUnit
{
public static class SmartAssert
{
public static void Equal<T>(IReadOnlyList<T> expected, IReadOnlyList<T> actual)
{
Exception CreateException(string comment)
{
var builder = new StringBuilder();
builder.AppendLine($"Failure ({comment})");
builder.AppendLine("*** Expected ***");
for (int i = 0; i < expected.Count; i++)
builder.AppendLine($"[{i}]: {expected[i]}");
builder.AppendLine("*** Actual ***");
for (int i = 0; i < actual.Count; i++)
builder.AppendLine($"[{i}]: {actual[i]}");
return new Exception(builder.ToString());
}

if (expected.Count != actual.Count)
throw CreateException("Length mismatch");
for (int i = 0; i < expected.Count; i++)
if (!expected[i].Equals(actual[i]))
throw CreateException($"Element mismatch (index={i})");
}
}
}

0 comments on commit b1baa71

Please sign in to comment.