@@ -54,105 +54,78 @@ run_completion ()
5454 __git_wrap__git_main && print_comp
5555}
5656
57+ # Test high-level completion
58+ # Arguments are:
59+ # 1: typed text so far (cur)
60+ # 2: expected completion
5761test_completion ()
5862{
59- test $# -gt 1 && echo " $2 " > expected
60- run_completion " $@ " &&
63+ if test $# -gt 1
64+ then
65+ printf ' %s\n' " $2 " > expected
66+ else
67+ sed -e ' s/Z$//' > expected
68+ fi &&
69+ run_completion " $1 " &&
6170 test_cmp expected out
6271}
6372
64- # Like test_completion, but reads expectation from stdin,
65- # which is convenient when it is multiline. We also process "_" into
66- # spaces to make test vectors more readable.
67- test_completion_long ()
73+ # Test __gitcomp.
74+ # The first argument is the typed text so far (cur); the rest are
75+ # passed to __gitcomp. Expected output comes is read from the
76+ # standard input, like test_completion().
77+ test_gitcomp ()
6878{
69- tr _ " " > expected &&
70- test_completion " $1 "
79+ local -a COMPREPLY &&
80+ sed -e ' s/Z$//' > expected &&
81+ cur=" $1 " &&
82+ shift &&
83+ __gitcomp " $@ " &&
84+ print_comp &&
85+ test_cmp expected out
7186}
7287
73- newline=$' \n '
74-
7588test_expect_success ' __gitcomp - trailing space - options' '
76- sed -e "s/Z$//" >expected <<-\EOF &&
89+ test_gitcomp "--re" "--dry-run --reuse-message= --reedit-message=
90+ --reset-author" <<-EOF
7791 --reuse-message=Z
7892 --reedit-message=Z
7993 --reset-author Z
8094 EOF
81- (
82- local -a COMPREPLY &&
83- cur="--re" &&
84- __gitcomp "--dry-run --reuse-message= --reedit-message=
85- --reset-author" &&
86- IFS="$newline" &&
87- echo "${COMPREPLY[*]}" > out
88- ) &&
89- test_cmp expected out
9095'
9196
9297test_expect_success ' __gitcomp - trailing space - config keys' '
93- sed -e "s/Z$//" >expected <<-\EOF &&
98+ test_gitcomp "br" "branch. branch.autosetupmerge
99+ branch.autosetuprebase browser." <<-\EOF
94100 branch.Z
95101 branch.autosetupmerge Z
96102 branch.autosetuprebase Z
97103 browser.Z
98104 EOF
99- (
100- local -a COMPREPLY &&
101- cur="br" &&
102- __gitcomp "branch. branch.autosetupmerge
103- branch.autosetuprebase browser." &&
104- IFS="$newline" &&
105- echo "${COMPREPLY[*]}" > out
106- ) &&
107- test_cmp expected out
108105'
109106
110107test_expect_success ' __gitcomp - option parameter' '
111- sed -e "s/Z$//" >expected <<-\EOF &&
108+ test_gitcomp "--strategy=re" "octopus ours recursive resolve subtree" \
109+ "" "re" <<-\EOF
112110 recursive Z
113111 resolve Z
114112 EOF
115- (
116- local -a COMPREPLY &&
117- cur="--strategy=re" &&
118- __gitcomp "octopus ours recursive resolve subtree
119- " "" "re" &&
120- IFS="$newline" &&
121- echo "${COMPREPLY[*]}" > out
122- ) &&
123- test_cmp expected out
124113'
125114
126115test_expect_success ' __gitcomp - prefix' '
127- sed -e "s/Z$//" >expected <<-\EOF &&
116+ test_gitcomp "branch.me" "remote merge mergeoptions rebase" \
117+ "branch.maint." "me" <<-\EOF
128118 branch.maint.merge Z
129119 branch.maint.mergeoptions Z
130120 EOF
131- (
132- local -a COMPREPLY &&
133- cur="branch.me" &&
134- __gitcomp "remote merge mergeoptions rebase
135- " "branch.maint." "me" &&
136- IFS="$newline" &&
137- echo "${COMPREPLY[*]}" > out
138- ) &&
139- test_cmp expected out
140121'
141122
142123test_expect_success ' __gitcomp - suffix' '
143- sed -e "s/Z$//" >expected <<-\EOF &&
124+ test_gitcomp "branch.me" "master maint next pu" "branch." \
125+ "ma" "." <<-\EOF
144126 branch.master.Z
145127 branch.maint.Z
146128 EOF
147- (
148- local -a COMPREPLY &&
149- cur="branch.me" &&
150- __gitcomp "master maint next pu
151- " "branch." "ma" "." &&
152- IFS="$newline" &&
153- echo "${COMPREPLY[*]}" > out
154- ) &&
155- test_cmp expected out
156129'
157130
158131test_expect_success ' basic' '
@@ -169,7 +142,7 @@ test_expect_success 'basic' '
169142'
170143
171144test_expect_success ' double dash "git" itself' '
172- sed -e "s/Z$//" >expected <<-\EOF &&
145+ test_completion "git --" <<-\EOF
173146 --paginate Z
174147 --no-pager Z
175148 --git-dir=
@@ -184,11 +157,10 @@ test_expect_success 'double dash "git" itself' '
184157 --no-replace-objects Z
185158 --help Z
186159 EOF
187- test_completion "git --"
188160'
189161
190162test_expect_success ' double dash "git checkout"' '
191- sed -e "s/Z$//" >expected <<-\EOF &&
163+ test_completion "git checkout --" <<-\EOF
192164 --quiet Z
193165 --ours Z
194166 --theirs Z
@@ -199,17 +171,15 @@ test_expect_success 'double dash "git checkout"' '
199171 --orphan Z
200172 --patch Z
201173 EOF
202- test_completion "git checkout --"
203174'
204175
205176test_expect_success ' general options' '
206177 test_completion "git --ver" "--version " &&
207178 test_completion "git --hel" "--help " &&
208- sed -e "s/Z$//" >expected <<-\EOF &&
179+ test_completion "git --exe" <<-\EOF &&
209180 --exec-path Z
210181 --exec-path=
211182 EOF
212- test_completion "git --exe" &&
213183 test_completion "git --htm" "--html-path " &&
214184 test_completion "git --pag" "--paginate " &&
215185 test_completion "git --no-p" "--no-pager " &&
@@ -247,44 +217,44 @@ test_expect_success 'setup for ref completion' '
247217'
248218
249219test_expect_success ' checkout completes ref names' '
250- test_completion_long "git checkout m" <<-\EOF
251- master_
252- mybranch_
253- mytag_
220+ test_completion "git checkout m" <<-\EOF
221+ master Z
222+ mybranch Z
223+ mytag Z
254224 EOF
255225'
256226
257227test_expect_success ' show completes all refs' '
258- test_completion_long "git show m" <<-\EOF
259- master_
260- mybranch_
261- mytag_
228+ test_completion "git show m" <<-\EOF
229+ master Z
230+ mybranch Z
231+ mytag Z
262232 EOF
263233'
264234
265235test_expect_success ' <ref>: completes paths' '
266- test_completion_long "git show mytag:f" <<-\EOF
267- file1_
268- file2_
236+ test_completion "git show mytag:f" <<-\EOF
237+ file1 Z
238+ file2 Z
269239 EOF
270240'
271241
272242test_expect_success ' complete tree filename with spaces' '
273243 echo content >"name with spaces" &&
274244 git add . &&
275245 git commit -m spaces &&
276- test_completion_long "git show HEAD:nam" <<-\EOF
277- name with spaces_
246+ test_completion "git show HEAD:nam" <<-\EOF
247+ name with spaces Z
278248 EOF
279249'
280250
281251test_expect_failure ' complete tree filename with metacharacters' '
282252 echo content >"name with \${meta}" &&
283253 git add . &&
284254 git commit -m meta &&
285- test_completion_long "git show HEAD:nam" <<-\EOF
286- name with ${meta}_
287- name with spaces_
255+ test_completion "git show HEAD:nam" <<-\EOF
256+ name with ${meta} Z
257+ name with spaces Z
288258 EOF
289259'
290260
0 commit comments