From 9226dbf732cae982ba836f08f720a2094974f428 Mon Sep 17 00:00:00 2001 From: Marc Khouzam Date: Thu, 21 Oct 2021 11:30:12 -0400 Subject: [PATCH] Add testing for different bash completion types These tests cover the issue: https://github.com/spf13/cobra/issues/1508 and the corresponding fix: https://github.com/spf13/cobra/pull/1509 Signed-off-by: Marc Khouzam --- tests/bash/comp-test-lib.bash | 2 +- tests/bash/comp-tests.bash | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/tests/bash/comp-test-lib.bash b/tests/bash/comp-test-lib.bash index 5b26f8f..f3dcb47 100755 --- a/tests/bash/comp-test-lib.bash +++ b/tests/bash/comp-test-lib.bash @@ -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})) diff --git a/tests/bash/comp-tests.bash b/tests/bash/comp-tests.bash index b9336d1..f89cc57 100755 --- a/tests/bash/comp-tests.bash +++ b/tests/bash/comp-tests.bash @@ -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 @@ -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