From 6b9ab88cf24df88b491f127cb8bd1a7f40903fde Mon Sep 17 00:00:00 2001 From: Stephen Toub Date: Sat, 2 Mar 2019 22:07:24 -0500 Subject: [PATCH] Improve assert error message in Process tests (dotnet/corefx#35725) Commit migrated from https://github.com/dotnet/corefx/commit/9a542f020ed230888cb956c90494910bfc9035c0 --- .../ref/CoreFx.Private.TestUtilities.cs | 1 + .../src/CoreFx.Private.TestUtilities.csproj | 1 + .../src/System/AssertExtensions.cs | 10 ++++++++++ .../System.Diagnostics.Process/tests/ProcessTests.Unix.cs | 2 +- 4 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/libraries/CoreFx.Private.TestUtilities/ref/CoreFx.Private.TestUtilities.cs b/src/libraries/CoreFx.Private.TestUtilities/ref/CoreFx.Private.TestUtilities.cs index 346e79e..8948f6a 100644 --- a/src/libraries/CoreFx.Private.TestUtilities/ref/CoreFx.Private.TestUtilities.cs +++ b/src/libraries/CoreFx.Private.TestUtilities/ref/CoreFx.Private.TestUtilities.cs @@ -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(System.Collections.Generic.HashSet expected, System.Collections.Generic.HashSet actual) { } public static void GreaterThanOrEqualTo(T actual, T greaterThanOrEqualTo, string userMessage = null) where T : System.IComparable { } public static void GreaterThan(T actual, T greaterThan, string userMessage = null) where T : System.IComparable { } public static void LessThanOrEqualTo(T actual, T lessThanOrEqualTo, string userMessage = null) where T : System.IComparable { } diff --git a/src/libraries/CoreFx.Private.TestUtilities/src/CoreFx.Private.TestUtilities.csproj b/src/libraries/CoreFx.Private.TestUtilities/src/CoreFx.Private.TestUtilities.csproj index 156d4e9..262fb54 100644 --- a/src/libraries/CoreFx.Private.TestUtilities/src/CoreFx.Private.TestUtilities.csproj +++ b/src/libraries/CoreFx.Private.TestUtilities/src/CoreFx.Private.TestUtilities.csproj @@ -86,6 +86,7 @@ + diff --git a/src/libraries/CoreFx.Private.TestUtilities/src/System/AssertExtensions.cs b/src/libraries/CoreFx.Private.TestUtilities/src/System/AssertExtensions.cs index fd3fa8a..1787ab6 100644 --- a/src/libraries/CoreFx.Private.TestUtilities/src/System/AssertExtensions.cs +++ b/src/libraries/CoreFx.Private.TestUtilities/src/System/AssertExtensions.cs @@ -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); } } + + /// Validates that the two sets contains the same elements. XUnit doesn't display the full collections. + public static void Equal(HashSet expected, HashSet actual) + { + if (!actual.SetEquals(expected)) + { + throw new XunitException($"Expected: {string.Join(", ", expected)}{Environment.NewLine}Actual: {string.Join(", ", actual)}"); + } + } } } diff --git a/src/libraries/System.Diagnostics.Process/tests/ProcessTests.Unix.cs b/src/libraries/System.Diagnostics.Process/tests/ProcessTests.Unix.cs index 6e7d6d3..8b37c81 100644 --- a/src/libraries/System.Diagnostics.Process/tests/ProcessTests.Unix.cs +++ b/src/libraries/System.Diagnostics.Process/tests/ProcessTests.Unix.cs @@ -512,7 +512,7 @@ namespace System.Diagnostics.Tests if (bool.Parse(checkGroupsExact)) { - Assert.Equal(expectedGroups, GetGroups()); + AssertExtensions.Equal(expectedGroups, GetGroups()); } else { -- 2.7.4