New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add tests for rm removing symlinks #849
base: master
Are you sure you want to change the base?
Changes from 4 commits
64a682e
c678839
1438bf1
4167033
042d17c
4639ca9
44ec920
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,11 +35,14 @@ test('file does not exist', t => { | |
t.is(result.stderr, 'rm: no such file or directory: asdfasdf'); | ||
}); | ||
|
||
test('cannot delete a directoy without recursive flag', t => { | ||
test('cannot delete a directory without recursive flag', t => { | ||
const result = shell.rm(`${t.context.tmp}/rm`); | ||
t.truthy(shell.error()); | ||
t.is(result.code, 1); | ||
t.is(result.stderr, 'rm: path is a directory'); | ||
t.truthy(fs.existsSync(`${t.context.tmp}/rm`)); | ||
const contents = fs.readdirSync(t.context.tmp); | ||
t.true(contents.length > 0); | ||
}); | ||
|
||
test('only an option', t => { | ||
|
@@ -57,6 +60,24 @@ test('invalid option', t => { | |
t.is(result.stderr, 'rm: option not recognized: @'); | ||
}); | ||
|
||
test( | ||
'cannot remove a symbolic link to a directory with trailing slash without -r flag', | ||
t => { | ||
utils.skipOnWin(t, () => { | ||
// the trailing slash signifies that we want to delete the source | ||
// directory and its contents, which can only be done with the -r flag | ||
const result = shell.rm(`${t.context.tmp}/rm/link_to_a_dir/`); | ||
t.truthy(shell.error()); | ||
t.is(result.code, 1); | ||
t.is(result.stderr, 'rm: path is a directory'); | ||
t.truthy(fs.existsSync(`${t.context.tmp}/rm/link_to_a_dir`)); | ||
t.truthy(fs.existsSync(`${t.context.tmp}/rm/a_dir`)); | ||
const contents = fs.readdirSync(`${t.context.tmp}/rm/a_dir`); | ||
t.true(contents.length > 0); | ||
}); | ||
} | ||
); | ||
|
||
// | ||
// Valids | ||
// | ||
|
@@ -259,27 +280,74 @@ test( | |
} | ||
); | ||
|
||
test('remove symbolic link to a file', t => { | ||
t.truthy(shell.test('-L', `${t.context.tmp}/link`)); | ||
const result = shell.rm(`${t.context.tmp}/link`); | ||
t.falsy(shell.error()); | ||
t.is(result.code, 0); | ||
t.falsy(shell.test('-L', `${t.context.tmp}/link`)); | ||
t.falsy(fs.existsSync(`${t.context.tmp}/link`)); | ||
t.truthy(fs.existsSync(`${t.context.tmp}/file1`)); | ||
}); | ||
|
||
test('remove symbolic link to a dir', t => { | ||
t.truthy(shell.test('-L', `${t.context.tmp}/rm/link_to_a_dir`)); | ||
const result = shell.rm(`${t.context.tmp}/rm/link_to_a_dir`); | ||
t.falsy(shell.error()); | ||
t.is(result.code, 0); | ||
t.falsy(shell.test('-L', `${t.context.tmp}/rm/link_to_a_dir`)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is already covered by the next line? Or, does There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
t.falsy(fs.existsSync(`${t.context.tmp}/rm/link_to_a_dir`)); | ||
t.truthy(fs.existsSync(`${t.context.tmp}/rm/a_dir`)); | ||
}); | ||
|
||
test('rm -rf on a symbolic link to a dir deletes its contents', t => { | ||
test('rm -r, symlink to a dir, trailing slash', t => { | ||
utils.skipOnWin(t, () => { | ||
const result = shell.rm('-r', `${t.context.tmp}/rm/link_to_a_dir/`); | ||
t.truthy(shell.error()); | ||
t.is(result.code, 1); | ||
// Both the link and original dir should remain, but contents are deleted | ||
t.truthy(fs.existsSync(`${t.context.tmp}/rm/link_to_a_dir`)); | ||
t.truthy(fs.existsSync(`${t.context.tmp}/rm/a_dir`)); | ||
t.falsy(fs.existsSync(`${t.context.tmp}/rm/a_dir/a_file`)); | ||
}); | ||
}); | ||
|
||
test('rm -rf, symlink to a dir, trailing slash', t => { | ||
utils.skipOnWin(t, () => { | ||
const result = shell.rm('-rf', `${t.context.tmp}/rm/link_to_a_dir/`); | ||
t.falsy(shell.error()); | ||
t.is(result.code, 0); | ||
|
||
// Both the link and original dir should remain, but contents are deleted | ||
t.truthy(fs.existsSync(`${t.context.tmp}/rm/link_to_a_dir`)); | ||
t.truthy(fs.existsSync(`${t.context.tmp}/rm/a_dir`)); | ||
t.falsy(fs.existsSync(`${t.context.tmp}/rm/a_dir/a_file`)); | ||
}); | ||
}); | ||
|
||
test('rm -r, symlink to a dir, no trailing slash', t => { | ||
utils.skipOnWin(t, () => { | ||
const result = shell.rm('-rf', `${t.context.tmp}/rm/link_to_a_dir`); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be |
||
t.falsy(shell.error()); | ||
t.is(result.code, 0); | ||
// The link should be deleted, but the dir and contents remain | ||
t.falsy(fs.existsSync(`${t.context.tmp}/rm/link_to_a_dir`)); | ||
t.truthy(fs.existsSync(`${t.context.tmp}/rm/a_dir`)); | ||
t.truthy(fs.existsSync(`${t.context.tmp}/rm/a_dir/a_file`)); | ||
}); | ||
}); | ||
|
||
test('rm -rf, symlink to a dir, no trailing slash', t => { | ||
utils.skipOnWin(t, () => { | ||
const result = shell.rm('-rf', `${t.context.tmp}/rm/link_to_a_dir`); | ||
t.falsy(shell.error()); | ||
t.is(result.code, 0); | ||
// The link should be deleted, but the dir and contents remain | ||
t.falsy(fs.existsSync(`${t.context.tmp}/rm/link_to_a_dir`)); | ||
t.truthy(fs.existsSync(`${t.context.tmp}/rm/a_dir`)); | ||
t.truthy(fs.existsSync(`${t.context.tmp}/rm/a_dir/a_file`)); | ||
}); | ||
}); | ||
|
||
test('remove broken symbolic link', t => { | ||
utils.skipOnWin(t, () => { | ||
t.truthy(shell.test('-L', `${t.context.tmp}/rm/fake.lnk`)); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you rephrase this as "delete the contents of the source directory, without removing the source directory itself or the link"?