@@ -23,9 +23,11 @@ check_completion() {
2323 local input=" $1 "
2424 local expected_completions=(" $2 " )
2525 local expected_options=(" $3 " )
26- local expected_exit_code=${4:- 0} ;
26+ local expected_actions=(" $4 " )
27+ local expected_exit_code=${5:- 0} ;
2728 local -a output
2829 local -a options
30+ local -a actions
2931
3032 echo " Checking completion $input " >&2
3133
@@ -54,9 +56,11 @@ check_completion() {
5456 fi
5557
5658 read -r -a options <<< " ${output[0]}"
57- local completions=(" ${output[@]: 1} " )
59+ read -r -a actions <<< " ${output[1]}"
60+ local completions=(" ${output[@]: 2} " )
5861
5962 echo -n " options: " >&2 ; printf " '%s'," " ${options[@]} " >&2 ; echo >&2
63+ echo -n " actions: " >&2 ; printf " '%s'," " ${actions[@]} " >&2 ; echo >&2
6064 echo -n " completions: " >&2 ; printf " '%s'," " ${completions[@]} " >&2 ; echo >&2
6165
6266 if [[ " ${completions[*]} " != " ${expected_completions[*]} " ]]; then
@@ -68,10 +72,15 @@ check_completion() {
6872 echo -n " ! invalid options, expecting: " ; printf " '%s'," " ${expected_options[@]} " ; echo
6973 exit 1
7074 fi
75+
76+ if [[ " ${actions[*]} " != " ${expected_actions[*]} " ]]; then
77+ echo -n " ! invalid actions, expecting: " ; printf " '%s'," " ${expected_actions[@]} " ; echo
78+ exit 1
79+ fi
7180}
7281
7382expect_failure () {
74- check_completion " $1 " ' ' ' ' 1
83+ check_completion " $1 " ' ' ' ' ' ' 1
7584}
7685
7786function test_complete_function() {
@@ -107,15 +116,30 @@ check_completion foo-with-multiple-words "foo --bar"
107116complete -o nospace -W " foo" foo-with-word-and-option
108117check_completion foo-with-word-and-option " foo" nospace
109118
119+ complete -W " foo" -f foo-with-word-and-action
120+ check_completion foo-with-word-and-action " foo" ' ' file
121+
122+ complete -o nospace -W " foo" -f foo-with-word-option-and-action
123+ check_completion foo-with-word-option-and-action " foo" nospace file
124+
110125complete -o nospace -W " foo" -o nosort foo-with-multiple-options
111126check_completion foo-with-multiple-options " foo" " nosort nospace"
112127
113128complete -o nospace -W " foo bar" -o nosort foo-with-multiple-words-and-options
114129check_completion foo-with-multiple-words-and-options " foo bar" " nosort nospace"
115130
131+ complete -o nospace -W " foo bar" -o nosort -A binding -A job foo-with-multiple-words-options-and-actions
132+ check_completion foo-with-multiple-words-options-and-actions " foo bar" " nosort nospace" " job binding"
133+
116134complete -o nospace -o nosort -o default foo-with-only-options
117135check_completion foo-with-only-options ' ' " default nosort nospace"
118136
137+ complete -a -A ' command' -e -A ' file' foo-with-only-actions
138+ check_completion foo-with-only-actions ' ' ' ' ' alias command export file'
139+
140+ complete -acefg foo-with-only-actions-joined
141+ check_completion foo-with-only-actions-joined ' ' ' ' ' alias command export file group'
142+
119143complete -F foo_complete_function_not_existant foo-with-function-invalid
120144expect_failure foo-with-function-invalid
121145
0 commit comments