stretchr / testify

A toolkit with common assertions and mocks that plays nicely with the standard library
MIT License
23.15k stars 1.59k forks source link

assert: Fix EqualValues to handle overflow/underflow #1531

Closed arjunmahishi closed 7 months ago

arjunmahishi commented 7 months ago

Summary

The underlying function ObjectsAreEqualValues did not handle overflow/underflow of values while converting one type to another for comparison. For example:

    EqualValues(t, int(270), int8(14))

would return true, even though the values are not equal. Because, when you convert int(270) to int8, it overflows and becomes 14 (270 % 256 = 14)

Changes

This commit fixes that by making sure that the conversion always happens from the smaller type to the larger type, and then comparing the values. Additionally, this commit also separates out the test cases of ObjectsAreEqualValues from TestObjectsAreEqual.

Related issues

Closes #1462