Skip to content

Commit

Permalink
chore: rename some tests (#871)
Browse files Browse the repository at this point in the history
No change to logic.

This renames some tests to be a bit more readable.
  • Loading branch information
nfischer committed Jul 11, 2018
1 parent 131b88f commit 6d66a1a
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 74 deletions.
129 changes: 58 additions & 71 deletions test/cp.js
Expand Up @@ -54,7 +54,7 @@ test('invalid option', t => {
t.is(result.stderr, 'cp: option not recognized: @');
});

test('invalid option', t => {
test('invalid option #2', t => {
const result = shell.cp('-Z', 'asdfasdf', `${t.context.tmp}/file2`);
t.truthy(shell.error());
t.is(result.code, 1);
Expand Down Expand Up @@ -265,39 +265,34 @@ test('recursive, nothing exists', t => {
t.is(shell.ls('-R', 'test/resources/cp').toString(), shell.ls('-R', `${t.context.tmp}/cp`).toString());
});

test(
'recursive, nothing exists, source ends in \'/\' (see Github issue #15)',
t => {
const result = shell.cp('-R', 'test/resources/cp/', `${t.context.tmp}/`);
t.falsy(shell.error());
t.falsy(result.stderr);
t.is(result.code, 0);
t.is(shell.ls('-R', 'test/resources/cp').toString(), shell.ls('-R', `${t.context.tmp}/cp`).toString());
}
);
test('recursive, nothing exists, source ends in "/"', t => {
// Github issue #15
const result = shell.cp('-R', 'test/resources/cp/', `${t.context.tmp}/`);
t.falsy(shell.error());
t.falsy(result.stderr);
t.is(result.code, 0);
t.is(shell.ls('-R', 'test/resources/cp').toString(), shell.ls('-R', `${t.context.tmp}/cp`).toString());
});

test(
'recursive, globbing regular files with extension (see Github issue #376)',
t => {
const result = shell.cp('-R', 'test/resources/file*.txt', t.context.tmp);
t.falsy(shell.error());
t.falsy(result.stderr);
t.is(result.code, 0);
t.truthy(fs.existsSync(`${t.context.tmp}/file1.txt`));
t.truthy(fs.existsSync(`${t.context.tmp}/file2.txt`));
}
);
test('recursive, globbing regular files with extension', t => {
// Github issue #376
const result = shell.cp('-R', 'test/resources/file*.txt', t.context.tmp);
t.falsy(shell.error());
t.falsy(result.stderr);
t.is(result.code, 0);
t.truthy(fs.existsSync(`${t.context.tmp}/file1.txt`));
t.truthy(fs.existsSync(`${t.context.tmp}/file2.txt`));
});

test(
'recursive, copying one regular file (also related to Github issue #376)',
t => {
const result = shell.cp('-R', 'test/resources/file1.txt', t.context.tmp);
t.falsy(shell.error());
t.falsy(result.stderr);
t.is(result.code, 0);
t.truthy(fs.existsSync(`${t.context.tmp}/file1.txt`));
t.falsy(common.statFollowLinks(`${t.context.tmp}/file1.txt`).isDirectory()); // don't let it be a dir
}
test('recursive, copying one regular file', t => {
// Github issue #376
const result = shell.cp('-R', 'test/resources/file1.txt', t.context.tmp);
t.falsy(shell.error());
t.falsy(result.stderr);
t.is(result.code, 0);
t.truthy(fs.existsSync(`${t.context.tmp}/file1.txt`));
t.falsy(common.statFollowLinks(`${t.context.tmp}/file1.txt`).isDirectory()); // don't let it be a dir
}
);

test('recursive, everything exists, no force flag', t => {
Expand Down Expand Up @@ -365,34 +360,30 @@ test('recursive, everything exists, with force flag', t => {
t.is(shell.cat('test/resources/cp/dir_a/z').toString(), shell.cat(`${t.context.tmp}/cp/dir_a/z`).toString()); // after cp
});

test(
'recursive, creates dest dir since it\'s only one level deep (see Github issue #44)',
t => {
const result = shell.cp('-r', 'test/resources/issue44', `${t.context.tmp}/dir2`);
t.falsy(shell.error());
t.falsy(result.stderr);
t.is(result.code, 0);
t.is(shell.ls('-R', 'test/resources/issue44').toString(), shell.ls('-R', `${t.context.tmp}/dir2`).toString());
t.is(
test("recursive, creates dest dir since it's only one level deep", t => {
// Github issue #44
const result = shell.cp('-r', 'test/resources/issue44', `${t.context.tmp}/dir2`);
t.falsy(shell.error());
t.falsy(result.stderr);
t.is(result.code, 0);
t.is(shell.ls('-R', 'test/resources/issue44').toString(), shell.ls('-R', `${t.context.tmp}/dir2`).toString());
t.is(
shell.cat('test/resources/issue44/main.js').toString(),
shell.cat(`${t.context.tmp}/dir2/main.js`).toString()
);
}
);
});

test(
'recursive, does *not* create dest dir since it\'s too deep (see Github issue #44)',
t => {
const result = shell.cp('-r', 'test/resources/issue44', `${t.context.tmp}/dir2/dir3`);
t.truthy(shell.error());
t.is(
result.stderr,
`cp: cannot create directory '${t.context.tmp}/dir2/dir3': No such file or directory`
);
t.is(result.code, 1);
t.falsy(fs.existsSync(`${t.context.tmp}/dir2`));
}
);
test("recursive, does *not* create dest dir since it's too deep", t => {
// Github issue #44
const result = shell.cp('-r', 'test/resources/issue44', `${t.context.tmp}/dir2/dir3`);
t.truthy(shell.error());
t.is(
result.stderr,
`cp: cannot create directory '${t.context.tmp}/dir2/dir3': No such file or directory`
);
t.is(result.code, 1);
t.falsy(fs.existsSync(`${t.context.tmp}/dir2`));
});

test('recursive, copies entire directory', t => {
const result = shell.cp('-r', 'test/resources/cp/dir_a', `${t.context.tmp}/dest`);
Expand All @@ -409,21 +400,17 @@ test('recursive, with trailing slash, does the exact same', t => {
t.truthy(fs.existsSync(`${t.context.tmp}/dest/z`));
});

test(
'On Windows, permission bits are quite different so skip those tests for now',
t => {
utils.skipOnWin(t, () => {
// preserve mode bits
const execBit = parseInt('001', 8);
t.is(common.statFollowLinks('test/resources/cp-mode-bits/executable').mode & execBit, execBit);
shell.cp('test/resources/cp-mode-bits/executable', `${t.context.tmp}/executable`);
t.is(
common.statFollowLinks('test/resources/cp-mode-bits/executable').mode,
common.statFollowLinks(`${t.context.tmp}/executable`).mode
);
});
}
);
test('preserve mode bits by default for file', t => {
utils.skipOnWin(t, () => {
const execBit = parseInt('001', 8);
t.is(common.statFollowLinks('test/resources/cp-mode-bits/executable').mode & execBit, execBit);
shell.cp('test/resources/cp-mode-bits/executable', `${t.context.tmp}/executable`);
t.is(
common.statFollowLinks('test/resources/cp-mode-bits/executable').mode,
common.statFollowLinks(`${t.context.tmp}/executable`).mode
);
});
});

test('Make sure hidden files are copied recursively', t => {
shell.rm('-rf', t.context.tmp);
Expand Down
6 changes: 3 additions & 3 deletions test/echo.js
Expand Up @@ -31,7 +31,7 @@ test('simple test with defaults', t => {
});

test('allow arguments to begin with a hyphen', t => {
// see issue #20
// Github issue #20
const result = shell.echo('-asdf', '111');
const stdout = mocks.stdout();
const stderr = mocks.stderr();
Expand Down Expand Up @@ -62,7 +62,7 @@ test('-e option', t => {
});

test('piping to a file', t => {
// see issue #476
// Github issue #476
shell.mkdir(t.context.tmp);
const tmp = `${t.context.tmp}/echo.txt`;
const resultA = shell.echo('A').toEnd(tmp);
Expand Down Expand Up @@ -121,7 +121,7 @@ test('-en option with escaped characters', t => {
});

test('piping to a file with -n', t => {
// see issue #476
// Github issue #476
shell.mkdir(t.context.tmp);
const tmp = `${t.context.tmp}/echo.txt`;
const resultA = shell.echo('-n', 'A').toEnd(tmp);
Expand Down

0 comments on commit 6d66a1a

Please sign in to comment.