Skip to content

Commit

Permalink
replaced sys.puts with console.log and sys.print with process.stdout.…
Browse files Browse the repository at this point in the history
…write.

This is so all writes to stdout go through console.log
  • Loading branch information
tmpvar committed Jul 12, 2011
1 parent 455725b commit 29e5dfd
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 106 deletions.
13 changes: 6 additions & 7 deletions README.md
Expand Up @@ -327,13 +327,12 @@ if its missing:
var reporter = require('nodeunit').reporters.default; var reporter = require('nodeunit').reporters.default;
} }
catch(e) { catch(e) {
var sys = require('sys'); console.log("Cannot find nodeunit module.");
sys.puts("Cannot find nodeunit module."); console.log("You can download submodules for this project by doing:");
sys.puts("You can download submodules for this project by doing:"); console.log("");
sys.puts(""); console.log(" git submodule init");
sys.puts(" git submodule init"); console.log(" git submodule update");
sys.puts(" git submodule update"); console.log("");
sys.puts("");
process.exit(); process.exit();
} }


Expand Down
41 changes: 16 additions & 25 deletions lib/reporters/default.js
Expand Up @@ -11,7 +11,6 @@
var nodeunit = require('../nodeunit'), var nodeunit = require('../nodeunit'),
utils = require('../utils'), utils = require('../utils'),
fs = require('fs'), fs = require('fs'),
sys = require('sys'),
track = require('../track'), track = require('../track'),
path = require('path'); path = require('path');
AssertionError = require('../assert').AssertionError; AssertionError = require('../assert').AssertionError;
Expand Down Expand Up @@ -59,70 +58,62 @@ exports.run = function (files, options) {
}); });
var tracker = track.createTracker(function (tracker) { var tracker = track.createTracker(function (tracker) {
if (tracker.unfinished()) { if (tracker.unfinished()) {
sys.puts(''); console.log('');
sys.puts(error(bold( console.log(error(bold(
'FAILURES: Undone tests (or their setups/teardowns): ' 'FAILURES: Undone tests (or their setups/teardowns): '
))); )));
var names = tracker.names(); var names = tracker.names();
for (var i = 0; i < names.length; i += 1) { for (var i = 0; i < names.length; i += 1) {
sys.puts('- ' + names[i]); console.log('- ' + names[i]);
} }
sys.puts(''); console.log('');
sys.puts('To fix this, make sure all tests call test.done()'); console.log('To fix this, make sure all tests call test.done()');
process.reallyExit(tracker.unfinished()); process.reallyExit(tracker.unfinished());
} }
}); });


