Added loose parser support to test runner (currently failing for 208/1680).
This commit is contained in:
parent
d424874cf8
commit
7db211d56a
@ -11,7 +11,8 @@
|
||||
tests.push({code: code, assert: assert, options: options});
|
||||
};
|
||||
|
||||
exports.runTests = function(parse, callback) {
|
||||
exports.runTests = function(config) {
|
||||
var parse = config.parse, callback = config.callback;
|
||||
var comments;
|
||||
|
||||
function onComment(block, text, start, end, startLoc, endLoc) {
|
||||
@ -32,9 +33,14 @@
|
||||
try {
|
||||
comments = [];
|
||||
if (test.options && !test.options.onComment) test.options.onComment = onComment;
|
||||
var ast = acorn.parse(test.code, test.options || opts);
|
||||
if (test.error) callback("fail", test.code,
|
||||
"Expected error message: " + test.error + "\nBut parsing succeeded.");
|
||||
var ast = parse(test.code, test.options || opts);
|
||||
if (test.error) {
|
||||
if (config.loose) {
|
||||
callback("ok", test.code);
|
||||
} else {
|
||||
callback("fail", test.code, "Expected error message: " + test.error + "\nBut parsing succeeded.");
|
||||
}
|
||||
}
|
||||
else if (test.assert) {
|
||||
var error = test.assert(ast);
|
||||
if (error) callback("fail", test.code,
|
||||
|
||||
10
test/run.js
10
test/run.js
@ -9,8 +9,12 @@ function report(state, code, message) {
|
||||
}
|
||||
|
||||
var t0 = +new Date;
|
||||
var acorn = typeof require == "undefined" ? window.acorn : require("../acorn.js");
|
||||
driver.runTests(acorn.parse, report);
|
||||
|
||||
var parse = (typeof require === "undefined" ? window.acorn : require("../acorn.js")).parse;
|
||||
var parse_dammit = (typeof require === "undefined") ? window.acorn_loose : require("../acorn_loose").parse_dammit;
|
||||
|
||||
driver.runTests({parse: parse, callback: report});
|
||||
driver.runTests({parse: parse_dammit, loose: true, callback: report});
|
||||
console.log(testsRun + " tests run in " + (+new Date - t0) + "ms");
|
||||
|
||||
if (failed) {
|
||||
@ -20,4 +24,4 @@ if (failed) {
|
||||
});
|
||||
} else {
|
||||
console.log("All passed.");
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user