Permalink
Browse files

Update to use util instead of sys.

  • Loading branch information...
philjackson committed Mar 27, 2012
1 parent cee7f1e commit ece260b5447e3b41d2d806ddbd955535fa07b72a
Showing with 91 additions and 64 deletions.
  1. +0 −1 bin/twerp.coffee
  2. +0 −1 lib/runner/progress.coffee
  3. +23 −13 lib/runner/progress.js
  4. +2 −3 lib/runner/simple.coffee
  5. +30 −19 lib/runner/simple.js
  6. +3 −3 lib/runner/tiny.coffee
  7. +32 −23 lib/runner/tiny.js
  8. +1 −1 package.json
View
@@ -2,7 +2,6 @@
util = require "util"
runners = require "../lib/runner/"
-sys = require "sys"
OptionParser = require( "../vendor/parseopt" ).OptionParser
parser = new OptionParser
@@ -1,4 +1,3 @@
-sys = require "sys"
util = require "util"
TwerpTest = require( "../../lib/twerptest" ).TwerpTest
View
@@ -1,42 +1,48 @@
-var Runner, TwerpTest, sys, util;
-var __hasProp = Object.prototype.hasOwnProperty, __extends = function(child, parent) {
- for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; }
- function ctor() { this.constructor = child; }
- ctor.prototype = parent.prototype;
- child.prototype = new ctor;
- child.__super__ = parent.prototype;
- return child;
-};
-sys = require("sys");
+var Runner, TwerpTest, util,
+ __hasProp = Object.prototype.hasOwnProperty,
+ __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor; child.__super__ = parent.prototype; return child; };
+
util = require("util");
+
TwerpTest = require("../../lib/twerptest").TwerpTest;
+
Runner = require("../runner").Runner;
-exports.Progress = (function() {
- __extends(Progress, Runner);
+
+exports.Progress = (function(_super) {
+
+ __extends(Progress, _super);
+
function Progress() {
Progress.__super__.constructor.apply(this, arguments);
}
+
Progress.prototype.onStartFile = function(file) {
return this.file = file;
};
+
Progress.prototype.onStartClass = function(suite) {
this.suite = suite;
return process.stderr.write("" + suite + "\n");
};
+
Progress.prototype.onEndClass = function(suite) {};
+
Progress.prototype.onStartTest = function(testName) {
this.testName = testName;
this.testCount = 0;
return this.passCount = 0;
};
+
Progress.prototype.onEndTest = function(testName, res) {
return process.stderr.write("\n");
};
+
Progress.prototype.onAssertionPass = function() {
this.passCount++;
this.testCount++;
return this.progress();
};
+
Progress.prototype.progress = function(err) {
var color, dotCount, dots, icon, out, status, summary, testName;
if (this.passCount === this.testCount) {
@@ -62,14 +68,18 @@ exports.Progress = (function() {
return process.stderr.write("\n");
}
};
+
Progress.prototype.onAssertionFail = function(err) {
this.testCount++;
return this.progress(err);
};
+
Progress.prototype.onRunEnd = function(summary) {
process.stderr.write("Time taken: " + summary.time + "\n");
process.stderr.write("Passed: " + summary.passed + "\n");
return process.stderr.write("Failed: " + summary.failed + "\n");
};
+
return Progress;
-})();
+
+})(Runner);
View
@@ -1,4 +1,3 @@
-sys = require "sys"
util = require "util"
TwerpTest = require( "../../lib/twerptest" ).TwerpTest
@@ -9,7 +8,7 @@ class exports.Simple extends Runner
onStartClass: ( classname ) -> util.puts " #{classname}:"
onEndClass: ( classname ) ->
- onStartTest: ( testname ) -> sys.print " #{testname}: "
+ onStartTest: ( testname ) -> util.print " #{testname}: "
onEndTest: ( testname, res ) =>
msg = " #{res.passed}/#{res.count} passed"
if res.expected
@@ -22,7 +21,7 @@ class exports.Simple extends Runner
util.puts "#{msg}."
- onAssertionPass: ( ) => sys.print @green "."
+ onAssertionPass: ( ) => util.print @green "."
onAssertionFail: ( e ) =>
spcr = "\n "
errs = e.stack.split( "\n" )
View
@@ -1,34 +1,40 @@
-var Runner, TwerpTest, sys, util;
-var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, __hasProp = Object.prototype.hasOwnProperty, __extends = function(child, parent) {
- for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; }
- function ctor() { this.constructor = child; }
- ctor.prototype = parent.prototype;
- child.prototype = new ctor;
- child.__super__ = parent.prototype;
- return child;
-};
-sys = require("sys");
+var Runner, TwerpTest, util,
+ __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
+ __hasProp = Object.prototype.hasOwnProperty,
+ __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor; child.__super__ = parent.prototype; return child; };
+
util = require("util");
+
TwerpTest = require("../../lib/twerptest").TwerpTest;
+
Runner = require("../runner").Runner;
-exports.Simple = (function() {
+
+exports.Simple = (function(_super) {
+
+ __extends(Simple, _super);
+
function Simple() {
- this.onRunEnd = __bind(this.onRunEnd, this);;
- this.onAssertionFail = __bind(this.onAssertionFail, this);;
- this.onAssertionPass = __bind(this.onAssertionPass, this);;
- this.onEndTest = __bind(this.onEndTest, this);; Simple.__super__.constructor.apply(this, arguments);
+ this.onRunEnd = __bind(this.onRunEnd, this);
+ this.onAssertionFail = __bind(this.onAssertionFail, this);
+ this.onAssertionPass = __bind(this.onAssertionPass, this);
+ this.onEndTest = __bind(this.onEndTest, this);
+ Simple.__super__.constructor.apply(this, arguments);
}
- __extends(Simple, Runner);
+
Simple.prototype.onStartFile = function(filename) {
return util.puts("" + filename + ":");
};
+
Simple.prototype.onStartClass = function(classname) {
return util.puts(" " + classname + ":");
};
+
Simple.prototype.onEndClass = function(classname) {};
+
Simple.prototype.onStartTest = function(testname) {
- return sys.print(" " + testname + ": ");
+ return util.print(" " + testname + ": ");
};
+
Simple.prototype.onEndTest = function(testname, res) {
var colour, msg;
msg = " " + res.passed + "/" + res.count + " passed";
@@ -38,20 +44,25 @@ exports.Simple = (function() {
}
return util.puts("" + msg + ".");
};
+
Simple.prototype.onAssertionPass = function() {
- return sys.print(this.green("."));
+ return util.print(this.green("."));
};
+
Simple.prototype.onAssertionFail = function(e) {
var errs, spcr;
spcr = "\n ";
errs = e.stack.split("\n");
errs[0] = this.red(errs[0]);
return util.print("" + spcr + (errs.join(spcr)));
};
+
Simple.prototype.onRunEnd = function(summary) {
util.puts("Time taken: " + summary.time);
util.puts("Passed: " + summary.passed);
return util.puts("Failed: " + summary.failed);
};
+
return Simple;
-})();
+
+})(Runner);
View
@@ -1,4 +1,4 @@
-sys = require "sys"
+util = require "util"
util = require "util"
TwerpTest = require( "../../lib/twerptest" ).TwerpTest
@@ -28,11 +28,11 @@ class exports.Tiny extends Runner
util.puts "#{msg}"
onAssertionPass: ( ) =>
- sys.print "\r#{@classname}: #{@current_test}: #{++@current_test_count} "
+ util.print "\r#{@classname}: #{@current_test}: #{++@current_test_count} "
onAssertionFail: ( e ) =>
@current_test_count++
- sys.print "\r#{@classname}: #{@current_test}:"
+ util.print "\r#{@classname}: #{@current_test}:"
spcr = "\n "
errs = e.stack.split( "\n" )
errs[0] = @red errs[0]
View
@@ -1,58 +1,67 @@
-var Runner, TwerpTest, sys, util;
-var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, __hasProp = Object.prototype.hasOwnProperty, __extends = function(child, parent) {
- for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; }
- function ctor() { this.constructor = child; }
- ctor.prototype = parent.prototype;
- child.prototype = new ctor;
- child.__super__ = parent.prototype;
- return child;
-};
-sys = require("sys");
+var Runner, TwerpTest, util,
+ __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
+ __hasProp = Object.prototype.hasOwnProperty,
+ __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor; child.__super__ = parent.prototype; return child; };
+
util = require("util");
+
+util = require("util");
+
TwerpTest = require("../../lib/twerptest").TwerpTest;
+
Runner = require("../runner").Runner;
-exports.Tiny = (function() {
+
+exports.Tiny = (function(_super) {
+
+ __extends(Tiny, _super);
+
function Tiny() {
- this.onRunEnd = __bind(this.onRunEnd, this);;
- this.onAssertionFail = __bind(this.onAssertionFail, this);;
- this.onAssertionPass = __bind(this.onAssertionPass, this);;
- this.onStartTest = __bind(this.onStartTest, this);;
- this.onStartClass = __bind(this.onStartClass, this);; Tiny.__super__.constructor.apply(this, arguments);
+ this.onRunEnd = __bind(this.onRunEnd, this);
+ this.onAssertionFail = __bind(this.onAssertionFail, this);
+ this.onAssertionPass = __bind(this.onAssertionPass, this);
+ this.onStartTest = __bind(this.onStartTest, this);
+ this.onStartClass = __bind(this.onStartClass, this);
+ Tiny.__super__.constructor.apply(this, arguments);
}
- __extends(Tiny, Runner);
+
Tiny.prototype.onStartClass = function(classname) {
return this.classname = classname;
};
+
Tiny.prototype.onStartTest = function(testname) {
var matches;
- if (matches = /^test[ _]?(.+)$/.exec(testname)) {
- testname = matches[1];
- }
+ if (matches = /^test[ _]?(.+)$/.exec(testname)) testname = matches[1];
this.current_test_count = 0;
return this.current_test = testname;
};
+
Tiny.prototype.onEndTest = function(testname, res) {
var colour, msg;
msg = "\r" + this.classname + ": " + this.current_test + ":";
msg += res.expected ? (colour = res.expected !== res.count ? this.red : this.green, " " + (this.green(res.count)) + " of " + (colour(res.expected))) : void 0;
return util.puts("" + msg);
};
+
Tiny.prototype.onAssertionPass = function() {
- return sys.print("\r" + this.classname + ": " + this.current_test + ": " + (++this.current_test_count) + " ");
+ return util.print("\r" + this.classname + ": " + this.current_test + ": " + (++this.current_test_count) + " ");
};
+
Tiny.prototype.onAssertionFail = function(e) {
var errs, spcr;
this.current_test_count++;
- sys.print("\r" + this.classname + ": " + this.current_test + ":");
+ util.print("\r" + this.classname + ": " + this.current_test + ":");
spcr = "\n ";
errs = e.stack.split("\n");
errs[0] = this.red(errs[0]);
return util.print("" + spcr + (errs.join(spcr)) + "\n");
};
+
Tiny.prototype.onRunEnd = function(summary) {
util.puts("\nTime taken: " + summary.time);
util.puts("Passed: " + summary.passed);
return util.puts("Failed: " + summary.failed);
};
+
return Tiny;
-})();
+
+})(Runner);
View
@@ -1,7 +1,7 @@
{
"name": "twerp",
"description": "Really simple, class based testing framework for node and Coffeescript.",
- "version": "1.0.6",
+ "version": "1.0.7",
"bugs": { "url" : "http://github.com/philjackson/twerp/issues" },
"directories": { "lib": "./lib" },
"bin": { "twerp": "./bin/twerp" },

0 comments on commit ece260b

Please sign in to comment.