shell: add option for maxLines

This commit is contained in:
Girish Ramakrishnan
2024-11-18 07:59:05 +05:30
parent d7f829b3e1
commit 8f6637773b
2 changed files with 46 additions and 2 deletions

View File

@@ -27,6 +27,24 @@ describe('shell', function () {
});
});
describe('maxLines', function () {
it('maxLines=0 means unlimited', async function () {
await shell.bash('for i in {1..10}; do echo $i; sleep 1; done', { encoding: 'utf8', maxLines: 0});
});
it('maxLines=2 kills the process (stdout)', async function () {
const [error] = await safe(shell.bash('for i in {1..10}; do echo $i; sleep 1; done', { encoding: 'utf8', maxLines: 2}));
expect(error).to.be.ok();
expect(error.stdoutLineCount).to.be(2);
});
it('maxLines=2 kills the process (stderr)', async function () {
const [error] = await safe(shell.bash('for i in {1..10}; do echo $i >&2; sleep 1; done', { encoding: 'utf8', maxLines: 2}));
expect(error).to.be.ok();
expect(error.stderrLineCount).to.be(2);
});
});
describe('sudo', function () {
it('cannot sudo invalid program', function (done) {
shell.sudo([ 'randomprogram' ], {}, function (error) {