Permalink
Browse files

replaced sys.puts with console.log and sys.print with process.stdout.…

…write.

This is so all writes to stdout go through console.log
  • Loading branch information...
1 parent 455725b commit 29e5dfd1d52d95e9b47d12d783909c174bde2d54 @tmpvar committed Jul 12, 2011
Showing with 71 additions and 106 deletions.
  1. +6 −7 README.md
  2. +16 −25 lib/reporters/default.js
  3. +27 −33 lib/reporters/html.js
  4. +3 −7 lib/reporters/junit.js
  5. +8 −14 lib/reporters/minimal.js
  6. +8 −14 lib/reporters/skip_passed.js
  7. +3 −5 lib/track.js
  8. +0 −1 test/test-runfiles.js
View
13 README.md
@@ -327,13 +327,12 @@ if its missing:
var reporter = require('nodeunit').reporters.default;
}
catch(e) {
- var sys = require('sys');
- sys.puts("Cannot find nodeunit module.");
- sys.puts("You can download submodules for this project by doing:");
- sys.puts("");
- sys.puts(" git submodule init");
- sys.puts(" git submodule update");
- sys.puts("");
+ console.log("Cannot find nodeunit module.");
+ console.log("You can download submodules for this project by doing:");
+ console.log("");
+ console.log(" git submodule init");
+ console.log(" git submodule update");
+ console.log("");
process.exit();
}
View
41 lib/reporters/default.js
@@ -11,7 +11,6 @@
var nodeunit = require('../nodeunit'),
utils = require('../utils'),
fs = require('fs'),
- sys = require('sys'),
track = require('../track'),
path = require('path');
AssertionError = require('../assert').AssertionError;
@@ -59,70 +58,62 @@ exports.run = function (files, options) {
});
var tracker = track.createTracker(function (tracker) {
if (tracker.unfinished()) {
- sys.puts('');
- sys.puts(error(bold(
+ console.log('');
+ console.log(error(bold(
'FAILURES: Undone tests (or their setups/teardowns): '
)));
var names = tracker.names();
for (var i = 0; i < names.length; i += 1) {
- sys.puts('- ' + names[i]);
+ console.log('- ' + names[i]);
}
- sys.puts('');
- sys.puts('To fix this, make sure all tests call test.done()');
+ console.log('');
+ console.log('To fix this, make sure all tests call test.done()');
process.reallyExit(tracker.unfinished());
}
});
nodeunit.runFiles(paths, {
moduleStart: function (name) {
- sys.puts('\n' + bold(name));
+ console.log('\n' + bold(name));
},
testDone: function (name, assertions) {
tracker.remove(name);
if (!assertions.failures()) {
- sys.puts('' + name);
+ console.log('' + name);
}
else {
- sys.puts(error('' + name) + '\n');
+ console.log(error('' + name) + '\n');
assertions.forEach(function (a) {
if (a.failed()) {
a = utils.betterErrors(a);
if (a.error instanceof AssertionError && a.message) {
- sys.puts(
+ console.log(
'Assertion Message: ' +
assertion_message(a.message)
);
}
- sys.puts(a.error.stack + '\n');
+ console.log(a.error.stack + '\n');
}
});
}
},
- done: function (assertions) {
- var end = new Date().getTime();
+ done: function (assertions, end) {
+ var end = end || new Date().getTime();
var duration = end - start;
if (assertions.failures()) {
- sys.puts(
+ console.log(
'\n' + bold(error('FAILURES: ')) + assertions.failures() +
'/' + assertions.length + ' assertions failed (' +
assertions.duration + 'ms)'
);
}
else {
- sys.puts(
- '\n' + bold(ok('OK: ')) + assertions.length +
- ' assertions (' + assertions.duration + 'ms)'
+ console.log(
+ '\n' + bold(ok('OK: ')) + assertions.length +
+ ' assertions (' + assertions.duration + 'ms)'
);
}
- // alexgorbatchev 2010-11-10 :: should be able to flush stdout
- // here, but doesn't seem to work, instead delay the exit to give
- // enough to time flush.
- // process.stdout.flush()
- // process.stdout.end()
- setTimeout(function () {
- process.reallyExit(assertions.failures());
- }, 10);
},
testStart: function(name) {
tracker.put(name);
View
60 lib/reporters/html.js
@@ -11,7 +11,6 @@
var nodeunit = require('../nodeunit'),
utils = require('../utils'),
fs = require('fs'),
- sys = require('sys'),
path = require('path'),
AssertionError = require('assert').AssertionError;
@@ -35,77 +34,72 @@ exports.run = function (files, options) {
return path.join(process.cwd(), p);
});
- sys.puts('<html>');
- sys.puts('<head>');
- sys.puts('<title></title>');
- sys.puts('<style type="text/css">');
- sys.puts('body { font: 12px Helvetica Neue }');
- sys.puts('h2 { margin:0 ; padding:0 }');
- sys.puts('pre { font: 11px Andale Mono; margin-left: 1em; padding-left: 1em; margin-top:0; font-size:smaller;}');
- sys.puts('.assertion_message { margin-left: 1em; }');
- sys.puts(' ol {' +
+ console.log('<html>');
+ console.log('<head>');
+ console.log('<title></title>');
+ console.log('<style type="text/css">');
+ console.log('body { font: 12px Helvetica Neue }');
+ console.log('h2 { margin:0 ; padding:0 }');
+ console.log('pre { font: 11px Andale Mono; margin-left: 1em; padding-left: 1em; margin-top:0; font-size:smaller;}');
+ console.log('.assertion_message { margin-left: 1em; }');
+ console.log(' ol {' +
' list-style: none;' +
' margin-left: 1em;' +
' padding-left: 1em;' +
' text-indent: -1em;' +
'}');
- sys.puts(' ol li.pass:before { content: "\\2714 \\0020"; }');
- sys.puts(' ol li.fail:before { content: "\\2716 \\0020"; }');
- sys.puts('</style>');
- sys.puts('</head>');
- sys.puts('<body>');
+ console.log(' ol li.pass:before { content: "\\2714 \\0020"; }');
+ console.log(' ol li.fail:before { content: "\\2716 \\0020"; }');
+ console.log('</style>');
+ console.log('</head>');
+ console.log('<body>');
nodeunit.runFiles(paths, {
moduleStart: function (name) {
- sys.puts('<h2>' + name + '</h2>');
- sys.puts('<ol>');
+ console.log('<h2>' + name + '</h2>');
+ console.log('<ol>');
},
testDone: function (name, assertions) {
if (!assertions.failures()) {
- sys.puts('<li class="pass">' + name + '</li>');
+ console.log('<li class="pass">' + name + '</li>');
}
else {
- sys.puts('<li class="fail">' + name);
+ console.log('<li class="fail">' + name);
assertions.forEach(function (a) {
if (a.failed()) {
a = utils.betterErrors(a);
if (a.error instanceof AssertionError && a.message) {
- sys.puts('<div class="assertion_message">' +
+ console.log('<div class="assertion_message">' +
'Assertion Message: ' + a.message +
'</div>');
}
- sys.puts('<pre>');
- sys.puts(a.error.stack);
- sys.puts('</pre>');
+ console.log('<pre>');
+ console.log(a.error.stack);
+ console.log('</pre>');
}
});
- sys.puts('</li>');
+ console.log('</li>');
}
},
moduleDone: function () {
- sys.puts('</ol>');
+ console.log('</ol>');
},
done: function (assertions) {
var end = new Date().getTime();
var duration = end - start;
if (assertions.failures()) {
- sys.puts(
+ console.log(
'<h3>FAILURES: ' + assertions.failures() +
'/' + assertions.length + ' assertions failed (' +
assertions.duration + 'ms)</h3>'
);
}
else {
- sys.puts(
+ console.log(
'<h3>OK: ' + assertions.length +
' assertions (' + assertions.duration + 'ms)</h3>'
);
}
- sys.puts('</body>');
- // should be able to flush stdout here, but doesn't seem to work,
- // instead delay the exit to give enough to time flush.
- setTimeout(function () {
- process.reallyExit(assertions.failures());
- }, 10);
+ console.log('</body>');
}
});
View
10 lib/reporters/junit.js
@@ -11,7 +11,6 @@
var nodeunit = require('../nodeunit'),
utils = require('../utils'),
fs = require('fs'),
- sys = require('sys'),
path = require('path'),
async = require('../../deps/async'),
AssertionError = require('assert').AssertionError,
@@ -154,28 +153,25 @@ exports.run = function (files, opts, callback) {
opts.output,
module.name + '.xml'
);
- sys.puts('Writing ' + filename);
+ console.log('Writing ' + filename);
fs.writeFile(filename, rendered, cb);
},
function (err) {
if (err) throw err;
else if (assertions.failures()) {
- sys.puts(
+ console.log(
'\n' + bold(error('FAILURES: ')) +
assertions.failures() + '/' +
assertions.length + ' assertions failed (' +
assertions.duration + 'ms)'
);
}
else {
- sys.puts(
+ console.log(
'\n' + bold(ok('OK: ')) + assertions.length +
' assertions (' + assertions.duration + 'ms)'
);
}
- setTimeout(function () {
- process.reallyExit(assertions.failures());
- }, 10);
});
});
View
22 lib/reporters/minimal.js
@@ -11,7 +11,6 @@
var nodeunit = require('../nodeunit'),
utils = require('../utils'),
fs = require('fs'),
- sys = require('sys'),
path = require('path'),
AssertionError = require('assert').AssertionError;
@@ -58,21 +57,21 @@ exports.run = function (files, options) {
nodeunit.runFiles(paths, {
moduleStart: function (name) {
- sys.print(bold(name) + ': ');
+ process.stdout.write(bold(name) + ': ');
},
moduleDone: function (name, assertions) {
- sys.puts('');
+ console.log('');
if (assertions.failures()) {
assertions.forEach(function (a) {
if (a.failed()) {
a = utils.betterErrors(a);
if (a.error instanceof AssertionError && a.message) {
- sys.puts(
+ console.log(
'Assertion in test ' + bold(a.testname) + ': ' +
magenta(a.message)
);
}
- sys.puts(a.error.stack + '\n');
+ console.log(a.error.stack + '\n');
}
});
}
@@ -82,10 +81,10 @@ exports.run = function (files, options) {
},
testDone: function (name, assertions) {
if (!assertions.failures()) {
- sys.print('.');
+ process.stdout.write('.');
}
else {
- sys.print(red('F'));
+ process.stdout.write(red('F'));
assertions.forEach(function (assertion) {
assertion.testname = name;
});
@@ -95,23 +94,18 @@ exports.run = function (files, options) {
var end = new Date().getTime();
var duration = end - start;
if (assertions.failures()) {
- sys.puts(
+ console.log(
'\n' + bold(red('FAILURES: ')) + assertions.failures() +
'/' + assertions.length + ' assertions failed (' +
assertions.duration + 'ms)'
);
}
else {
- sys.puts(
+ console.log(
'\n' + bold(green('OK: ')) + assertions.length +
' assertions (' + assertions.duration + 'ms)'
);
}
- // should be able to flush stdout here, but doesn't seem to work,
- // instead delay the exit to give enough to time flush.
- setTimeout(function () {
- process.reallyExit(assertions.failures());
- }, 10);
}
});
};
View
22 lib/reporters/skip_passed.js
@@ -11,7 +11,6 @@
var nodeunit = require('../nodeunit'),
utils = require('../utils'),
fs = require('fs'),
- sys = require('sys'),
path = require('path'),
AssertionError = require('assert').AssertionError;
@@ -58,53 +57,48 @@ exports.run = function (files, options) {
nodeunit.runFiles(paths, {
moduleStart: function (name) {
- sys.puts('\n' + bold(name));
+ console.log('\n' + bold(name));
},
testDone: function (name, assertions) {
if (assertions.failures()) {
- sys.puts(error('' + name) + '\n');
+ console.log(error('' + name) + '\n');
assertions.forEach(function (a) {
if (a.failed()) {
a = utils.betterErrors(a);
if (a.error instanceof AssertionError && a.message) {
- sys.puts(
+ console.log(
'Assertion Message: ' + assertion_message(a.message)
);
}
- sys.puts(a.error.stack + '\n');
+ console.log(a.error.stack + '\n');
}
});
}
},
moduleDone: function (name, assertions) {
if (!assertions.failures()) {
- sys.puts('✔ all tests passed');
+ console.log('✔ all tests passed');
}
else {
- sys.puts(error('✖ some tests failed'));
+ console.log(error('✖ some tests failed'));
}
},
done: function (assertions) {
var end = new Date().getTime();
var duration = end - start;
if (assertions.failures()) {
- sys.puts(
+ console.log(
'\n' + bold(error('FAILURES: ')) + assertions.failures() +
'/' + assertions.length + ' assertions failed (' +
assertions.duration + 'ms)'
);
}
else {
- sys.puts(
+ console.log(
'\n' + bold(ok('OK: ')) + assertions.length +
' assertions (' + assertions.duration + 'ms)'
);
}
- // should be able to flush stdout here, but doesn't seem to work,
- // instead delay the exit to give enough to time flush.
- setTimeout(function () {
- process.reallyExit(assertions.failures());
- }, 10);
}
});
};
View
8 lib/track.js
@@ -3,8 +3,6 @@
* the undone tests.
*/
-var sys = require('sys');
-
exports.createTracker = function (on_exit) {
var names = {};
@@ -39,11 +37,11 @@ exports.createTracker = function (on_exit) {
exports.default_on_exit = function (tracker) {
if (tracker.unfinished()) {
- sys.puts('');
- sys.puts('Undone tests (or their setups/teardowns): ');
+ console.log('');
+ console.log('Undone tests (or their setups/teardowns): ');
var names = tracker.names();
for (var i = 0; i < names.length; i += 1) {
- sys.puts(names[i]);
+ console.log(names[i]);
}
process.reallyExit(tracker.unfinished());
}
View
1 test/test-runfiles.js
@@ -1,5 +1,4 @@
var assert = require('assert'),
- sys = require('sys'),
fs = require('fs'),
path = require('path'),
nodeunit = require('../lib/nodeunit');

0 comments on commit 29e5dfd

Please sign in to comment.