nodeunit.runFiles(paths, { nodeunit.runFiles(paths, {
moduleStart: function (name) { moduleStart: function (name) {
sys.puts('\n' + bold(name)); console.log('\n' + bold(name));
}, },
testDone: function (name, assertions) { testDone: function (name, assertions) {
tracker.remove(name); tracker.remove(name);


if (!assertions.failures()) { if (!assertions.failures()) {
sys.puts('✔ ' + name); console.log('✔ ' + name);
} }
else { else {
sys.puts(error('✖ ' + name) + '\n'); console.log(error('✖ ' + name) + '\n');
assertions.forEach(function (a) { assertions.forEach(function (a) {
if (a.failed()) { if (a.failed()) {
a = utils.betterErrors(a); a = utils.betterErrors(a);
if (a.error instanceof AssertionError && a.message) { if (a.error instanceof AssertionError && a.message) {
sys.puts( console.log(
'Assertion Message: ' + 'Assertion Message: ' +
assertion_message(a.message) assertion_message(a.message)
); );
} }
sys.puts(a.error.stack + '\n'); console.log(a.error.stack + '\n');
} }
}); });
} }
}, },
done: function (assertions) { done: function (assertions, end) {
var end = new Date().getTime(); var end = end || new Date().getTime();
var duration = end - start; var duration = end - start;
if (assertions.failures()) { if (assertions.failures()) {
sys.puts( console.log(
'\n' + bold(error('FAILURES: ')) + assertions.failures() + '\n' + bold(error('FAILURES: ')) + assertions.failures() +
'/' + assertions.length + ' assertions failed (' + '/' + assertions.length + ' assertions failed (' +
assertions.duration + 'ms)' assertions.duration + 'ms)'
); );
} }
else { else {
sys.puts( console.log(
'\n' + bold(ok('OK: ')) + assertions.length + '\n' + bold(ok('OK: ')) + assertions.length +
' assertions (' + assertions.duration + 'ms)' ' 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) { testStart: function(name) {
tracker.put(name); tracker.put(name);
Expand Down
60 changes: 27 additions & 33 deletions lib/reporters/html.js
Expand Up @@ -11,7 +11,6 @@
var nodeunit = require('../nodeunit'), var nodeunit = require('../nodeunit'),
utils = require('../utils'), utils = require('../utils'),
fs = require('fs'), fs = require('fs'),
sys = require('sys'),
path = require('path'), path = require('path'),
AssertionError = require('assert').AssertionError; AssertionError = require('assert').AssertionError;


Expand All @@ -35,77 +34,72 @@ exports.run = function (files, options) {
return path.join(process.cwd(), p); return path.join(process.cwd(), p);
}); });


sys.puts('<html>'); console.log('<html>');
sys.puts('<head>'); console.log('<head>');
sys.puts('<title></title>'); console.log('<title></title>');
sys.puts('<style type="text/css">'); console.log('<style type="text/css">');
sys.puts('body { font: 12px Helvetica Neue }'); console.log('body { font: 12px Helvetica Neue }');
sys.puts('h2 { margin:0 ; padding:0 }'); console.log('h2 { margin:0 ; padding:0 }');
sys.puts('pre { font: 11px Andale Mono; margin-left: 1em; padding-left: 1em; margin-top:0; font-size:smaller;}'); console.log('pre { font: 11px Andale Mono; margin-left: 1em; padding-left: 1em; margin-top:0; font-size:smaller;}');
sys.puts('.assertion_message { margin-left: 1em; }'); console.log('.assertion_message { margin-left: 1em; }');
sys.puts(' ol {' + console.log(' ol {' +
' list-style: none;' + ' list-style: none;' +
' margin-left: 1em;' + ' margin-left: 1em;' +
' padding-left: 1em;' + ' padding-left: 1em;' +
' text-indent: -1em;' + ' text-indent: -1em;' +
'}'); '}');
sys.puts(' ol li.pass:before { content: "\\2714 \\0020"; }'); console.log(' ol li.pass:before { content: "\\2714 \\0020"; }');
sys.puts(' ol li.fail:before { content: "\\2716 \\0020"; }'); console.log(' ol li.fail:before { content: "\\2716 \\0020"; }');
sys.puts('</style>'); console.log('</style>');
sys.puts('</head>'); console.log('</head>');
sys.puts('<body>'); console.log('<body>');
nodeunit.runFiles(paths, { nodeunit.runFiles(paths, {
moduleStart: function (name) { moduleStart: function (name) {
sys.puts('<h2>' + name + '</h2>'); console.log('<h2>' + name + '</h2>');
sys.puts('<ol>'); console.log('<ol>');
}, },
testDone: function (name, assertions) { testDone: function (name, assertions) {
if (!assertions.failures()) { if (!assertions.failures()) {
sys.puts('<li class="pass">' + name + '</li>'); console.log('<li class="pass">' + name + '</li>');
} }
else { else {
sys.puts('<li class="fail">' + name); console.log('<li class="fail">' + name);
assertions.forEach(function (a) { assertions.forEach(function (a) {
if (a.failed()) { if (a.failed()) {
a = utils.betterErrors(a); a = utils.betterErrors(a);
if (a.error instanceof AssertionError && a.message) { if (a.error instanceof AssertionError && a.message) {
sys.puts('<div class="assertion_message">' + console.log('<div class="assertion_message">' +
'Assertion Message: ' + a.message + 'Assertion Message: ' + a.message +
'</div>'); '</div>');
} }
sys.puts('<pre>'); console.log('<pre>');
sys.puts(a.error.stack); console.log(a.error.stack);
sys.puts('</pre>'); console.log('</pre>');
} }
}); });
sys.puts('</li>'); console.log('</li>');
} }
}, },
moduleDone: function () { moduleDone: function () {
sys.puts('</ol>'); console.log('</ol>');
}, },
done: function (assertions) { done: function (assertions) {
var end = new Date().getTime(); var end = new Date().getTime();
var duration = end - start; var duration = end - start;
if (assertions.failures()) { if (assertions.failures()) {
sys.puts( console.log(
'<h3>FAILURES: ' + assertions.failures() + '<h3>FAILURES: ' + assertions.failures() +
'/' + assertions.length + ' assertions failed (' + '/' + assertions.length + ' assertions failed (' +
assertions.duration + 'ms)</h3>' assertions.duration + 'ms)</h3>'
); );
} }
else { else {
sys.puts( console.log(
'<h3>OK: ' + assertions.length + '<h3>OK: ' + assertions.length +
' assertions (' + assertions.duration + 'ms)</h3>' ' assertions (' + assertions.duration + 'ms)</h3>'
); );
} }
sys.puts('</body>'); console.log('</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);
} }
}); });


Expand Down
10 changes: 3 additions & 7 deletions lib/reporters/junit.js
Expand Up @@ -11,7 +11,6 @@
var nodeunit = require('../nodeunit'), var nodeunit = require('../nodeunit'),
utils = require('../utils'), utils = require('../utils'),
fs = require('fs'), fs = require('fs'),
sys = require('sys'),
path = require('path'), path = require('path'),
async = require('../../deps/async'), async = require('../../deps/async'),
AssertionError = require('assert').AssertionError, AssertionError = require('assert').AssertionError,
Expand Down Expand Up @@ -154,28 +153,25 @@ exports.run = function (files, opts, callback) {
opts.output, opts.output,
module.name + '.xml' module.name + '.xml'
); );
sys.puts('Writing ' + filename); console.log('Writing ' + filename);
fs.writeFile(filename, rendered, cb); fs.writeFile(filename, rendered, cb);
}, },
function (err) { function (err) {
if (err) throw err; if (err) throw err;
else if (assertions.failures()) { else if (assertions.failures()) {
sys.puts( console.log(
'\n' + bold(error('FAILURES: ')) + '\n' + bold(error('FAILURES: ')) +
assertions.failures() + '/' + assertions.failures() + '/' +
assertions.length + ' assertions failed (' + assertions.length + ' assertions failed (' +
assertions.duration + 'ms)' assertions.duration + 'ms)'
); );
} }
else { else {
sys.puts( console.log(
'\n' + bold(ok('OK: ')) + assertions.length + '\n' + bold(ok('OK: ')) + assertions.length +
' assertions (' + assertions.duration + 'ms)' ' assertions (' + assertions.duration + 'ms)'
); );
} }
setTimeout(function () {
process.reallyExit(assertions.failures());
}, 10);
}); });


}); });
Expand Down
22 changes: 8 additions & 14 deletions lib/reporters/minimal.js
Expand Up @@ -11,7 +11,6 @@
var nodeunit = require('../nodeunit'), var nodeunit = require('../nodeunit'),
utils = require('../utils'), utils = require('../utils'),
fs = require('fs'), fs = require('fs'),
sys = require('sys'),
path = require('path'), path = require('path'),
AssertionError = require('assert').AssertionError; AssertionError = require('assert').AssertionError;


