Skip to content

Commit

Permalink
Add testing for different bash completion types
Browse files Browse the repository at this point in the history
These tests cover the issue: spf13/cobra#1508
and the corresponding fix: spf13/cobra#1509

Signed-off-by: Marc Khouzam <marc.khouzam@gmail.com>
  • Loading branch information
marckhouzam committed Oct 21, 2021
1 parent 724dce2 commit 9226dbf
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion tests/bash/comp-test-lib.bash
Expand Up @@ -158,7 +158,7 @@ _completionTests_complete() {
# used for both bash and zsh completion
COMP_LINE=${cmdLine}
COMP_POINT=${#COMP_LINE}
COMP_TYPE=9 # 9 is TAB
COMP_TYPE=${COMP_TYPE-9} # 9 is TAB, but we allow to override for some tests
COMP_KEY=9 # 9 is TAB
COMP_WORDS=($(echo ${cmdLine}))

Expand Down
26 changes: 26 additions & 0 deletions tests/bash/comp-tests.bash
Expand Up @@ -183,6 +183,18 @@ verifyDebug
# https://github.com/spf13/cobra/issues/1334
verifyRedirect

# Test other bash completion types with descriptions disabled.
# There should be no change in behaviour when there are no descriptions.
# The types are: menu-complete/menu-complete-backward (COMP_TYPE == 37)
# and insert-completions (COMP_TYPE == 42)
COMP_TYPE=37
_completionTests_verifyCompletion "testprog prefix nospace b" "bear bearpaw" nospace
_completionTests_verifyCompletion "testprog prefix nofile b" "bear bearpaw" nofile
COMP_TYPE=42
_completionTests_verifyCompletion "testprog prefix nospace b" "bear bearpaw" nospace
_completionTests_verifyCompletion "testprog prefix nofile b" "bear bearpaw" nofile
unset COMP_TYPE

# Test descriptions of bash v2
if [ "$BASHCOMP_VERSION" = bash2 ]; then

Expand Down Expand Up @@ -239,6 +251,20 @@ forthComp" nofile
forthComp" nofile
_completionTests_verifyCompletion "testprog --customComp fi" "firstComp" nofile

# Test descriptions are properly removed when using other bash completion types
# The types are: menu-complete/menu-complete-backward (COMP_TYPE == 37)
# and insert-completions (COMP_TYPE == 42)
COMP_TYPE=37
_completionTests_verifyCompletion "testprog prefix nospace b" "bear
bearpaw" nospace
_completionTests_verifyCompletion "testprog prefix nofile b" "bear
bearpaw" nofile
COMP_TYPE=42
_completionTests_verifyCompletion "testprog prefix nospace b" "bear
bearpaw" nospace
_completionTests_verifyCompletion "testprog prefix nofile b" "bear
bearpaw" nofile
unset COMP_TYPE
fi

# This must be the last call. It allows to exit with an exit code
Expand Down

0 comments on commit 9226dbf

Please sign in to comment.