-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Try parsing the stdout of *grep even in case of an error. This allows to return output when hitting, for instance, eperms on certain files. The stderr of *grep is now logged directly while the exit code is being recorded and used by vgrep on exit. Fixes: #216 Signed-off-by: Valentin Rothberg <[email protected]>
- Loading branch information
Showing
3 changed files
with
64 additions
and
12 deletions.
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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#!/usr/bin/env bats -t | ||
|
||
load helpers | ||
|
||
# Create a write-only file which causes the *grep implementations to fail. In | ||
# that case, vgrep should still parse the stdout of *grep and return the error | ||
# reported on stdout along with the exit code. | ||
|
||
WONLY_FILE=test/search_files/wonly.txt | ||
|
||
function setup() { | ||
touch $WONLY_FILE | ||
chmod 200 $WONLY_FILE | ||
} | ||
|
||
function teardown() { | ||
rm $WONLY_FILE | ||
} | ||
|
||
@test "Search with permission error" { | ||
run_vgrep --no-header foo test/search_files | ||
[ "$status" -eq 2 ] | ||
[[ ${lines[0]} =~ "test/search_files/wonly.txt: Permission denied (os error 13)" ]] | ||
[[ ${lines[1]} =~ "bar baz" ]] | ||
} | ||
|
||
@test "Search with permission error (--no-ripgrep)" { | ||
# Since the file isn't under version control, git will not try to read it | ||
run_vgrep --no-header --no-ripgrep foo test/search_files | ||
[ "$status" -eq 0 ] | ||
[[ ${lines[0]} =~ "bar baz" ]] | ||
} | ||
|
||
@test "Search with permission error (--no-git --no-ripgrep)" { | ||
run_vgrep --no-header --no-git --no-ripgrep foo test/search_files | ||
[ "$status" -eq 2 ] | ||
[[ ${lines[0]} =~ "test/search_files/wonly.txt: Permission denied" ]] | ||
[[ ${lines[1]} =~ "bar baz" ]] | ||
} |
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
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