mirror of
https://github.com/shelljs/shelljs.git
synced 2026-01-18 16:03:37 +00:00
No change to logic. This swaps out Array.prototype.indexOf in favor for Array.prototype.includes() to simplify logic. This does the same for the equivalent String.prototype functions. Test: npm test
78 lines
2.6 KiB
JavaScript
78 lines
2.6 KiB
JavaScript
import test from 'ava';
|
|
|
|
import shell from '..';
|
|
import utils from './utils/utils';
|
|
|
|
const oldConfigSilent = shell.config.silent;
|
|
const uncaughtErrorExitCode = 1;
|
|
|
|
test.beforeEach(t => {
|
|
t.context.tmp = utils.getTempDir();
|
|
shell.config.resetForTesting();
|
|
shell.cp('-r', 'test/resources', t.context.tmp);
|
|
});
|
|
|
|
test.afterEach.always(t => {
|
|
shell.rm('-rf', t.context.tmp);
|
|
});
|
|
|
|
//
|
|
// Valids
|
|
//
|
|
|
|
test('initial values', t => {
|
|
t.false(oldConfigSilent);
|
|
t.false(shell.config.verbose);
|
|
t.false(shell.config.fatal);
|
|
t.false(shell.config.noglob);
|
|
});
|
|
|
|
test('default behavior', t => {
|
|
const result = shell.exec(JSON.stringify(shell.config.execPath) + ` -e "require('./global'); ls('file_doesnt_exist'); echo(1234);"`);
|
|
t.is(result.code, 0);
|
|
t.is(result.stdout, '1234\n');
|
|
t.is(result.stderr, 'ls: no such file or directory: file_doesnt_exist\n');
|
|
});
|
|
|
|
test('set -e', t => {
|
|
const result = shell.exec(JSON.stringify(shell.config.execPath) + ` -e "require('./global'); set('-e'); ls('file_doesnt_exist'); echo(1234);"`);
|
|
t.is(result.code, uncaughtErrorExitCode);
|
|
t.is(result.stdout, '');
|
|
t.truthy(result.stderr.includes('Error: ls: no such file or directory: file_doesnt_exist'));
|
|
});
|
|
|
|
test('set -v', t => {
|
|
const result = shell.exec(JSON.stringify(shell.config.execPath) + ` -e "require('./global'); set('-v'); ls('file_doesnt_exist'); echo(1234);"`);
|
|
t.is(result.code, 0);
|
|
t.is(result.stdout, '1234\n');
|
|
t.is(
|
|
result.stderr,
|
|
'ls file_doesnt_exist\nls: no such file or directory: file_doesnt_exist\necho 1234\n'
|
|
);
|
|
});
|
|
|
|
test('set -ev', t => {
|
|
const result = shell.exec(JSON.stringify(shell.config.execPath) + ` -e "require('./global'); set('-ev'); ls('file_doesnt_exist'); echo(1234);"`);
|
|
t.is(result.code, uncaughtErrorExitCode);
|
|
t.is(result.stdout, '');
|
|
t.truthy(result.stderr.includes('Error: ls: no such file or directory: file_doesnt_exist'));
|
|
t.truthy(result.stderr.includes('ls file_doesnt_exist\n'));
|
|
t.falsy(result.stderr.includes('echo 1234\n'));
|
|
});
|
|
|
|
test('set -e, set +e', t => {
|
|
const result = shell.exec(JSON.stringify(shell.config.execPath) + ` -e "require('./global'); set('-e'); set('+e'); ls('file_doesnt_exist'); echo(1234);"`);
|
|
t.is(result.code, 0);
|
|
t.is(result.stdout, '1234\n');
|
|
t.is(result.stderr, 'ls: no such file or directory: file_doesnt_exist\n');
|
|
});
|
|
|
|
test('set -f', t => {
|
|
shell.set('-f'); // disable globbing
|
|
shell.rm(`${t.context.tmp}/*.txt`);
|
|
t.truthy(shell.error()); // file '*.txt' doesn't exist, so rm() fails
|
|
shell.set('+f');
|
|
shell.rm(`${t.context.tmp}/*.txt`);
|
|
t.falsy(shell.error()); // globbing works, so rm succeeds
|
|
});
|