nunit: Broken `char` comparison in v3.7 and higher

Hi,

I just found out that there is a problem comparing chars that happened from 3.7.

Take this assertion:

Assert.That('2', Is.GreaterThan('3'));

When run in 3.6.1, the assertion will (correctly) fail:

Test 'whatever' failed:   Expected: greater than '3'
  But was:  '2'

When the same assertion is run in 3.7.0 or higher, it will not fail, which, in my opinion, is wrong as ‘2’ is definitely not greater than ‘3’ and neither are their numeric values (50 and 51).

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 18 (17 by maintainers)

Most upvoted comments

I think the code has been broken like this for as long as it has existed. In the past, it was only used for equality comparisons. GreaterThan and LessThan comparisons were made using operators.

Now this code is also used for GreaterThan and LessThan, so we have to return -1 as well when it’s appropriate, not just 0 or 1.

The problem is here (we always return 1 if the two chars are different instead of using the comparison) https://github.com/nunit/nunit/blob/d03e93c8f25170a8ff48e80863a3fe6fd294613a/src/NUnitFramework/framework/Constraints/NUnitComparer.cs#L58-L59