echo() overrides silent()

This commit is contained in:
Artur Adib 2012-03-27 18:51:02 -04:00
parent 84cc2267ce
commit 2f3bce71d1
3 changed files with 38 additions and 6 deletions

View File

@ -777,7 +777,7 @@ exports.which = wrap('which', _which);
//@ like `.to()`.
function _echo(options) {
var messages = [].slice.call(arguments, 1);
log.apply(this, messages);
console.log.apply(this, messages);
return ShellString(messages.join(' '));
};
exports.echo = wrap('echo', _echo);
@ -868,7 +868,8 @@ exports.error = function() {
//@ silent(silentState); // restore old silent state
//@ ```
//@
//@ Suppresses all output if `state = true`. Returns state if no arguments given.
//@ Suppresses all command output if `state = true`, except for `echo()` calls.
//@ Returns state if no arguments given.
exports.silent = function(_state) {
if (typeof _state !== 'boolean')
return state.silent;

View File

@ -2,7 +2,8 @@ var shell = require('..');
var assert = require('assert'),
path = require('path'),
fs = require('fs');
fs = require('fs'),
child = require('child_process');
// Node shims for < v0.7
fs.existsSync = fs.existsSync || path.existsSync;
@ -20,7 +21,30 @@ shell.mkdir('tmp')
// Valids
//
assert.equal(shell.echo('hello world'), 'hello world');
assert.equal(shell.error(), null);
shell.exit(123);
// From here on we use child.exec() to intercept the stdout
// simple test with defaults
shell.mkdir('-p', 'tmp');
var file = 'tmp/tempscript'+Math.random()+'.js',
script = 'require(\'../../global.js\'); echo(111);';
script.to(file);
child.exec('node '+file, function(err, stdout, stderr) {
assert.ok(stdout === '111\n' || stdout === '111\nundefined\n'); // 'undefined' for v0.4
// simple test with silent(true)
shell.mkdir('-p', 'tmp');
var file = 'tmp/tempscript'+Math.random()+'.js',
script = 'require(\'../../global.js\'); silent(true); echo(555);';
script.to(file);
child.exec('node '+file, function(err, stdout, stderr) {
assert.ok(stdout === '555\n' || stdout === '555\nundefined\n'); // 'undefined' for v0.4
theEnd();
});
});
function theEnd() {
shell.exit(123);
}

View File

@ -76,6 +76,13 @@ shell.exec('node -e \"console.log(5678);\"', {async:true}, function(code, output
assert.ok(output === '5678\n' || output === '5678\nundefined\n'); // 'undefined' for v0.4
asyncFlags[0] = true;
// Most of the following code doesn't really belong here since it tests the sync version.
// However there seems to be a race condition with the stdout returned by child.exec()
// that makes the tests fail intermittently. So we're keeping them here in a chain
// to avoid this race issue
//
// check if stdout is proxied with default silent options (i.e. silent = false)
//