mirror of https://gitee.com/bigwinds/arangodb
Set jsunity output to gtest style (#9646)
* Set jsunity output to gtest style * More pretty printing * Fix jslint * Remove unnecessary spaces
This commit is contained in:
parent
b6aec209a5
commit
0c6d3b7ddc
|
@ -334,6 +334,7 @@ let result = main(ARGUMENTS);
|
|||
|
||||
if (!result) {
|
||||
// force an error in the console
|
||||
throw 'peng!';
|
||||
process.exit(1);
|
||||
// throw 'peng!';
|
||||
}
|
||||
|
||||
|
|
|
@ -41,10 +41,10 @@ const platform = require('internal').platform;
|
|||
/* Constants: */
|
||||
// const BLUE = require('internal').COLORS.COLOR_BLUE;
|
||||
// const CYAN = require('internal').COLORS.COLOR_CYAN;
|
||||
// const GREEN = require('internal').COLORS.COLOR_GREEN;
|
||||
const GREEN = require('internal').COLORS.COLOR_GREEN;
|
||||
const RED = require('internal').COLORS.COLOR_RED;
|
||||
const RESET = require('internal').COLORS.COLOR_RESET;
|
||||
// const YELLOW = require('internal').COLORS.COLOR_YELLOW;
|
||||
const YELLOW = require('internal').COLORS.COLOR_YELLOW;
|
||||
|
||||
let didSplitBuckets = false;
|
||||
|
||||
|
@ -221,7 +221,7 @@ function performTests (options, testList, testname, runFn, serverOptions, startS
|
|||
break;
|
||||
}
|
||||
|
||||
print('\n' + Date() + ' ' + runFn.info + ': Trying', te, '...');
|
||||
print('\n' + (new Date()).toISOString() + GREEN + " [============] " + runFn.info + ': Trying', te, '...', RESET);
|
||||
let reply = runFn(options, instanceInfo, te, env);
|
||||
|
||||
if (reply.hasOwnProperty('forceTerminate')) {
|
||||
|
|
|
@ -289,7 +289,7 @@ function unitTestPrettyPrintResults (res, testOutputDirectory, options) {
|
|||
function skipInternalMember (r, a) {
|
||||
return !r.hasOwnProperty(a) || internalMembers.indexOf(a) !== -1;
|
||||
}
|
||||
print(BLUE + '================================================================================');
|
||||
print(YELLOW + '================================================================================');
|
||||
print('TEST RESULTS');
|
||||
print('================================================================================\n' + RESET);
|
||||
|
||||
|
@ -685,7 +685,7 @@ function iterateTests(cases, options, jsonReply) {
|
|||
if (options.testBuckets) {
|
||||
printTestName += " - " + options.testBuckets;
|
||||
}
|
||||
print(BLUE + '================================================================================');
|
||||
print(YELLOW + '================================================================================');
|
||||
print('Executing test', printTestName);
|
||||
print('================================================================================\n' + RESET);
|
||||
|
||||
|
|
|
@ -46,16 +46,26 @@ var TOTALTEARDOWNS = 0;
|
|||
|
||||
var jsUnity = require('./jsunity/jsunity').jsUnity;
|
||||
var STARTTEST = 0.0;
|
||||
var ENDTEST = 0.0;
|
||||
var STARTSUITE = 0.0;
|
||||
var ENDTEARDOWN = 0.0;
|
||||
var testFilter = "undefined";
|
||||
var currentSuiteName = "undefined";
|
||||
var testCount = 0;
|
||||
var startMessage = "";
|
||||
|
||||
function setTestFilter(filter) {
|
||||
testFilter = filter;
|
||||
}
|
||||
|
||||
jsUnity.results.begin = function (total, suiteName) {
|
||||
print(Date() + ' Running ' + (suiteName || 'unnamed test suite'));
|
||||
print(' ' + total + ' test(s) found');
|
||||
print();
|
||||
if (testCount > 0)
|
||||
{
|
||||
print();
|
||||
testCount = 0;
|
||||
}
|
||||
currentSuiteName = suiteName;
|
||||
startMessage = " [------------] " + total + " tests from " + (suiteName || 'unnamed test suite');
|
||||
RESULTS = {};
|
||||
|
||||
STARTTEST = jsUnity.env.getDate();
|
||||
|
@ -65,49 +75,97 @@ jsUnity.results.pass = function (index, testName) {
|
|||
var newtime = jsUnity.env.getDate();
|
||||
|
||||
RESULTS[testName].status = true;
|
||||
RESULTS[testName].duration = newtime - STARTTEST;
|
||||
RESULTS[testName].duration = (ENDTEST - STARTTEST);
|
||||
|
||||
print(newtime.toISOString() + internal.COLORS.COLOR_GREEN + ' [PASSED] ' + testName + internal.COLORS.COLOR_RESET +
|
||||
' in ' + STARTTEST.toISOString() + '+' + ((newtime - STARTTEST) / 1000).toFixed(3) + 's');
|
||||
print(newtime.toISOString() + internal.COLORS.COLOR_GREEN + ' [ PASSED ] ' +
|
||||
testName + internal.COLORS.COLOR_RESET +
|
||||
' (setUp: ' + RESULTS[testName].setUpDuration + 'ms,' +
|
||||
' test: ' + RESULTS[testName].duration + 'ms,' +
|
||||
' tearDown: ' + RESULTS[testName].tearDownDuration + 'ms)');
|
||||
|
||||
STARTTEST = newtime;
|
||||
|
||||
++testCount;
|
||||
};
|
||||
|
||||
jsUnity.results.fail = function (index, testName, message) {
|
||||
var newtime = jsUnity.env.getDate();
|
||||
|
||||
++testCount;
|
||||
|
||||
if (RESULTS[testName] === undefined)
|
||||
{
|
||||
if (testCount === 1)
|
||||
{
|
||||
print(newtime.toISOString() + internal.COLORS.COLOR_RED + " [ FAILED ] " + currentSuiteName +
|
||||
internal.COLORS.COLOR_RESET + " (setUpAll: " + (jsUnity.env.getDate() - STARTTEST) + "ms)");
|
||||
|
||||
ENDTEST = newtime;
|
||||
}
|
||||
print(internal.COLORS.COLOR_RED + message + internal.COLORS.COLOR_RESET);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
RESULTS[testName].status = false;
|
||||
RESULTS[testName].message = message;
|
||||
RESULTS[testName].duration = newtime - STARTTEST;
|
||||
RESULTS[testName].duration = (ENDTEST - STARTTEST);
|
||||
|
||||
print(newtime.toISOString() + internal.COLORS.COLOR_RED + ' [FAILED] ' + testName + internal.COLORS.COLOR_RESET +
|
||||
' in ' + STARTTEST.toISOString() + '+' + ((newtime - STARTTEST) / 1000).toFixed(3) + 's: ' +
|
||||
internal.COLORS.COLOR_RED + message + internal.COLORS.COLOR_RESET);
|
||||
if (RESULTS[testName].setUpDuration === undefined)
|
||||
{
|
||||
RESULTS[testName].setUpDuration = newtime - SETUPS;
|
||||
RESULTS[testName].duration = 0;
|
||||
}
|
||||
|
||||
print(newtime.toISOString() + internal.COLORS.COLOR_RED + " [ FAILED ] " +
|
||||
testName + internal.COLORS.COLOR_RESET +
|
||||
' (setUp: ' + RESULTS[testName].setUpDuration + 'ms,' +
|
||||
' test: ' + RESULTS[testName].duration + 'ms,' +
|
||||
' tearDown: ' + (newtime - ENDTEST) + 'ms)\n' +
|
||||
internal.COLORS.COLOR_RED + message + internal.COLORS.COLOR_RESET);
|
||||
|
||||
STARTTEST = newtime;
|
||||
};
|
||||
|
||||
jsUnity.results.end = function (passed, failed, duration) {
|
||||
print(' ' + passed + ' test(s) passed');
|
||||
print(' ' + ((failed > 0) ?
|
||||
internal.COLORS.COLOR_RED :
|
||||
internal.COLORS.COLOR_RESET) +
|
||||
failed + ' test(s) failed' + internal.COLORS.COLOR_RESET);
|
||||
print(' ' + duration + ' millisecond(s) elapsed');
|
||||
print();
|
||||
print(jsUnity.env.getDate().toISOString() +
|
||||
((failed > 0) ? internal.COLORS.COLOR_RED : internal.COLORS.COLOR_GREEN) + " [------------] " +
|
||||
(passed + failed) + " tests from " + currentSuiteName + " ran" + internal.COLORS.COLOR_RESET +
|
||||
" (tearDownAll: " + (jsUnity.env.getDate() - ENDTEST) + "ms)");
|
||||
print(jsUnity.env.getDate().toISOString() + internal.COLORS.COLOR_GREEN +
|
||||
" [ PASSED ] " + passed + " tests." + internal.COLORS.COLOR_RESET);
|
||||
if(failed > 0)
|
||||
{
|
||||
print(jsUnity.env.getDate().toISOString() + internal.COLORS.COLOR_RED +
|
||||
" [ FAILED ] " + failed + ' tests.' + internal.COLORS.COLOR_RESET);
|
||||
}
|
||||
};
|
||||
|
||||
jsUnity.results.beginSetUp = function(index, testName) {
|
||||
if (testCount === 0)
|
||||
{
|
||||
print(STARTTEST.toISOString() + internal.COLORS.COLOR_GREEN +
|
||||
startMessage + internal.COLORS.COLOR_RESET + ' (setUpAll: ' +
|
||||
(jsUnity.env.getDate() - STARTTEST) + 'ms)' + internal.COLORS.COLOR_RESET);
|
||||
}
|
||||
RESULTS[testName] = {};
|
||||
SETUPS = jsUnity.env.getDate();
|
||||
print(jsUnity.env.getDate().toISOString() + internal.COLORS.COLOR_GREEN + ' [ RUN ] ' + testName + internal.COLORS.COLOR_RESET);
|
||||
};
|
||||
|
||||
jsUnity.results.endSetUp = function(index, testName) {
|
||||
RESULTS[testName].setUpDuration = jsUnity.env.getDate() - SETUPS;
|
||||
TOTALSETUPS += RESULTS[testName].setUpDuration;
|
||||
|
||||
STARTTEST = jsUnity.env.getDate();
|
||||
};
|
||||
|
||||
jsUnity.results.beginTeardown = function(index, testName) {
|
||||
TEARDOWNS = jsUnity.env.getDate();
|
||||
|
||||
ENDTEST = jsUnity.env.getDate();
|
||||
};
|
||||
|
||||
jsUnity.results.endTeardown = function(index, testName) {
|
||||
RESULTS[testName].tearDownDuration = jsUnity.env.getDate() - TEARDOWNS;
|
||||
TOTALTEARDOWNS += RESULTS[testName].tearDownDuration;
|
||||
|
@ -220,11 +278,15 @@ function Run (testsuite) {
|
|||
// //////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
function Done (suiteName) {
|
||||
internal.printf('%d total, %d passed, %d failed, %d ms', TOTAL, PASSED, FAILED, DURATION);
|
||||
print();
|
||||
let newtime = jsUnity.env.getDate();
|
||||
|
||||
var ok = FAILED === 0;
|
||||
|
||||
print(newtime.toISOString() + (ok ? internal.COLORS.COLOR_GREEN : internal.COLORS.COLOR_RED) +
|
||||
" [============] " + "Ran: " + TOTAL + " tests (" + PASSED + " passed, " + FAILED + " failed)" +
|
||||
internal.COLORS.COLOR_RESET+ " (" + DURATION + "ms total)");
|
||||
print();
|
||||
|
||||
COMPLETE.duration = DURATION;
|
||||
COMPLETE.status = ok;
|
||||
COMPLETE.failed = FAILED;
|
||||
|
|
|
@ -523,64 +523,60 @@ var jsUnity = exports.jsUnity = (function () {
|
|||
var test = suite.tests[j];
|
||||
|
||||
counter = 0;
|
||||
|
||||
try {
|
||||
this.results.beginSetUp(suite.scope, test.name);
|
||||
setUp(test.name);
|
||||
this.results.endSetUp(suite.scope, test.name);
|
||||
|
||||
test.fn.call(suite.scope, test.name);
|
||||
let didSetUp = false;
|
||||
let didTest = false;
|
||||
let skipTest = false;
|
||||
let didTearDown = false;
|
||||
let messages = [];
|
||||
|
||||
|
||||
this.results.beginTeardown(suite.scope, test.name);
|
||||
tearDown(test.name);
|
||||
this.results.endTeardown(suite.scope, test.name);
|
||||
|
||||
this.results.pass(j + 1, test.name);
|
||||
|
||||
results.passed++;
|
||||
} catch (e) {
|
||||
while (1) {
|
||||
try {
|
||||
tearDown(test.name); // if tearDown above throws exc, will call again!
|
||||
}
|
||||
catch (x) {
|
||||
var xstack;
|
||||
if (x.stack !== undefined) {
|
||||
xstack = x.stack;
|
||||
if (!didSetUp) {
|
||||
this.results.beginSetUp(suite.scope, test.name);
|
||||
setUp(test.name);
|
||||
this.results.endSetUp(suite.scope, test.name);
|
||||
didSetUp = true;
|
||||
}
|
||||
if (e.stack !== undefined) {
|
||||
this.results.fail(j + 1,
|
||||
test.name,
|
||||
e + " - " + String(e.stack) +
|
||||
" - teardown failed - " +
|
||||
x +
|
||||
" - " +
|
||||
xstack);
|
||||
if (!didTest && !skipTest) {
|
||||
test.fn.call(suite.scope, test.name);
|
||||
didTest = true;
|
||||
}
|
||||
if (!didTearDown) {
|
||||
this.results.beginTeardown(suite.scope, test.name);
|
||||
tearDown(test.name);
|
||||
this.results.endTeardown(suite.scope, test.name);
|
||||
didTearDown = true;
|
||||
}
|
||||
|
||||
if (messages.length === 0) {
|
||||
this.results.pass(j + 1, test.name);
|
||||
results.passed++;
|
||||
} else {
|
||||
this.results.fail(j + 1, test.name, messages.join('\n'));
|
||||
}
|
||||
break;
|
||||
} catch (e) {
|
||||
if ( typeof e === "string" ) {
|
||||
e = new Error(e);
|
||||
}
|
||||
if (!didSetUp) {
|
||||
this.results.endSetUp(suite.scope, test.name);
|
||||
didSetUp = true;
|
||||
messages.push(String(e.stack) + " - setUp failed");
|
||||
skipTest = true;
|
||||
continue;
|
||||
}
|
||||
if (!didTest && !skipTest) {
|
||||
didTest = true;
|
||||
messages.push(String(e.stack) + " - test failed");
|
||||
continue;
|
||||
}
|
||||
if (!didTearDown) {
|
||||
this.results.endTeardown(suite.scope, test.name);
|
||||
didTearDown = true;
|
||||
messages.push(String(e.stack) + " - tearDown failed");
|
||||
continue;
|
||||
}
|
||||
else {
|
||||
this.results.fail(j + 1,
|
||||
test.name,
|
||||
e +
|
||||
" - teardown failed - " +
|
||||
x +
|
||||
" - " +
|
||||
xstack);
|
||||
}
|
||||
|
||||
this.log.error("Teardown failed (again): " +
|
||||
x +
|
||||
" - " +
|
||||
xstack +
|
||||
" aborting tests");
|
||||
|
||||
i = arguments.length; j = cnt; break;
|
||||
}
|
||||
|
||||
if (e.stack !== undefined) {
|
||||
this.results.fail(j + 1, test.name, e + " - " + String(e.stack));
|
||||
}
|
||||
else {
|
||||
this.results.fail(j + 1, test.name, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue