Skip to content

Commit

Permalink
Add --print-stdout and --print-stderr option.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kami committed Apr 13, 2011
1 parent 4e8a7a6 commit cf1d156
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
4 changes: 3 additions & 1 deletion lib/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ var OPTIONS = [
['-c', '--chdir STRING', 'Directory to which each test process chdirs before running the tests'],
['-v', '--verbosity [NUMBER]', 'Test runner verbosity'],
['-f', '--failfast', 'Exit after the first failure'],
['', '--timeout [NUMBER]', 'How long to wait (ms) for a test file to complete before timing out']
['', '--timeout [NUMBER]', 'How long to wait (ms) for a test file to complete before timing out'],
['', '--print-stdout', 'Print data which was sent to stdout'],
['', '--print-stderr', 'Print data which was sent to stderr']
];

exports.DEFAULT_TEST_TIMEOUT = DEFAULT_TEST_TIMEOUT;
Expand Down
29 changes: 25 additions & 4 deletions lib/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ var dateStart;
* @param {Function} callback Callback which is called on completion.
*/
var executeTest = function(cwd, chdir, testInitFile, filePath, failfast, timeout,
verbosity, callback) {
verbosity, printStdout, printStderr, callback) {
var fileName = path.basename(filePath);

// Timeout for init, setUp and tearDown functions
Expand Down Expand Up @@ -104,8 +104,17 @@ var executeTest = function(cwd, chdir, testInitFile, filePath, failfast, timeout
}

if (Object.keys(failedResult).length > 0 || timeouts > 0) {
common.printStderr(stderrJoined);
common.printStdout(stdoutJoined);
}
else {
if (printStderr) {
common.printStderr(stderrJoined);
}

if (printStdout) {
common.printStdout(stdoutJoined);
}
}

if (failfast && failedResult) {
Expand All @@ -127,12 +136,13 @@ process.on('exit', function() {
});

var runTests = function(cwd, initFile, testInitFile, chdir, tests, failFast,
timeout, verbosity) {
timeout, verbosity, printStdout, printStderr) {
dateStart = testUtil.getUnixTimestamp();

var executeTests = function() {
async.forEachSeries(tests, function(test, callback) {
executeTest(cwd, chdir, testInitFile, test, failFast, timeout, verbosity, callback);
executeTest(cwd, chdir, testInitFile, test, failFast, timeout, verbosity,
printStdout, printStderr, callback);
},

function(err) {
Expand Down Expand Up @@ -162,6 +172,8 @@ var run = function(cwd, argv) {
var testInitFile = null;
var chdir = null;
var failFast = false;
var printStdout = false;
var printStderr = false;
var verbosity = constants.DEFAULT_VERBOSITY;
var timeout = constants.DEFAULT_TEST_TIMEOUT;
var tests = [];
Expand Down Expand Up @@ -216,10 +228,19 @@ var run = function(cwd, argv) {
}
});

p.on('print-stdout', function(opt, value) {
printStdout = true;
});

p.on('print-stderr', function(opt, value) {
printStderr = true;
});

p.parse(process.argv);

if (tests.length > 0) {
runTests(cwd, initFile, testInitFile, chdir, tests, failFast, timeout, verbosity);
runTests(cwd, initFile, testInitFile, chdir, tests, failFast, timeout,
verbosity, printStdout, printStderr);
}
else {
sys.puts(p.banner);
Expand Down

0 comments on commit cf1d156

Please sign in to comment.