Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
fix indentation for lint
  • Loading branch information
nfischer committed Jul 10, 2018
commit 1f15fbb118ebeff72c960144f7e761dc47bb8e59
86 changes: 41 additions & 45 deletions test/cp.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,35 +266,33 @@ test('recursive, nothing exists', t => {
});

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());
}
);
// 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', 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`));
}
);
// 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', 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
}
// 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 @@ -363,31 +361,29 @@ test('recursive, everything exists, with force flag', t => {
});

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(
// 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", 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`));
}
);
// 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 Down