Permalink
Browse files

Added success and failure count to ConsoleReporter, and made the node…

… example exit based on that
  • Loading branch information...
1 parent b022867 commit f8cc672cb3fcda1ccdf58a6ca3381564149f01c7 @ianb committed Oct 5, 2012
Showing with 10 additions and 1 deletion.
  1. +3 −0 doctest.js
  2. +7 −1 examples/node-example.js
View
3 doctest.js
@@ -302,13 +302,16 @@ HTMLReporter.prototype = {
var ConsoleReporter = exports.ConsoleReporter = function (runner) {
this.runner = runner;
+ this.successes = this.failures = 0;
};
ConsoleReporter.prototype = {
logSuccess: function (example, got) {
+ this.successes++;
console.log('Passed:', example.textSummary());
},
logFailure: function (example, got) {
+ this.failures++;
console.log('Failed:', example.expr);
console.log('Expected:');
console.log(example.expected);
View
8 examples/node-example.js
@@ -1,6 +1,12 @@
-var doctest = require('./doctest.js');
+var doctest = require('../doctest.js');
var runner = new doctest.Runner({Reporter: doctest.ConsoleReporter});
var parser = new doctest.TextParser.fromFile(runner, './examples-2.js');
parser.parse();
runner.run();
+var reporter = runner.reporter;
+console.log('Successes:', reporter.successes);
+console.log('Failures:', reporter.failures);
+if ((! reporter.successes) || reporter.failures) {
+ process.exit(1);
+}

0 comments on commit f8cc672

Please sign in to comment.