@joebigelow / wix / commits / cd2a9d19

Add additional error detail to WixAssert.CompareLineByLine

Rob Mensching committed Jan 2, 2022 at 07:52 UTC cd2a9d19ba7d74ef73d899861d41e3b3bf42aad9
1 file changed +12 -8
src/internal/WixBuildTools.TestSupport/WixAssert.cs
+12 -8
@@ -12,13 +12,17 @@ namespace WixBuildTools.TestSupport
12 {
13 public static void CompareLineByLine(string[] expectedLines, string[] actualLines)
14 {
15 - for (var i = 0; i < expectedLines.Length; ++i)
15 + var lineNumber = 0;
16 +
17 + for (; lineNumber < expectedLines.Length && lineNumber < actualLines.Length; ++lineNumber)
18 {
17 - Assert.True(actualLines.Length > i, $"{i}: expectedLines longer than actualLines");
18 - WixAssert.StringEqual($"{i}: {expectedLines[i]}", $"{i}: {actualLines[i]}");
19 + WixAssert.StringEqual($"{lineNumber}: {expectedLines[lineNumber]}", $"{lineNumber}: {actualLines[lineNumber]}");
20 }
21
21 - Assert.True(expectedLines.Length == actualLines.Length, $"actualLines ({actualLines.Length}) longer than expectedLines ({expectedLines.Length})");
22 + var additionalExpectedLines = expectedLines.Length > lineNumber ? String.Join(Environment.NewLine, expectedLines.Skip(lineNumber).Select((s, i) => $"{lineNumber + i}: {s}")) : $"Missing {actualLines.Length - lineNumber} lines";
23 + var additionalActualLines = actualLines.Length > lineNumber ? String.Join(Environment.NewLine, actualLines.Skip(lineNumber).Select((s, i) => $"{lineNumber + i}: {s}")) : $"Missing {expectedLines.Length - lineNumber} lines";
24 +
25 + WixAssert.StringEqual(additionalExpectedLines, additionalActualLines);
26 }
27
28 public static void CompareXml(XContainer xExpected, XContainer xActual)
@@ -70,21 +74,21 @@ namespace WixBuildTools.TestSupport
74 public static readonly StringObjectEqualityComparer InvariantCultureIgnoreCase = new StringObjectEqualityComparer(true);
75 public static readonly StringObjectEqualityComparer InvariantCulture = new StringObjectEqualityComparer(false);
76
73 - private readonly StringComparer _stringComparer;
77 + private readonly StringComparer stringComparer;
78
79 public StringObjectEqualityComparer(bool ignoreCase)
80 {
77 - this._stringComparer = ignoreCase ? StringComparer.InvariantCultureIgnoreCase : StringComparer.InvariantCulture;
81 + this.stringComparer = ignoreCase ? StringComparer.InvariantCultureIgnoreCase : StringComparer.InvariantCulture;
82 }
83
84 public new bool Equals(object x, object y)
85 {
82 - return this._stringComparer.Equals((string)x,(string)y);
86 + return this.stringComparer.Equals((string)x,(string)y);
87 }
88
89 public int GetHashCode(object obj)
90 {
87 - return this._stringComparer.GetHashCode((string)obj);
91 + return this.stringComparer.GetHashCode((string)obj);
92 }
93 }
94 }