Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Forward compatibility with node 0.3 util module #4

Closed
wants to merge 1 commit into from

1 participant

@josh

In node v0.3 sys has been renamed to util.

This patch checks for the existence of the new module, otherwise falls back to sys.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 26, 2010
  1. @josh
This page is out of date. Refresh to see the latest.
Showing with 14 additions and 14 deletions.
  1. +2 −2 lib/ns.js
  2. +12 −12 test/async_testing.js
View
4 lib/ns.js
@@ -3,7 +3,7 @@
var assert = require('assert');
var Buffer = require('buffer').Buffer;
var events = require('events');
-var sys = require('sys');
+var util = require(!!process.binding('natives').util ? 'util' : 'sys');
// Get the length of the netstring payload (i.e. excluding header and footer)
// pointed to by Buffer or String 'buf'. Returns -1 if the buffer is
@@ -213,5 +213,5 @@ var Stream = function(s) {
});
}
-sys.inherits(Stream, events.EventEmitter);
+util.inherits(Stream, events.EventEmitter);
exports.Stream = Stream;
View
24 test/async_testing.js
@@ -1,4 +1,4 @@
-var sys = require('sys'),
+var util = require(!!process.binding('natives').util ? 'util' : 'sys'),
assert = require('assert'),
events = require('events'),
fs = require('fs'),
@@ -51,7 +51,7 @@ var Test = function(name, func, suite) {
this.__failure = null;
this.__symbol = '.';
};
-sys.inherits(Test, events.EventEmitter);
+util.inherits(Test, events.EventEmitter);
Test.prototype.run = function() {
var self = this;
@@ -182,11 +182,11 @@ TestSuite.prototype.finish = function() {
output += this.tests.length + ' test' + (this.tests.length == 1 ? '' : 's') + '; ';
output += failures.length + ' failure' + (failures.length == 1 ? '' : 's') + '; ';
output += this.numAssertions + ' assertion' + (this.numAssertions == 1 ? '' : 's') + ' ';
- sys.error(output);
+ util.error(output);
- sys.error('');
+ util.error('');
failures.forEach(function(t) {
- sys.error(t.failureString());
+ util.error(t.failureString());
});
if( this.callback ) {
@@ -221,7 +221,7 @@ TestSuite.prototype.runTests = function(callback) {
if( callback ) {
this.callback = callback;
}
- sys.error('Running "' + this.name + '"');
+ util.error('Running "' + this.name + '"');
this.runTest(0);
};
TestSuite.prototype.runTest = function(testIndex) {
@@ -249,12 +249,12 @@ TestSuite.prototype.runTest = function(testIndex) {
process.addListener('uncaughtException', errorListener);
var exitListener = function() {
- sys.error("\n\nOoops! The process exited in the middle of the test '" + t.__name + "'\nDid you forget to finish it?\n");
+ util.error("\n\nOoops! The process exited in the middle of the test '" + t.__name + "'\nDid you forget to finish it?\n");
};
process.addListener('exit', exitListener);
}
else {
- sys.error(' Starting test "' + this.__name + '"');
+ util.error(' Starting test "' + this.__name + '"');
}
try {
@@ -346,7 +346,7 @@ exports.runSuites = function(module, callback) {
var suite = suites.shift();
suite.runTests(function() {
if( suites.length > 0 ) {
- sys.error('----------------------------------\n');
+ util.error('----------------------------------\n');
}
stats.numSuites++;
if( suite.numFailedTests > 0 ) {
@@ -356,7 +356,7 @@ exports.runSuites = function(module, callback) {
});
}
- sys.error('');
+ util.error('');
runNextSuite();
};
@@ -404,7 +404,7 @@ exports.runSuitesInPaths = function(paths) {
if( sts ) {
stats.numSuites += sts.numSuites;
stats.numFailed += sts.numFailed;
- sys.error('----------------------------------');
+ util.error('----------------------------------');
}
if( testFiles.length < 1 ) {
@@ -412,7 +412,7 @@ exports.runSuitesInPaths = function(paths) {
if( stats.numFailed > 0 ) {
output += ': ' + stats.numFailed + ' had failures';
}
- sys.error(output);
+ util.error(output);
return;
}
var file = testFiles.shift();
Something went wrong with that request. Please try again.