@@ -54,105 +54,78 @@ run_completion ()
54
54
__git_wrap__git_main && print_comp
55
55
}
56
56
57
+ # Test high-level completion
58
+ # Arguments are:
59
+ # 1: typed text so far (cur)
60
+ # 2: expected completion
57
61
test_completion ()
58
62
{
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 " &&
61
70
test_cmp expected out
62
71
}
63
72
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 ()
68
78
{
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
71
86
}
72
87
73
- newline=$' \n '
74
-
75
88
test_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
77
91
--reuse-message=Z
78
92
--reedit-message=Z
79
93
--reset-author Z
80
94
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
90
95
'
91
96
92
97
test_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
94
100
branch.Z
95
101
branch.autosetupmerge Z
96
102
branch.autosetuprebase Z
97
103
browser.Z
98
104
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
108
105
'
109
106
110
107
test_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
112
110
recursive Z
113
111
resolve Z
114
112
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
124
113
'
125
114
126
115
test_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
128
118
branch.maint.merge Z
129
119
branch.maint.mergeoptions Z
130
120
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
140
121
'
141
122
142
123
test_expect_success ' __gitcomp - suffix' '
143
- sed -e "s/Z$//" >expected <<-\EOF &&
124
+ test_gitcomp "branch.me" "master maint next pu" "branch." \
125
+ "ma" "." <<-\EOF
144
126
branch.master.Z
145
127
branch.maint.Z
146
128
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
156
129
'
157
130
158
131
test_expect_success ' basic' '
@@ -169,7 +142,7 @@ test_expect_success 'basic' '
169
142
'
170
143
171
144
test_expect_success ' double dash "git" itself' '
172
- sed -e "s/Z$//" >expected <<-\EOF &&
145
+ test_completion "git --" <<-\EOF
173
146
--paginate Z
174
147
--no-pager Z
175
148
--git-dir=
@@ -184,11 +157,10 @@ test_expect_success 'double dash "git" itself' '
184
157
--no-replace-objects Z
185
158
--help Z
186
159
EOF
187
- test_completion "git --"
188
160
'
189
161
190
162
test_expect_success ' double dash "git checkout"' '
191
- sed -e "s/Z$//" >expected <<-\EOF &&
163
+ test_completion "git checkout --" <<-\EOF
192
164
--quiet Z
193
165
--ours Z
194
166
--theirs Z
@@ -199,17 +171,15 @@ test_expect_success 'double dash "git checkout"' '
199
171
--orphan Z
200
172
--patch Z
201
173
EOF
202
- test_completion "git checkout --"
203
174
'
204
175
205
176
test_expect_success ' general options' '
206
177
test_completion "git --ver" "--version " &&
207
178
test_completion "git --hel" "--help " &&
208
- sed -e "s/Z$//" >expected <<-\EOF &&
179
+ test_completion "git --exe" <<-\EOF &&
209
180
--exec-path Z
210
181
--exec-path=
211
182
EOF
212
- test_completion "git --exe" &&
213
183
test_completion "git --htm" "--html-path " &&
214
184
test_completion "git --pag" "--paginate " &&
215
185
test_completion "git --no-p" "--no-pager " &&
@@ -247,44 +217,44 @@ test_expect_success 'setup for ref completion' '
247
217
'
248
218
249
219
test_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
254
224
EOF
255
225
'
256
226
257
227
test_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
262
232
EOF
263
233
'
264
234
265
235
test_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
269
239
EOF
270
240
'
271
241
272
242
test_expect_success ' complete tree filename with spaces' '
273
243
echo content >"name with spaces" &&
274
244
git add . &&
275
245
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
278
248
EOF
279
249
'
280
250
281
251
test_expect_failure ' complete tree filename with metacharacters' '
282
252
echo content >"name with \${meta}" &&
283
253
git add . &&
284
254
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
288
258
EOF
289
259
'
290
260
0 commit comments