diff --git a/test/driver.js b/test/driver.js index 5c71b1eeff..f6d35a1d6c 100644 --- a/test/driver.js +++ b/test/driver.js @@ -11,9 +11,8 @@ tests.push({code: code, assert: assert, options: options}); }; - exports.runTests = function(config) { - var parse = config.parse, callback = config.callback; - var comments; + exports.runTests = function(config, callback) { + var parse = config.parse, comments; function onComment(block, text, start, end, startLoc, endLoc) { comments.push({ @@ -32,9 +31,11 @@ var test = tests[i]; try { comments = []; - var testOpts = JSON.parse(JSON.stringify(test.options || opts)); - if (!testOpts.onComment) testOpts.onComment = onComment; + var testOpts = test.options || opts; + var oldOnComment = testOpts.onComment; + if (!oldOnComment) testOpts.onComment = onComment; var ast = parse(test.code, testOpts); + testOpts.onComment = oldOnComment; if (test.error) { if (config.loose) { callback("ok", test.code); diff --git a/test/run.js b/test/run.js index 2fa2c8dbff..fcd40680da 100644 --- a/test/run.js +++ b/test/run.js @@ -2,26 +2,50 @@ var driver = require("./driver.js"); require("./tests.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) { - if (state != "ok") {++failed; console.log(code, message);} - ++testsRun; + if (state != "ok") {++stats.failed; console.log(code, message);} + ++stats.testsRun; } -var t0 = +new Date; +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; +} -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; +function outputStats(name, stats) { + console.log(name + ": " + stats.testsRun + " tests run in " + stats.duration + "ms; " + + (stats.failed ? stats.failed + " failures." : "all passed.")); +} -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"); +var total = {testsRun: 0, failed: 0, duration: 0}; -if (failed) { - console.log(failed + " failures."); +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); + +if (total.failed) { process.stdout.write("", function() { process.exit(1); }); -} else { - console.log("All passed."); }