[Pkg-javascript-commits] [node-acorn-jsx] 318/484: Collect test stats separately for each mode.

Bastien Roucariès rouca at moszumanska.debian.org
Sat Aug 19 14:20:49 UTC 2017


This is an automated email from the git hooks/post-receive script.

rouca pushed a commit to branch master
in repository node-acorn-jsx.

commit 0abe4b64a804ca3fd78f80c9567948e83c37d04d
Author: Ingvar Stepanyan <me at rreverser.com>
Date:   Sun Oct 26 20:23:45 2014 +0200

    Collect test stats separately for each mode.
---
 test/driver.js | 11 ++++++-----
 test/run.js    | 50 +++++++++++++++++++++++++++++++++++++-------------
 2 files changed, 43 insertions(+), 18 deletions(-)

diff --git a/test/driver.js b/test/driver.js
index 5c71b1e..f6d35a1 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 2fa2c8d..fcd4068 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;
+}
+
+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 t0 = +new Date;
+function outputStats(name, stats) {
+  console.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};
 
-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;
+for (var name in modes) {
+  var stats = modes[name].stats;
+  outputStats(name + " parser", stats);
+  for (var key in stats) total[key] += stats[key];
+}
 
-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");
+outputStats("Total", total);
 
-if (failed) {
-  console.log(failed + " failures.");
+if (total.failed) {
   process.stdout.write("", function() {
     process.exit(1);
   });
-} else {
-  console.log("All passed.");
 }

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-acorn-jsx.git



More information about the Pkg-javascript-commits mailing list