Bug 461180: Fix test case result comparison function.

The old code fails when actual is Number.NaN and expected is a number.

(Patch from mrbkap, jimb, and Waldo.)
This commit is contained in:
Jim Blandy 2008-11-27 02:29:34 -08:00
Родитель 68b268583f
Коммит 0e3c433601
1 изменённых файлов: 23 добавлений и 41 удалений

Просмотреть файл

@ -693,48 +693,30 @@ if (typeof options == 'function')
function getTestCaseResult(expected, actual)
{
var expected_t = typeof expected;
var actual_t = typeof actual;
var passed = true;
if (typeof expected != typeof actual)
return false;
if (typeof expected != 'number')
// Note that many tests depend on the use of '==' here, not '==='.
return actual == expected;
// because ( NaN == NaN ) always returns false, need to do
// a special compare to see if we got the right result.
// Distinguish NaN from other values. Using x != x comparisons here
// works even if tests redefine isNaN.
if (actual != actual)
{
if ( actual_t == "object" )
{
actual = "NaN object";
}
else
{
actual = "NaN number";
}
}
return expected != expected;
if (expected != expected)
{
if ( expected_t == "object" )
{
expected = "NaN object";
}
else
{
expected = "NaN number";
}
}
return false;
if (expected_t != actual_t)
{
passed = false;
}
else if (expected != actual)
{
if (expected_t != 'number' || (Math.abs(actual - expected) > 1E-10))
{
passed = false;
}
}
// Tolerate a certain degree of error.
if (actual != expected)
return Math.abs(actual - expected) <= 1E-10;
return passed;
// Here would be a good place to distinguish 0 and -0, if we wanted
// to. However, doing so would introduce a number of failures in
// areas where they don't seem important. For example, the WeekDay
// function in ECMA-262 returns -0 for Sundays before the epoch, but
// the Date functions in SpiderMonkey specified in terms of WeekDay
// often don't. This seems unimportant.
return true;
}
if (typeof dump == 'undefined')