-
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
Grep directory support #1044
base: master
Are you sure you want to change the base?
Grep directory support #1044
Changes from all commits
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 |
---|---|---|
|
@@ -56,6 +56,24 @@ test("multiple files, one doesn't exist, one doesn't match", t => { | |
t.is(result.code, 2); | ||
}); | ||
|
||
test('-r option not provided, but directory is present', t => { | ||
t.truthy(fs.existsSync('test/resources')); | ||
t.truthy('/test/resources/a.txt'); | ||
const result = shell.grep(/oogabooga/, 'test/resources', 'test/resources/a.txt'); | ||
t.truthy(shell.error()); | ||
t.is(result.stderr, 'grep: test/resources Is a directory'); | ||
t.is(result.code, 2); | ||
}); | ||
|
||
test('atleast one directory or file does not exist', t => { | ||
t.truthy(fs.existsSync('test/resources')); | ||
t.falsy(fs.existsSync('test/resources/random.txt')); | ||
const result = shell.grep('-r', /oogabooga/, 'test/resources', 'test/resources/random.txt'); | ||
t.truthy(shell.error()); | ||
t.is(result.code, 2); | ||
t.is(result.stderr, 'grep: no such file or directory: test/resources/random.txt'); | ||
}); | ||
|
||
// | ||
// Valids | ||
// | ||
|
@@ -162,6 +180,30 @@ test('-i option', t => { | |
t.is(result.split('\n').length - 1, 3); | ||
}); | ||
|
||
test('one directory provided with -r option', t => { | ||
const result = shell.grep('-r', 'test', 'test/resources'); | ||
t.falsy(shell.error()); | ||
t.is(result.split('\n').length, 29); | ||
}); | ||
|
||
test('multiple directories or files provided', t => { | ||
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. We should probably split this into two separate test cases for clarity.
|
||
const result = shell.grep('-r', 'test', 'test/resources', 'test/resources/a.txt', 'test/resources/file2.txt', 'test/utils/'); | ||
t.falsy(shell.error()); | ||
t.is(result.split('\n').length, 39); | ||
}); | ||
|
||
test('directory provided in glob form', t => { | ||
const result = shell.grep('-r', 'test', 'test/r*'); | ||
t.falsy(shell.error()); | ||
t.is(result.split('\n').length, 66); | ||
}); | ||
|
||
test('works with array syntax', t => { | ||
const result = shell.grep('-r', 'test', ['test/r*', 'package.json'], 'scripts'); | ||
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. Please do not include anything outside of the resources/ folder in the test (package.json, scripts, etc.). It makes the test much more difficult to maintain if we do unrelated changes in package.json etc. I think the same goes for |
||
t.falsy(shell.error()); | ||
t.is(result.split('\n').length, 72); | ||
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. Is this the right value? I get a different answer in my shell:
|
||
}); | ||
|
||
test('the pattern looks like an option', t => { | ||
const result = shell.grep('--', '-v', 'test/resources/grep/file2'); | ||
t.falsy(shell.error()); | ||
|
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.
I think we also need to check
result.stdout
. Mygrep
will return results for the folders which actually do exist.