diff --git a/src/libraries/System.Console/tests/ConsoleKeyInfoTests.cs b/src/libraries/System.Console/tests/ConsoleKeyInfoTests.cs index da3720a43d015..43a4007708f24 100644 --- a/src/libraries/System.Console/tests/ConsoleKeyInfoTests.cs +++ b/src/libraries/System.Console/tests/ConsoleKeyInfoTests.cs @@ -3,11 +3,19 @@ using System.Collections.Generic; using Xunit; +using Xunit.Abstractions; namespace System.Tests { public class ConsoleKeyInfoTests { + private readonly ITestOutputHelper _output; + + public ConsoleKeyInfoTests(ITestOutputHelper output) + { + _output = output; + } + [Fact] public void Ctor_DefaultCtor_PropertiesReturnDefaults() { @@ -37,12 +45,23 @@ public void Equals_SameData(ConsoleKeyInfo cki) { ConsoleKeyInfo other = cki; // otherwise compiler warns about comparing the instance with itself - Assert.True(cki.Equals((object)other)); - Assert.True(cki.Equals(other)); - Assert.True(cki == other); - Assert.False(cki != other); + try + { + Assert.True(cki.Equals((object)other)); + Assert.True(cki.Equals(other)); + Assert.True(cki == other); + Assert.False(cki != other); + + Assert.Equal(cki.GetHashCode(), other.GetHashCode()); + } + catch + { + // Log more info in failure case to help investigate https://github.com/dotnet/runtime/issues/60240 + _output.WriteLine($"ConsoleKeyInfo had KeyChar {cki.KeyChar} Key {cki.Key} Modifiers {cki.Modifiers}"); + _output.WriteLine($"`cki.Equals(other)` gives {cki.Equals(other)} and `cki == other` gives {cki == other}"); - Assert.Equal(cki.GetHashCode(), other.GetHashCode()); + throw; + } } [Theory]