Make tests runnable under node
This commit is contained in:
parent
587c790f7b
commit
03d95cda2c
@ -1,13 +1,15 @@
|
|||||||
|
(function(exports) {
|
||||||
var tests = [];
|
var tests = [];
|
||||||
|
var acorn = typeof require == "undefined" ? window.acorn : require("../acorn.js");
|
||||||
|
|
||||||
function test(code, ast, options) {
|
exports.test = function(code, ast, options) {
|
||||||
tests.push({code: code, ast: ast, options: options});
|
tests.push({code: code, ast: ast, options: options});
|
||||||
}
|
};
|
||||||
function testFail(code, message, options) {
|
exports.testFail = function(code, message, options) {
|
||||||
tests.push({code: code, error: message, options: options});
|
tests.push({code: code, error: message, options: options});
|
||||||
}
|
};
|
||||||
|
|
||||||
function runTests(callback) {
|
exports.runTests = function(callback) {
|
||||||
var opts = {linePositions: true};
|
var opts = {linePositions: true};
|
||||||
for (var i = 0; i < tests.length; ++i) {
|
for (var i = 0; i < tests.length; ++i) {
|
||||||
var test = tests[i];
|
var test = tests[i];
|
||||||
@ -30,7 +32,7 @@ function runTests(callback) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
function ppJSON(v) { return JSON.stringify(v, null, 2); }
|
function ppJSON(v) { return JSON.stringify(v, null, 2); }
|
||||||
function addPath(str, pt) {
|
function addPath(str, pt) {
|
||||||
@ -56,3 +58,4 @@ function misMatch(exp, act) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
})(typeof exports == "undefined" ? window : exports);
|
||||||
|
|||||||
14
test/run.js
Normal file
14
test/run.js
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
var driver = require("./driver.js");
|
||||||
|
require("./tests.js");
|
||||||
|
|
||||||
|
var testsRun = 0, failed = 0;
|
||||||
|
function report(state, code, message) {
|
||||||
|
if (state != "ok") {++failed; console.log(code, message);}
|
||||||
|
++testsRun;
|
||||||
|
}
|
||||||
|
|
||||||
|
var t0 = +new Date;
|
||||||
|
driver.runTests(report);
|
||||||
|
console.log(testsRun + " tests run in " + (+new Date - t0) + "ms");
|
||||||
|
if (failed) console.log(failed + " failures.");
|
||||||
|
else console.log("All passed.");
|
||||||
@ -1,6 +1,11 @@
|
|||||||
// Tests largely based on those of Esprima
|
// Tests largely based on those of Esprima
|
||||||
// (http://esprima.org/test/)
|
// (http://esprima.org/test/)
|
||||||
|
|
||||||
|
if (typeof exports != "undefined") {
|
||||||
|
var test = require("./driver.js").test;
|
||||||
|
var testFail = require("./driver.js").testFail;
|
||||||
|
}
|
||||||
|
|
||||||
test("this\n", {
|
test("this\n", {
|
||||||
type: "Program",
|
type: "Program",
|
||||||
start: {
|
start: {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user