Skip to content

Commit

Permalink
chore: make test output display more info when compare fails
Browse files Browse the repository at this point in the history
  • Loading branch information
activescott committed Oct 25, 2021
1 parent ff4944e commit 318113b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
11 changes: 6 additions & 5 deletions src/Lessmsi.Tests/FileEntryGraph.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,22 +174,23 @@ private static string SerializeDate(DateTime dateTime)

public static bool CompareEntries(FileEntryGraph a, FileEntryGraph b, out string errorMessage)
{
errorMessage = "";
bool suceeded = true;
if (a.Entries.Count != b.Entries.Count)
{
errorMessage = string.Format("Entries for '{0}' and '{1}' have a different number of file entries ({2}, {3} respectively).", a.ForFileName, b.ForFileName, a.Entries.Count, b.Entries.Count);
return false;
suceeded = false;
}

for (int i = 0; i < Math.Max(a.Entries.Count, b.Entries.Count); i++)
{
if (!a.Entries[i].Equals(b.Entries[i]))
{
errorMessage = string.Format("'{0}'!='{1}' at index '{2}'.", a.Entries[i].Path, b.Entries[i].Path, i);
return false;
errorMessage += string.Format("'{0}'!='{1}' at index '{2}'.", a.Entries[i].Path, b.Entries[i].Path, i);
suceeded = false;
}
}
errorMessage = "";
return true;
return suceeded;
}
}
}
2 changes: 1 addition & 1 deletion src/Lessmsi.Tests/TestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ protected static void AssertAreEqual(FileEntryGraph expected, FileEntryGraph act
string msg;
if (!FileEntryGraph.CompareEntries(expected, actual, out msg))
{
throw new Exception("FileEntryGraph entries are not the equal");
throw new Exception(string.Format("FileEntryGraph entries are not the equal: {0}", msg));
}
}

Expand Down

0 comments on commit 318113b

Please sign in to comment.