-
Notifications
You must be signed in to change notification settings - Fork 722
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
Open
freitagbr
wants to merge
7
commits into
master
Choose a base branch
from
rm-test-coverage
base: master
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
64a682e
test(rm): add tests for removing symlinks
freitagbr c678839
test(rm): skip symlink test on windows
freitagbr 1438bf1
Rename and move test, add assertions
freitagbr 4167033
Add tests for rm -r/-f on links to dirs
freitagbr 042d17c
Properly handle rm -r on links to dirs with a trailing slash
freitagbr 4639ca9
Rephrase comment for clarity
freitagbr 44ec920
Use -r in -r test
freitagbr File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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,16 +60,23 @@ test('invalid option', t => { | |
t.is(result.stderr, 'rm: option not recognized: @'); | ||
}); | ||
|
||
test('remove symbolic link to a dir without -r fails', t => { | ||
utils.skipOnWin(t, () => { | ||
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`)); | ||
}); | ||
}); | ||
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 | ||
|
@@ -290,19 +300,54 @@ test('remove symbolic link to a dir', t => { | |
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`)); | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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"?