Ox.test: eval all scripts; add stringifyResult method; properly stringify actual async result; in async path, rename 'result' to 'actual'

This commit is contained in:
rolux 2012-06-24 15:40:48 +02:00
parent 966ceeb1f1
commit 9f1b86ab87

View file

@ -823,18 +823,12 @@ Ox.test = function(argument, callback) {
"$1'" + statement.replace(/'/g, "\\'") + "', "
);
}
if (test.expected || statement.match(/Ox\.test\./)) {
// Eval the statement, unless it's a script tag that doesn't
// add a property to Ox.test
Ox.Log('TEST', statement);
actual = eval(statement);
}
Ox.Log('TEST', statement);
actual = eval(statement);
Ox.print(JSON.stringify(actual))
if (!isAsync && test.expected) {
Ox.test.data[id].results.push({
actual: Ox.isEqual(actual, -0) ? '-0'
: Ox.isNaN(actual) ? 'NaN'
: Ox.isUndefined(actual) ? 'undefined'
: JSON.stringify(actual),
actual: stringifyResult(actual),
expected: test.expected,
name: item.name,
section: item.section,
@ -852,6 +846,12 @@ Ox.test = function(argument, callback) {
delete Ox.test.data[id];
}
}
function stringifyResult(result) {
return Ox.isEqual(result, -0) ? '-0'
: Ox.isNaN(result) ? 'NaN'
: Ox.isUndefined(result) ? 'undefined'
: JSON.stringify(result);
}
if (arguments.length == 2) {
if (Ox.typeOf(argument) == 'string' && Ox.contains(argument, '\n')) {
// source code
@ -868,7 +868,7 @@ Ox.test = function(argument, callback) {
}
} else {
var statement = arguments[0],
result = arguments[1],
actual = arguments[1],
expected = arguments[2],
id, test;
Ox.forEach(Ox.test.data, function(v, k) {
@ -879,9 +879,9 @@ Ox.test = function(argument, callback) {
}
});
Ox.test.data[id].results.push(Ox.extend(test, {
actual: result,
actual: stringifyResult(actual),
statement: statement,
passed: Ox.isEqual(result, expected)
passed: Ox.isEqual(actual, expected)
}));
delete Ox.test.data[id].tests[statement];
if (Ox.test.data[id].done && Ox.isEmpty(Ox.test.data[id].tests)) {