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
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
41 changes: 16 additions & 25 deletions lib/reporters/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
60 changes: 27 additions & 33 deletions lib/reporters/html.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
var nodeunit = require('../nodeunit'),
utils = require('../utils'),
fs = require('fs'),
sys = require('sys'),
path = require('path'),
AssertionError = require('assert').AssertionError;

Expand All @@ -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>');
}
});

Expand Down
10 changes: 3 additions & 7 deletions lib/reporters/junit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
});

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

Expand Down Expand Up @@ -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');
}
});
}
Expand All @@ -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;
});
Expand All @@ -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);
}
});
};
Loading

0 comments on commit 29e5dfd

Please sign in to comment.