Skip to content

Commit

Permalink
logging (#63326)
Browse files Browse the repository at this point in the history
  • Loading branch information
danmoseley committed Jan 4, 2022
1 parent 7172c68 commit 312c66f
Showing 1 changed file with 24 additions and 5 deletions.
29 changes: 24 additions & 5 deletions src/libraries/System.Console/tests/ConsoleKeyInfoTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down Expand Up @@ -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]
Expand Down

0 comments on commit 312c66f

Please sign in to comment.