Collect test stats separately for each mode.
This commit is contained in:
parent
b7367a2a8c
commit
0abe4b64a8
@ -11,9 +11,8 @@
|
|||||||
tests.push({code: code, assert: assert, options: options});
|
tests.push({code: code, assert: assert, options: options});
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.runTests = function(config) {
|
exports.runTests = function(config, callback) {
|
||||||
var parse = config.parse, callback = config.callback;
|
var parse = config.parse, comments;
|
||||||
var comments;
|
|
||||||
|
|
||||||
function onComment(block, text, start, end, startLoc, endLoc) {
|
function onComment(block, text, start, end, startLoc, endLoc) {
|
||||||
comments.push({
|
comments.push({
|
||||||
@ -32,9 +31,11 @@
|
|||||||
var test = tests[i];
|
var test = tests[i];
|
||||||
try {
|
try {
|
||||||
comments = [];
|
comments = [];
|
||||||
var testOpts = JSON.parse(JSON.stringify(test.options || opts));
|
var testOpts = test.options || opts;
|
||||||
if (!testOpts.onComment) testOpts.onComment = onComment;
|
var oldOnComment = testOpts.onComment;
|
||||||
|
if (!oldOnComment) testOpts.onComment = onComment;
|
||||||
var ast = parse(test.code, testOpts);
|
var ast = parse(test.code, testOpts);
|
||||||
|
testOpts.onComment = oldOnComment;
|
||||||
if (test.error) {
|
if (test.error) {
|
||||||
if (config.loose) {
|
if (config.loose) {
|
||||||
callback("ok", test.code);
|
callback("ok", test.code);
|
||||||
|
|||||||
48
test/run.js
48
test/run.js
@ -2,26 +2,50 @@ var driver = require("./driver.js");
|
|||||||
require("./tests.js");
|
require("./tests.js");
|
||||||
require("./tests-harmony.js");
|
require("./tests-harmony.js");
|
||||||
|
|
||||||
var testsRun = 0, failed = 0;
|
var stats, modes = {
|
||||||
|
Normal: {
|
||||||
|
config: {
|
||||||
|
parse: (typeof require === "undefined" ? window.acorn : require("../acorn.js")).parse
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Loose: {
|
||||||
|
config: {
|
||||||
|
parse: (typeof require === "undefined") ? window.acorn_loose : require("../acorn_loose").parse_dammit,
|
||||||
|
loose: true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
function report(state, code, message) {
|
function report(state, code, message) {
|
||||||
if (state != "ok") {++failed; console.log(code, message);}
|
if (state != "ok") {++stats.failed; console.log(code, message);}
|
||||||
++testsRun;
|
++stats.testsRun;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (var name in modes) {
|
||||||
|
var mode = modes[name];
|
||||||
|
stats = mode.stats = {testsRun: 0, failed: 0};
|
||||||
var t0 = +new Date;
|
var t0 = +new Date;
|
||||||
|
driver.runTests(mode.config, report);
|
||||||
|
mode.stats.duration = +new Date - t0;
|
||||||
|
}
|
||||||
|
|
||||||
var parse = (typeof require === "undefined" ? window.acorn : require("../acorn.js")).parse;
|
function outputStats(name, stats) {
|
||||||
var parse_dammit = (typeof require === "undefined") ? window.acorn_loose : require("../acorn_loose").parse_dammit;
|
console.log(name + ": " + stats.testsRun + " tests run in " + stats.duration + "ms; " +
|
||||||
|
(stats.failed ? stats.failed + " failures." : "all passed."));
|
||||||
|
}
|
||||||
|
|
||||||
driver.runTests({parse: parse, callback: report});
|
var total = {testsRun: 0, failed: 0, duration: 0};
|
||||||
driver.runTests({parse: parse_dammit, loose: true, callback: report});
|
|
||||||
console.log(testsRun + " tests run in " + (+new Date - t0) + "ms");
|
|
||||||
|
|
||||||
if (failed) {
|
for (var name in modes) {
|
||||||
console.log(failed + " failures.");
|
var stats = modes[name].stats;
|
||||||
|
outputStats(name + " parser", stats);
|
||||||
|
for (var key in stats) total[key] += stats[key];
|
||||||
|
}
|
||||||
|
|
||||||
|
outputStats("Total", total);
|
||||||
|
|
||||||
|
if (total.failed) {
|
||||||
process.stdout.write("", function() {
|
process.stdout.write("", function() {
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
});
|
});
|
||||||
} else {
|
|
||||||
console.log("All passed.");
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user