shell: rewrite exec to use execFile
this also renames execFile to execArgs
This commit is contained in:
@@ -11,18 +11,18 @@ const BoxError = require('../boxerror.js'),
|
||||
shell = require('../shell.js');
|
||||
|
||||
describe('shell', function () {
|
||||
describe('execFile', function () {
|
||||
describe('execArgs', function () {
|
||||
it('can run valid program', async function () {
|
||||
await shell.promises.execFile('test', 'ls', [ '-l' ], {});
|
||||
await shell.promises.execArgs('test', 'ls', [ '-l' ], {});
|
||||
});
|
||||
|
||||
it('fails on invalid program', async function () {
|
||||
const [error] = await safe(shell.promises.execFile('test', 'randomprogram', [ ], {}));
|
||||
const [error] = await safe(shell.promises.execArgs('test', 'randomprogram', [ ], {}));
|
||||
expect(error.reason).to.be(BoxError.SHELL_ERROR);
|
||||
});
|
||||
|
||||
it('fails on failing program', async function () {
|
||||
const [error] = await safe(shell.promises.execFile('test', '/usr/bin/false', [ ], {}));
|
||||
const [error] = await safe(shell.promises.execArgs('test', '/usr/bin/false', [ ], {}));
|
||||
expect(error.reason).to.be(BoxError.SHELL_ERROR);
|
||||
});
|
||||
});
|
||||
@@ -50,10 +50,6 @@ describe('shell', function () {
|
||||
});
|
||||
|
||||
describe('exec', function () {
|
||||
it('exec a valid shell program', async function () {
|
||||
await shell.promises.exec('test', 'ls -l | wc -c', {});
|
||||
});
|
||||
|
||||
it('exec throws for invalid program', async function () {
|
||||
const [error] = await safe(shell.promises.exec('test', 'cannotexist', {}));
|
||||
expect(error.reason).to.be(BoxError.SHELL_ERROR);
|
||||
@@ -68,5 +64,14 @@ describe('shell', function () {
|
||||
const [error] = await safe(shell.promises.exec('sleeping', 'sleep 20', { timeout: 1000 }));
|
||||
expect(error.reason).to.be(BoxError.SHELL_ERROR);
|
||||
});
|
||||
|
||||
it('cannot exec a shell program by default', async function () {
|
||||
const [error] = await safe(shell.promises.exec('test', 'ls -l | wc -c', {}));
|
||||
expect(error.reason).to.be(BoxError.SHELL_ERROR);
|
||||
});
|
||||
|
||||
it('cannot exec a shell program b', async function () {
|
||||
await shell.promises.exec('test', 'ls -l | wc -c', { shell: '/bin/bash' });
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user