-
Notifications
You must be signed in to change notification settings - Fork 739
fix: Exit 1 with empty string if no match #901
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
Conversation
@nfischer
|
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.
Looks pretty close so far. Let me know if explanations make sense, since we don't have much documentation on these common
APIs.
@@ -127,6 +134,15 @@ test('one file, * in string-regex, make sure * is not globbed', t => { | |||
t.is(result.toString(), 'this line ends in.js\nlllllllllllllllll.js\n'); | |||
}); | |||
|
|||
test("one file, pattern doesn't match", t => { |
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.
Do you want this under 'valids' or 'invalids?
Even though it's a non-0 exit code, I would personally consider testing for the absence of something to be a "valid" use case, but I'm happy to move it.
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.
This spot LGTM
@nfischer Ok, how's that look. I added another test case for the specific case where there are two files, one which dne and the other of which doesn't match. I can move this to the "Invalids" section if you think that's better (see above)... |
Codecov Report
@@ Coverage Diff @@
## master #901 +/- ##
==========================================
+ Coverage 97.32% 97.32% +<.01%
==========================================
Files 34 34
Lines 1269 1271 +2
==========================================
+ Hits 1235 1237 +2
Misses 34 34
Continue to review full report at Codecov.
|
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.
LGTM % suggestions
@@ -127,6 +134,15 @@ test('one file, * in string-regex, make sure * is not globbed', t => { | |||
t.is(result.toString(), 'this line ends in.js\nlllllllllllllllll.js\n'); | |||
}); | |||
|
|||
test("one file, pattern doesn't match", t => { |
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.
This spot LGTM
When we can read all files, but none match, exit 1 and return no output. This matches the behavior of grep more closely. Fixes #900
@nfischer applied your suggestions and squashed |
Thanks. I'll merge this after I push a release (this probably constitutes a breaking change). |
Hi. This fix is still not available on the latest release v0.8.4, despite being on the master branch (https://github.com/shelljs/shelljs/blob/master/src/grep.js#L72-L75). What is its status? Was there an issue with its packaging? This fix is really needed, as the current grep implementation is broken - I would argue it's a fixing change rather than a breaking one, as anyone relying on exit code 1 to detect the absence of matches is currently broken. Thanks. |
I think this landed after v0.8.3 went out. v0.8.4 was a small patch release for a specific bug, which is why this didn't make it in that release either. I've updated the milestone field to clarify this is expected to be part of v0.9.0. I haven't had time to figure out what needs to make it in that release and what should be punted to the next release. |
@nfischer Thanks for the quick reply. Any idea when v0.9.0 might be released? It's been over 2 years now since this fix, so I'll have to use another script in the mean time. |
Resolve an issue where grep returned 0 (with a
\n
as the output), even when the regex doesn't match.Fixes #900