Web-driver support for loose parser + small fixes.
* Added support for acorn_loose and grouped log to web-driver. * Removed unused copy-pasted `parseTemplate` from loose parser. * Throw non-SyntaxError errors immediately (as those are generic).
This commit is contained in:
committed by
Marijn Haverbeke
parent
6bf8311061
commit
96ccdb05fa
138
test/run.js
138
test/run.js
@@ -1,56 +1,104 @@
|
||||
var driver = require("./driver.js");
|
||||
require("./tests.js");
|
||||
require("./tests-harmony.js");
|
||||
(function() {
|
||||
var driver;
|
||||
|
||||
var stats, modes = {
|
||||
Normal: {
|
||||
config: {
|
||||
parse: (typeof require === "undefined" ? window.acorn : require("../acorn.js")).parse
|
||||
if (typeof require !== "undefined") {
|
||||
driver = require("./driver.js");
|
||||
require("./tests.js");
|
||||
require("./tests-harmony.js");
|
||||
} else {
|
||||
driver = window;
|
||||
}
|
||||
|
||||
var htmlLog = typeof document === "object" && document.getElementById('log');
|
||||
var htmlGroup;
|
||||
|
||||
function group(name) {
|
||||
if (htmlLog) {
|
||||
htmlGroup = document.createElement("ul");
|
||||
var item = document.createElement("li");
|
||||
item.textContent = name;
|
||||
item.appendChild(htmlGroup);
|
||||
htmlLog.appendChild(item);
|
||||
}
|
||||
},
|
||||
Loose: {
|
||||
config: {
|
||||
parse: (typeof require === "undefined") ? window.acorn_loose : require("../acorn_loose").parse_dammit,
|
||||
loose: true,
|
||||
filter: function (test) {
|
||||
var opts = test.options || {};
|
||||
if (opts.loose === false) return false;
|
||||
return (opts.ecmaVersion || 5) <= 6;
|
||||
}
|
||||
if (typeof console === "object" && console.group) {
|
||||
console.group(name);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
function report(state, code, message) {
|
||||
if (state != "ok") {++stats.failed; console.log(code, message);}
|
||||
++stats.testsRun;
|
||||
}
|
||||
function groupEnd() {
|
||||
htmlGroup = null;
|
||||
if (typeof console === "object" && console.groupEnd) {
|
||||
console.groupEnd(name);
|
||||
}
|
||||
}
|
||||
|
||||
for (var name in modes) {
|
||||
var mode = modes[name];
|
||||
stats = mode.stats = {testsRun: 0, failed: 0};
|
||||
var t0 = +new Date;
|
||||
driver.runTests(mode.config, report);
|
||||
mode.stats.duration = +new Date - t0;
|
||||
}
|
||||
function log(title, message) {
|
||||
if (htmlGroup) {
|
||||
var elem = document.createElement("li");
|
||||
elem.innerHTML = "<b>" + title + "</b> " + message;
|
||||
htmlGroup.appendChild(elem);
|
||||
}
|
||||
if (typeof console === "object") console.log(title, message);
|
||||
}
|
||||
|
||||
function outputStats(name, stats) {
|
||||
console.log(name + ": " + stats.testsRun + " tests run in " + stats.duration + "ms; " +
|
||||
(stats.failed ? stats.failed + " failures." : "all passed."));
|
||||
}
|
||||
var stats, modes = {
|
||||
Normal: {
|
||||
config: {
|
||||
parse: (typeof require === "undefined" ? window.acorn : require("../acorn.js")).parse
|
||||
}
|
||||
},
|
||||
Loose: {
|
||||
config: {
|
||||
parse: (typeof require === "undefined" ? window.acorn : require("../acorn_loose")).parse_dammit,
|
||||
loose: true,
|
||||
filter: function (test) {
|
||||
var opts = test.options || {};
|
||||
if (opts.loose === false) return false;
|
||||
return (opts.ecmaVersion || 5) <= 6;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var total = {testsRun: 0, failed: 0, duration: 0};
|
||||
function report(state, code, message) {
|
||||
if (state != "ok") {++stats.failed; log(code, message);}
|
||||
++stats.testsRun;
|
||||
}
|
||||
|
||||
for (var name in modes) {
|
||||
var stats = modes[name].stats;
|
||||
outputStats(name + " parser", stats);
|
||||
for (var key in stats) total[key] += stats[key];
|
||||
}
|
||||
group("Errors");
|
||||
|
||||
outputStats("Total", total);
|
||||
for (var name in modes) {
|
||||
var mode = modes[name];
|
||||
stats = mode.stats = {testsRun: 0, failed: 0};
|
||||
var t0 = +new Date;
|
||||
driver.runTests(mode.config, report);
|
||||
mode.stats.duration = +new Date - t0;
|
||||
}
|
||||
|
||||
if (total.failed) {
|
||||
process.stdout.write("", function() {
|
||||
process.exit(1);
|
||||
});
|
||||
}
|
||||
groupEnd();
|
||||
|
||||
function outputStats(name, stats) {
|
||||
log(name + ":", stats.testsRun + " tests run in " + stats.duration + "ms; " +
|
||||
(stats.failed ? stats.failed + " failures." : "all passed."));
|
||||
}
|
||||
|
||||
var total = {testsRun: 0, failed: 0, duration: 0};
|
||||
|
||||
group("Stats");
|
||||
|
||||
for (var name in modes) {
|
||||
var stats = modes[name].stats;
|
||||
outputStats(name + " parser", stats);
|
||||
for (var key in stats) total[key] += stats[key];
|
||||
}
|
||||
|
||||
outputStats("Total", total);
|
||||
|
||||
groupEnd();
|
||||
|
||||
if (total.failed && typeof process === "object") {
|
||||
process.stdout.write("", function() {
|
||||
process.exit(1);
|
||||
});
|
||||
}
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user