As I think about this, I don't think that program-termination is really
the right time to output a testing summary.  It only appears to be the
right time because the typical way in which we run tests is with the -l
switch from the command line in a batch invocation of a fresh instance of
conkeror, but it is clearly not the right time if conkeror is not
immediately exited after testing.  Instead, I would propose a command-line
switch called -walnut-summary (or -walnut-summarize?), to give the user
true control over the time of summary generation, without introducing new
assumptions about the manner in which tests will be loaded.  What say you?

You're quite right. Indeed, it needn't be a switch; it can be a command invoked with -f. See patch below.

In addition though, I still think it would be convenient, for the specific instance of a "command line batch invocation in a fresh instance of conkeror", to have the summary without specifically asking for it. That can be achieved using the exiting_hook given in another thread. But how do I test whether we are in this stand alone batch mode?

Subject: [PATCH] New command walnut-summarize

This provides summary results such as the following:

% conkeror -q -batch -l tests/simple -f walnut-summarize
...
Totals: 78 run, 0 failed in 18 suites
---
 modules/walnut.js |   27 ++++++++++++++++++++++++++-
 1 files changed, 26 insertions(+), 1 deletions(-)

diff --git a/modules/walnut.js b/modules/walnut.js
index 8cb3048..34062ec 100644
--- a/modules/walnut.js
+++ b/modules/walnut.js
@@ -57,7 +57,31 @@ function assert_objects_equal (got, expect) {
 function walnut_results () {
     this.run = 0;
     this.failed = 0;
+    this.suites = 0;
 }
+walnut_results.prototype = {
+    show : function (title) {
+        dumpln((title ? title + ": " : "") +
+               this.run +" run, " + this.failed + " failed" +
+               (this.suites > 1 ? " in " + this.suites + " suites" : ""));
+    },
+    accumulate : function (results) {
+        this.run += results.run;
+        this.failed += results.failed;
+        this.suites += results.suites ? results.suites : 1;
+    }
+}
+
+var walnut_totals = new walnut_results();
+
+function walnut_summarize (keep) {
+    walnut_totals.show("Totals");
+    if (!keep)
+        walnut_totals = new walnut_results();
+}
+interactive("walnut-summarize",
+ "Print summary of walnut results. With prefix, keep results to " + + "accumulate with future walnut runs. By default results are " +
+            "discarded.",
+            function(I) {walnut_summarize(I.P);});

 function walnut_run (suite) {
     var results = new walnut_results();
@@ -83,7 +107,8 @@ function walnut_run (suite) {
     }
     if (suite.suite_teardown)
         suite.suite_teardown();
-    dumpln(results.run+" run, "+results.failed+" failed");
+    results.show();
+    walnut_totals.accumulate(results);
     return results;
 }
_______________________________________________
Conkeror mailing list
[email protected]
https://www.mozdev.org/mailman/listinfo/conkeror

Reply via email to