Expand Down Expand Up @@ -58,21 +57,21 @@ exports.run = function (files, options) {


nodeunit.runFiles(paths, { nodeunit.runFiles(paths, {
moduleStart: function (name) { moduleStart: function (name) {
sys.print(bold(name) + ': '); process.stdout.write(bold(name) + ': ');
}, },
moduleDone: function (name, assertions) { moduleDone: function (name, assertions) {
sys.puts(''); console.log('');
if (assertions.failures()) { if (assertions.failures()) {
assertions.forEach(function (a) { assertions.forEach(function (a) {
if (a.failed()) { if (a.failed()) {
a = utils.betterErrors(a); a = utils.betterErrors(a);
if (a.error instanceof AssertionError && a.message) { if (a.error instanceof AssertionError && a.message) {
sys.puts( console.log(
'Assertion in test ' + bold(a.testname) + ': ' + 'Assertion in test ' + bold(a.testname) + ': ' +
magenta(a.message) magenta(a.message)
); );
} }
sys.puts(a.error.stack + '\n'); console.log(a.error.stack + '\n');
} }
}); });
} }
Expand All @@ -82,10 +81,10 @@ exports.run = function (files, options) {
}, },
testDone: function (name, assertions) { testDone: function (name, assertions) {
if (!assertions.failures()) { if (!assertions.failures()) {
sys.print('.'); process.stdout.write('.');
} }
else { else {
sys.print(red('F')); process.stdout.write(red('F'));
assertions.forEach(function (assertion) { assertions.forEach(function (assertion) {
assertion.testname = name; assertion.testname = name;
}); });
Expand All @@ -95,23 +94,18 @@ exports.run = function (files, options) {
var end = new Date().getTime(); var end = new Date().getTime();
var duration = end - start; var duration = end - start;
if (assertions.failures()) { if (assertions.failures()) {
sys.puts( console.log(
'\n' + bold(red('FAILURES: ')) + assertions.failures() + '\n' + bold(red('FAILURES: ')) + assertions.failures() +
'/' + assertions.length + ' assertions failed (' + '/' + assertions.length + ' assertions failed (' +
assertions.duration + 'ms)' assertions.duration + 'ms)'
); );
} }
else { else {
sys.puts( console.log(
'\n' + bold(green('OK: ')) + assertions.length + '\n' + bold(green('OK: ')) + assertions.length +
' assertions (' + assertions.duration + 'ms)' ' 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);
} }
}); });
}; };

0 comments on commit 29e5dfd

Please sign in to comment.