fix: Exit 1 with empty string if no match#901
fix: Exit 1 with empty string if no match#901nfischer merged 1 commit intoshelljs:masterfrom wyardley:wyardley-issue_900_grep
Conversation
|
@nfischer |
nfischer
left a comment
There was a problem hiding this comment.
Looks pretty close so far. Let me know if explanations make sense, since we don't have much documentation on these common APIs.
| 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.
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.
|
@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.
|
| t.is(result.toString(), 'this line ends in.js\nlllllllllllllllll.js\n'); | ||
| }); | ||
|
|
||
| test("one file, pattern doesn't match", t => { |
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
\nas the output), even when the regex doesn't match.Fixes #900