-
Notifications
You must be signed in to change notification settings - Fork 733
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 exit status and extra newlines #900
Comments
Yup, this is broken. Can you send a PR? Lines 69 to 71 in 4bd22e7
⬆️ You can check if the Any chance |
@nfischer I think I'm close (see commits), but as it is now, it's creating test failures for the other failure cases in a way I don't totally understand (i.e., even though there's a return after Also, do we expect stdout / stderr to be nulls or empty strings in this case? |
@wyardley thanks, I added some comments. Can you create a PR? Then I can check any travis failures. |
Yes, can do. I think you were commenting on an earlier commit, so at least a couple of those items were already fixed. I’ll adjust the remaining stuff and throw up a PR |
@nfischer: also took a look at sed, and because it doesn't add the extra I can create a test case for the case of an empty input file, though, if you want.... it would be something like this: diff --git a/test/resources/sed/empty b/test/resources/sed/empty
new file mode 100644
index 0000000..e69de29
diff --git a/test/sed.js b/test/sed.js
index fc65c54..420cf69 100644
--- a/test/sed.js
+++ b/test/sed.js
@@ -174,3 +174,9 @@ test('glob file names, with in-place-replacement', t => {
t.is(shell.cat(`${t.context.tmp}/file1.txt`).toString(), 'hello1\n');
t.is(shell.cat(`${t.context.tmp}/file2.txt`).toString(), 'hello2\n');
});
+
+test('empty file', t => {
+ const result = shell.sed('widget', 'wizzle', 'test/resources/sed/empty');
+ t.is(result.code, 0);
+ t.is(result.toString(), '');
+}); |
@wyardley thanks for investigating Do we need to check an empty file, or do you think it's sufficient to check files that don't match the pattern? That patch seems reasonable for a separate PR (it can still target this bug). |
The behavior seems the same, so I don't think it's a big thing either way... easy enough to make a PR for the extra test case if you want it tho. |
Yeah, it would be nice to explicitly test the successful return code if we aren't testing it already. |
As discussed as an aside in #900, add test case with an empty file.
Node version (or tell us if you're using electron or some other framework):
v8.11.3
ShellJS version (the most recent version/Github branch you see the bug on):
0.8.2
Operating system:
Mac OS X
Description of the bug:
grep()
returns 0, even if a string is not found, and the resulting string also contains a newline.Example ShellJS command to reproduce the error:
(given a file
testfile
without the string asdfasdf at the beginning of a line):Output of above:
I don't believe you'll have even a newline if you grep for something that isn't found, and you'll definitely get a non-0 status code if the string isn't found.
As best I could tell, the only reliable way to detect the absence of a string to use something like:
Of course, at this point, it might be easier to use regexp on the file directly, but this still seems inconsistent with the behavior of the
grep
command.The text was updated successfully, but these errors were encountered: