-
Notifications
You must be signed in to change notification settings - Fork 77
fix(completion): support Homebrew-installed completion assets #155
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,108 @@ | ||
| #!/usr/bin/env bats | ||
| # Tests for completion path resolution in lib/commands/completion.sh | ||
|
|
||
| load test_helper | ||
|
|
||
| log_error() { printf '%s\n' "$*" >&2; } | ||
| log_info() { printf '%s\n' "$*" >&2; } | ||
|
|
||
| setup() { | ||
| TEST_GTR_DIR="$(mktemp -d)" | ||
| export GTR_DIR="$TEST_GTR_DIR" | ||
| # shellcheck disable=SC1091 | ||
| . "$PROJECT_ROOT/lib/commands/completion.sh" | ||
| } | ||
|
|
||
| teardown() { | ||
| rm -rf "$TEST_GTR_DIR" | ||
| } | ||
|
|
||
| write_test_file() { | ||
| local path="$1" content="$2" | ||
| mkdir -p "$(dirname "$path")" | ||
| printf '%s\n' "$content" > "$path" | ||
| } | ||
|
|
||
| setup_source_layout() { | ||
| write_test_file "$TEST_GTR_DIR/completions/gtr.bash" "# source bash completion" | ||
| write_test_file "$TEST_GTR_DIR/completions/_git-gtr" "#compdef git-gtr" | ||
| write_test_file "$TEST_GTR_DIR/completions/git-gtr.fish" "# fish source completion" | ||
| } | ||
|
|
||
| setup_homebrew_layout() { | ||
| write_test_file "$TEST_GTR_DIR/etc/bash_completion.d/git-gtr" "# brew bash completion" | ||
| write_test_file "$TEST_GTR_DIR/share/zsh/site-functions/_git-gtr" "#compdef git-gtr" | ||
| write_test_file "$TEST_GTR_DIR/share/fish/vendor_completions.d/git-gtr.fish" "# fish brew completion" | ||
| } | ||
|
|
||
| @test "cmd_completion bash uses source checkout asset when present" { | ||
| setup_source_layout | ||
|
|
||
| run cmd_completion bash | ||
|
|
||
| [ "$status" -eq 0 ] | ||
| [ "$output" = "# source bash completion" ] | ||
| } | ||
|
|
||
| @test "cmd_completion zsh uses source checkout completions directory when present" { | ||
| setup_source_layout | ||
|
|
||
| run cmd_completion zsh | ||
|
|
||
| [ "$status" -eq 0 ] | ||
| [[ "$output" == *"fpath=('$TEST_GTR_DIR/completions' \$fpath)"* ]] | ||
| } | ||
|
|
||
| @test "cmd_completion fish uses source checkout asset when present" { | ||
| setup_source_layout | ||
|
|
||
| run cmd_completion fish | ||
|
|
||
| [ "$status" -eq 0 ] | ||
| [ "$output" = "# fish source completion" ] | ||
| } | ||
|
|
||
| @test "cmd_completion bash falls back to Homebrew asset layout" { | ||
| setup_homebrew_layout | ||
|
|
||
| run cmd_completion bash | ||
|
|
||
| [ "$status" -eq 0 ] | ||
| [ "$output" = "# brew bash completion" ] | ||
| } | ||
|
|
||
| @test "cmd_completion zsh falls back to Homebrew site-functions directory" { | ||
| setup_homebrew_layout | ||
|
|
||
| run cmd_completion zsh | ||
|
|
||
| [ "$status" -eq 0 ] | ||
| [[ "$output" == *"fpath=('$TEST_GTR_DIR/share/zsh/site-functions' \$fpath)"* ]] | ||
| } | ||
|
|
||
| @test "cmd_completion fish falls back to Homebrew vendor completions" { | ||
| setup_homebrew_layout | ||
|
|
||
| run cmd_completion fish | ||
|
|
||
| [ "$status" -eq 0 ] | ||
| [ "$output" = "# fish brew completion" ] | ||
| } | ||
|
|
||
| @test "cmd_completion prefers source checkout assets over Homebrew assets" { | ||
| setup_source_layout | ||
| setup_homebrew_layout | ||
|
|
||
| run cmd_completion bash | ||
|
|
||
| [ "$status" -eq 0 ] | ||
| [ "$output" = "# source bash completion" ] | ||
| } | ||
|
|
||
| @test "cmd_completion returns a clear error when completion assets are missing" { | ||
| run cmd_completion bash | ||
|
|
||
| [ "$status" -eq 1 ] | ||
| [[ "$output" == *"Could not find bash completion asset under:"* ]] | ||
| [[ "$output" == *"Expected either a source checkout (completions/) or a Homebrew install layout."* ]] | ||
| } |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.