mirror of https://gitee.com/bigwinds/arangodb
Refactor Test Runner
This commit is contained in:
parent
b5764513d9
commit
403cdd80b6
|
@ -1,50 +1,51 @@
|
||||||
/*jslint indent: 2, nomen: true, maxlen: 120, regexp: true, todo: true */
|
/*jslint indent: 2, nomen: true, maxlen: 120, regexp: true, todo: true */
|
||||||
/*global module, require, exports, print */
|
/*global module, require, exports, print */
|
||||||
var RunTest = require('jsunity').runTest;
|
|
||||||
var _ = require("underscore");
|
var runTest = require('jsunity').runTest,
|
||||||
var internal = require('internal');
|
_ = require('underscore'),
|
||||||
var fs = require('fs');
|
internal = require('internal'),
|
||||||
|
fs = require('fs'),
|
||||||
|
runJSUnityTests,
|
||||||
|
runJasmineTests,
|
||||||
|
runCommandLineTests;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
/// @brief runs all jsunity tests
|
/// @brief runs all jsunity tests
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
function RunJSUnityTests (tests) {
|
runJSUnityTests = function (tests) {
|
||||||
var result = true,
|
'use strict';
|
||||||
i,
|
var result = true;
|
||||||
file,
|
|
||||||
ok;
|
|
||||||
|
|
||||||
for (i = 0; i < tests.length; ++i) {
|
_.each(tests, function (file) {
|
||||||
file = tests[i];
|
print("\nRunning JSUnity test from file '" + file + "'");
|
||||||
print();
|
|
||||||
print("running tests from file '" + file + "'");
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
ok = RunTest(file);
|
result = result && runTest(file);
|
||||||
result = result && ok;
|
} catch (err) {
|
||||||
}
|
|
||||||
catch (err) {
|
|
||||||
print("cannot run test file '" + file + "': " + err);
|
print("cannot run test file '" + file + "': " + err);
|
||||||
print(err.stack);
|
print(err.stack);
|
||||||
result = false;
|
result = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal.wait(0); // force GC
|
internal.wait(0); // force GC
|
||||||
}
|
});
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
};
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
/// @brief runs all jsunity tests
|
/// @brief runs all jsunity tests
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
function RunJasmineTests (testFiles) {
|
runJasmineTests = function (testFiles) {
|
||||||
var result = true;
|
'use strict';
|
||||||
|
var result = true,
|
||||||
|
tests,
|
||||||
|
jasmine;
|
||||||
|
|
||||||
if (testFiles.length > 0) {
|
if (testFiles.length > 0) {
|
||||||
var tests = _.map(testFiles, function (x) { return fs.read(x); }),
|
tests = _.map(testFiles, function (x) { return fs.read(x); });
|
||||||
jasmine = require('jasmine');
|
jasmine = require('jasmine');
|
||||||
|
|
||||||
print('\nRunning Jasmine Tests: ' + testFiles.join(', '));
|
print('\nRunning Jasmine Tests: ' + testFiles.join(', '));
|
||||||
|
@ -52,25 +53,26 @@ function RunJasmineTests (testFiles) {
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
};
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
/// @brief runs tests from command-line
|
/// @brief runs tests from command-line
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
function runCommandLineTests () {
|
runCommandLineTests = function () {
|
||||||
|
'use strict';
|
||||||
var result = true,
|
var result = true,
|
||||||
unitTests = internal.unitTests(),
|
unitTests = internal.unitTests(),
|
||||||
isSpecRegEx = /.+spec.js/,
|
isSpecRegEx = /.+spec.js/,
|
||||||
isSpec = function(unitTest) {
|
isSpec = function (unitTest) {
|
||||||
return isSpecRegEx.test(unitTest);
|
return isSpecRegEx.test(unitTest);
|
||||||
},
|
},
|
||||||
jasmine = _.filter(unitTests, isSpec),
|
jasmine = _.filter(unitTests, isSpec),
|
||||||
jsUnity = _.reject(unitTests, isSpec);
|
jsUnity = _.reject(unitTests, isSpec);
|
||||||
|
|
||||||
result = RunJSUnityTests(jsUnity) && RunJasmineTests(jasmine);
|
result = runJSUnityTests(jsUnity) && runJasmineTests(jasmine);
|
||||||
|
|
||||||
internal.setUnitTestsResult(result);
|
internal.setUnitTestsResult(result);
|
||||||
}
|
};
|
||||||
|
|
||||||
exports.runCommandLineTests = runCommandLineTests;
|
exports.runCommandLineTests = runCommandLineTests;
|
||||||
|
|
Loading…
Reference in New Issue