log entire content to see which assertion fails (#67586)
authorAdam Sitnik <adam.sitnik@gmail.com>
Wed, 6 Apr 2022 09:07:44 +0000 (11:07 +0200)
committerGitHub <noreply@github.com>
Wed, 6 Apr 2022 09:07:44 +0000 (11:07 +0200)
* add AssertExtensions.Eqal(string, string) that logs entire content if provided strings are not equal

* log entire content to see which assertion fails

src/libraries/Common/tests/TestUtilities/System/AssertExtensions.cs
src/libraries/System.Diagnostics.Process/tests/ProcessStreamReadTests.cs

index c56fdae..90372ba 100644 (file)
@@ -499,6 +499,17 @@ namespace System
                 throw new XunitException($"Expected: {expected1} || {expected2}{Environment.NewLine}Actual: {value}");
         }
 
+        /// <summary>
+        /// Compares two strings, logs entire content if they are not equal.
+        /// </summary>
+        public static void Equal(string expected, string actual)
+        {
+            if (!expected.Equals(actual))
+            {
+                throw new AssertActualExpectedException(expected, actual, "Provided strings were not equal!");
+            }
+        }
+
         public delegate void AssertThrowsActionReadOnly<T>(ReadOnlySpan<T> span);
 
         public delegate void AssertThrowsAction<T>(Span<T> span);
index 3cbab6c..26174ab 100644 (file)
@@ -82,7 +82,7 @@ namespace System.Diagnostics.Tests
             p.WaitForExit(); // This ensures async event handlers are finished processing.
 
             const string Expected = RemotelyInvokable.TestConsoleApp + " started error stream" + RemotelyInvokable.TestConsoleApp + " closed error stream";
-            Assert.Equal(Expected, sb.ToString());
+            AssertExtensions.Equal(Expected, sb.ToString());
             Assert.Equal(invokeRequired ? 3 : 0, invokeCalled);
         }