Skip to content

Commit

Permalink
mv: add tests for error on recently created files shelljs#631
Browse files Browse the repository at this point in the history
  • Loading branch information
uttpal committed Apr 11, 2017
1 parent fe8f43d commit 8f94027
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 15 deletions.
18 changes: 3 additions & 15 deletions test/cp.js
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,7 @@ test('copy mutliple files to same location', t => {
);
});

test.only('should not overwrite recently created files', t => {
test('should not overwrite recently created files', t => {
const result = shell.cp('resources/file1', 'resources/cp/file1', t.context.tmp);
t.truthy(shell.error());
t.is(result.code, 1);
Expand All @@ -727,20 +727,8 @@ test.only('should not overwrite recently created files', t => {
);
});

test.only('should not overwrite recently created files (even with force option)', t => {
const result = shell.cp('-f', 'resources/file1', 'resources/cp/file1', t.context.tmp);
t.truthy(shell.error());
t.is(result.code, 1);

// Ensure First file is copied
t.is(shell.cat(`${t.context.tmp}/file1`).toString(), 'test1');
t.is(
result.stderr,
`cp: will not overwrite just-created '${t.context.tmp}/file1' with 'resources/cp/file1'`
);
});

test.only('should not overwrite recently created files (in recursive Mode)', t => {
test('should not overwrite recently created files (in recursive Mode)', t => {
const result = shell.cp('-R', 'resources/file1', 'resources/cp/file1', t.context.tmp);
t.truthy(shell.error());
t.is(result.code, 1);
Expand All @@ -753,7 +741,7 @@ test.only('should not overwrite recently created files (in recursive Mode)', t =
);
});

test.only('should not overwrite recently created files (not give error -n mode)', t => {
test('should not overwrite recently created files (not give error no-force mode)', t => {
const result = shell.cp('-n', 'resources/file1', 'resources/cp/file1', t.context.tmp);
t.falsy(shell.error());
t.is(result.code, 0);
Expand Down
33 changes: 33 additions & 0 deletions test/mv.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,3 +206,36 @@ test('dest exists, but -f given', t => {
t.falsy(fs.existsSync('file1'));
t.truthy(fs.existsSync('file2'));
});

test('should not overwrite recently created files', t => {
shell.mkdir('-p', 't');
let result = shell.mv('file1', 'cp/file1', 't/');
t.truthy(shell.error());
t.is(result.code, 1);

// Ensure First file is copied
t.is(shell.cat('t/file1').toString(), 'test1');
t.is(
result.stderr,
"mv: will not overwrite just-created 't/file1' with 'cp/file1'"
);

result = shell.mv('t/file1', 'file1'); // revert
t.truthy(fs.existsSync('file1'));
t.truthy(fs.existsSync('cp/file1'));
});


test('should not overwrite recently created files (not give error no-force mode)', t => {
shell.mkdir('-p', 't');
let result = shell.mv('-n', 'file1', 'cp/file1', 't/');
t.falsy(shell.error());
t.is(result.code, 0);

// Ensure First file is copied
t.is(shell.cat('t/file1').toString(), 'test1');

result = shell.mv('t/file1', 'file1'); // revert
t.truthy(fs.existsSync('file1'));
t.truthy(fs.existsSync('cp/file1'));
});

0 comments on commit 8f94027

Please sign in to comment.