Permalink
Browse files

Merge pull request #30 from davidaurelio/master

Adapt to newer node versions, fix dependencies
  • Loading branch information...
2 parents 3e59153 + 90cfabf commit 5db879193d6f9f8c9b1fcb7b9d404f81811e6846 @foobarfighter committed Jan 24, 2012
Showing with 30 additions and 13 deletions.
  1. +3 −2 package.json
  2. +13 −4 src/adapters/node.js
  3. +14 −7 src/adapters/node/colors.js
View
5 package.json
@@ -4,10 +4,11 @@
, "repository" : {"type": "git", "url": "http://github.com/foobarfighter/foounit.git"}
, "author" : "Bob Remeika"
, "version" : "0.1.0"
-, "main" : "./src/adapters/node"
+, "main" : "./src/adapters/node"
, "bin" : "./bin/foounit"
, "dependencies": {
"nomnom" : ">=0.5.0",
- "fsh" : "=0.0.2"
+ "fsh" : "=0.0.2",
+ "underscore": ""
}
}
View
17 src/adapters/node.js
@@ -24,9 +24,18 @@ foounit.cli = require('./node/cli').cli;
foounit.generateSuite = require('./node/cli').generateSuite;
var adapter = (function (){
- var sys = require('sys')
+ var puts
, fs = require('fs')
- , runInThisContext = process.binding('evals').Script.runInThisContext;
+ , runInThisContext = (
+ process.binding('evals').Script || // older node versions
+ require('vm') // newer node versions
+ ).runInThisContext;
+
+ try {
+ puts = require('util').puts;
+ } catch (e) {
+ puts = require('sys').puts;
+ }
// Private variables
var self = {}, _specdir;
@@ -52,7 +61,7 @@ var adapter = (function (){
self.load = function (path){
path = foounit.translatePath(path) + '.js';
var code = fs.readFileSync(path);
- runInThisContext(code, path, true);
+ runInThisContext(code, path, true);
}
/**
@@ -82,7 +91,7 @@ var adapter = (function (){
if (example.isFailure()){
colors.putsRed('F');
colors.putsRed(example.getFullDescription());
- sys.puts(new Array(example.getFullDescription().length+1).join('='));
+ puts(new Array(example.getFullDescription().length+1).join('='));
colors.highlightSpecs(example.getException().stack);
} else if (example.isSuccess()){
colors.printGreen('.');
View
21 src/adapters/node/colors.js
@@ -1,24 +1,31 @@
// TODO: Switch to a better color library
-var sys = require('sys');
+var puts;
+try {
+ puts = require('util').puts;
+ print = require('util').print;
+} catch (e) {
+ puts = require('sys').puts;
+ print = require('sys').print;
+}
exports.putsRed = function (str){
- sys.puts('\33[31m' + str + '\33[39m');
+ puts('\33[31m' + str + '\33[39m');
}
exports.printYellow = function (str){
- sys.print('\33[33m' + str + '\33[39m');
+ print('\33[33m' + str + '\33[39m');
}
exports.putsYellow = function (str){
- sys.puts('\33[33m' + str + '\33[39m');
+ puts('\33[33m' + str + '\33[39m');
}
exports.printGreen = function (str){
- sys.print('\33[32m' + str + '\33[39m');
+ print('\33[32m' + str + '\33[39m');
}
exports.putsGreen = function (str){
- sys.puts('\33[32m' + str + '\33[39m');
+ puts('\33[32m' + str + '\33[39m');
}
exports.highlightSpecs = function (stack){
@@ -28,7 +35,7 @@ exports.highlightSpecs = function (stack){
if (line.match(/_spec\.js/)){
exports.printYellow(line + "\n");
} else {
- sys.puts(line);
+ puts(line);
}
}
}

0 comments on commit 5db8791

Please sign in to comment.