Improve assert error message in Process tests (dotnet/corefx#35725)
authorStephen Toub <stoub@microsoft.com>
Sun, 3 Mar 2019 03:07:24 +0000 (22:07 -0500)
committerGitHub <noreply@github.com>
Sun, 3 Mar 2019 03:07:24 +0000 (22:07 -0500)
Commit migrated from https://github.com/dotnet/corefx/commit/9a542f020ed230888cb956c90494910bfc9035c0

src/libraries/CoreFx.Private.TestUtilities/ref/CoreFx.Private.TestUtilities.cs
src/libraries/CoreFx.Private.TestUtilities/src/CoreFx.Private.TestUtilities.csproj
src/libraries/CoreFx.Private.TestUtilities/src/System/AssertExtensions.cs
src/libraries/System.Diagnostics.Process/tests/ProcessTests.Unix.cs

index 346e79e..8948f6a 100644 (file)
@@ -16,6 +16,7 @@ namespace System
     {
         public static void Contains(string value, string substring) { }
         public static void Equal(byte[] expected, byte[] actual) { }
+        public static void Equal<T>(System.Collections.Generic.HashSet<T> expected, System.Collections.Generic.HashSet<T> actual) { }
         public static void GreaterThanOrEqualTo<T>(T actual, T greaterThanOrEqualTo, string userMessage = null) where T : System.IComparable { }
         public static void GreaterThan<T>(T actual, T greaterThan, string userMessage = null) where T : System.IComparable { }
         public static void LessThanOrEqualTo<T>(T actual, T lessThanOrEqualTo, string userMessage = null) where T : System.IComparable { }
index 156d4e9..262fb54 100644 (file)
@@ -86,6 +86,7 @@
     </Compile>
   </ItemGroup>
   <ItemGroup>
+    <Reference Include="System.Collections" />
     <Reference Include="System.Memory" />
     <Reference Include="Microsoft.Win32.Registry" />
     <Reference Include="System.Runtime" />
index fd3fa8a..1787ab6 100644 (file)
@@ -2,6 +2,7 @@
 // The .NET Foundation licenses this file to you under the MIT license.
 // See the LICENSE file in the project root for more information.
 
+using System.Collections.Generic;
 using System.Runtime.InteropServices;
 using System.Threading.Tasks;
 using Xunit;
@@ -337,5 +338,14 @@ namespace System
                 throw new AssertActualExpectedException(expectedString, actualString, null);
             }
         }
+
+        /// <summary>Validates that the two sets contains the same elements. XUnit doesn't display the full collections.</summary>
+        public static void Equal<T>(HashSet<T> expected, HashSet<T> actual)
+        {
+            if (!actual.SetEquals(expected))
+            {
+                throw new XunitException($"Expected: {string.Join(", ", expected)}{Environment.NewLine}Actual: {string.Join(", ", actual)}");
+            }
+        }
     }
 }
index 6e7d6d3..8b37c81 100644 (file)
@@ -512,7 +512,7 @@ namespace System.Diagnostics.Tests
 
             if (bool.Parse(checkGroupsExact))
             {
-                Assert.Equal(expectedGroups, GetGroups());
+                AssertExtensions.Equal(expectedGroups, GetGroups());
             }
             else
             {