-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Add test script to compare rg --help
output to zsh completion function
#540
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,83 @@ | ||
#!/bin/sh | ||
|
||
# Compares options in `rg --help` output to options in zsh completion function | ||
|
||
set -e | ||
|
||
main() { | ||
local rg="target/${TARGET}/release/rg" | ||
local _rg='complete/_rg' | ||
local ret='0' | ||
local helpTemp="$( mktemp )" | ||
local compTemp="$( mktemp )" | ||
local diff | ||
|
||
[ -e "${rg}" ] || rg="target/${TARGET}/debug/rg" | ||
|
||
if [ ! -e "${rg}" ]; then | ||
printf 'File not found: %s\n' "${rg}" >&2 | ||
ret='1' | ||
elif [ ! -e "${_rg}" ]; then | ||
printf 'File not found: %s\n' "${_rg}" >&2 | ||
ret='1' | ||
else | ||
# 'Parse' options out of the `--help` output. To prevent false positives | ||
# we only look at lines where the first non-white-space character is `-` | ||
"${rg}" --help | | ||
"${rg}" -- '^\s*-' | | ||
"${rg}" -io -- '[\t ,](-[a-z0-9]|--[a-z0-9-]+)\b' | | ||
tr -d '\t ,' | | ||
sort -u > "${helpTemp}" | ||
|
||
# 'Parse' options out of the completion-function file. To prevent false | ||
# negatives, we: | ||
# | ||
# * Exclude lines that look like comments | ||
# * Exclude lines that don't appear to have a bracketed description | ||
# suitable for `_arguments` | ||
# * Exclude those bracketed descriptions so we don't match options | ||
# which might be referenced in them | ||
# * Exclude parenthetical lists of exclusive options so we don't match | ||
# those | ||
# | ||
# This does of course make the following assumptions: | ||
# | ||
# * Each option definition is on its own (single) line | ||
# * Each option definition has a description | ||
# * Option names are static — i.e., they aren't constructed from | ||
# variables or command substitutions. Brace expansion is OK as long as | ||
# each component of the expression is a complete option flag — in | ||
# other words, `{--foo,--bar}` is valid, but `--{foo,bar}` is not | ||
"${rg}" -v -- '^\s*#' "${_rg}" | | ||
"${rg}" --replace '$1' -- '^.*?(?:\(.+?\).*?)?(-.+)\[.+\].*' | | ||
tr -d "\t (){}*=+:'\"" | | ||
tr ',' '\n' | | ||
sort -u > "${compTemp}" | ||
|
||
diff="$( | ||
if diff --help 2>&1 | grep -qF -- '--label'; then | ||
diff -U2 \ | ||
--label '`rg --help`' \ | ||
--label "${_rg}" \ | ||
"${helpTemp}" "${compTemp}" || true | ||
else | ||
diff -U2 \ | ||
-L '`rg --help`' \ | ||
-L "${_rg}" \ | ||
"${helpTemp}" "${compTemp}" || true | ||
fi | ||
)" | ||
|
||
[ -n "${diff}" ] && { | ||
printf '%s\n' 'zsh completion options differ from `--help` options:' >&2 | ||
printf '%s\n' "${diff}" >&2 | ||
ret='1' | ||
} | ||
fi | ||
|
||
rm -f "${helpTemp}" "${compTemp}" | ||
|
||
return "${ret}" | ||
} | ||
|
||
main "${@}" |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
We probably can't do this exact thing. This would at, the very least, depend on ripgrep being built before these tests are run. I think we could probably do it by using a debug build, but right now, a release build is not built in CI. It might be easier to just use
grep
. :P (I think you could setrg=grep
and it will just work.)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.
Oh hmm I see you're using the
--replace
flag. If you just changerg
totarget/${TARGET}/debug/rg
, then I think that should be OK.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.
Yeah, i could easily have replicated most of the find/replace stuff with
grep
and/orsed
, but i figured that since i neededrg
for the--help
output anyway i might as well just use it for everything