jsx
Version:
a faster, safer, easier JavaScript
57 lines (48 loc) • 1.37 kB
JavaScript
/**
* launches _Main.main(:string[]):void invoked by jsx --run|--executable
*/
JSX.runMain = function (sourceFile, args) {
var module = JSX.require(sourceFile);
if (! module) {
throw new ReferenceError("entry point module not found in " + sourceFile);
}
if (! module._Main) {
throw new ReferenceError("entry point _Main not found in " + sourceFile);
}
if (! module._Main.main) {
throw new ReferenceError("entry point _Main.main(:string[]):void not found in " + sourceFile);
}
module._Main.main(args);
};
/**
* launches _Test#test*():void invoked by jsx --test
*/
JSX.runTests = function (sourceFile, tests) {
var module = JSX.require(sourceFile);
if (! module) return;
var testClass = module._Test;
if (!testClass) return; // skip if there's no test class
if(tests.length === 0) {
var p = testClass.prototype;
for (var m in p) {
if (p[m] instanceof Function && m.match(/^test\w*$/)) {
tests.push(m);
}
}
}
var testCase = new testClass();
if (testCase.beforeClass != null)
testCase.beforeClass(tests);
for (var i = 0; i < tests.length; ++i) {
(function (method) {
if (method in testCase) {
testCase.run(method, function() { testCase[method](); });
}
else {
throw new ReferenceError("No such test method: " + method);
}
}(tests[i]));
}
if (testCase.afterClass != null)
testCase.afterClass();
};