mirror of
https://gitlab.silvrtree.co.uk/martind2000/nci.git
synced 2025-02-11 05:09:17 +00:00
test failed shell command
This commit is contained in:
parent
26cb2aa9a1
commit
a47f9e2cdf
@ -16,16 +16,36 @@ describe('Shell command', function() {
|
|||||||
expect(shellCommand.shell).equal('/bin/sh');
|
expect(shellCommand.shell).equal('/bin/sh');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
var collectData = function(result, field) {
|
||||||
|
return function(data) {
|
||||||
|
result[field] += data;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
var std = {out: '', err: ''};
|
||||||
it('echo "Hello world" should be done', function(done) {
|
it('echo "Hello world" should be done', function(done) {
|
||||||
var stdout = '';
|
shellCommand.on('stdout', collectData(std, 'out'));
|
||||||
shellCommand.on('stdout', function(data) {
|
shellCommand.on('stderr', collectData(std, 'err'));
|
||||||
stdout += data;
|
shellCommand.run({cmd: 'echo "Hello world1"'}, function(err) {
|
||||||
});
|
|
||||||
shellCommand.run({cmd: 'echo "Hello world"'}, function(err) {
|
|
||||||
expect(err).not.ok();
|
expect(err).not.ok();
|
||||||
expect(stdout).equal('Hello world\n');
|
expect(std.err).equal('');
|
||||||
|
expect(std.out).equal('Hello world1\n');
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('echo1 "Hello world" should fails', function(done) {
|
||||||
|
std.out = '';
|
||||||
|
std.err = '';
|
||||||
|
shellCommand.run({cmd: 'echo1 "Hello world"'}, function(err) {
|
||||||
|
expect(err).ok();
|
||||||
|
expect(err).an(Error);
|
||||||
|
expect(err.message).equal(
|
||||||
|
'Spawned command outputs to stderr: /bin/sh: 1: echo1: not found\n'
|
||||||
|
);
|
||||||
|
expect(std.err).equal('');
|
||||||
|
expect(std.out).equal('');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user