@@ -72,87 +72,65 @@ test_completion ()
72
72
73
73
newline=$' \n '
74
74
75
- test_expect_success ' __gitcomp - trailing space - options' '
76
- sed -e "s/Z$//" >expected <<-\EOF &&
77
- --reuse-message=Z
78
- --reedit-message=Z
79
- --reset-author Z
80
- EOF
75
+ # Test __gitcomp.
76
+ # The first argument is the typed text so far (cur); the rest are
77
+ # passed to __gitcomp. Expected output comes is read from the
78
+ # standard input, like test_completion().
79
+ test_gitcomp ()
80
+ {
81
+ sed -e ' s/Z$//' > expected &&
81
82
(
82
83
local -a COMPREPLY &&
83
- cur="--re " &&
84
- __gitcomp "--dry-run --reuse-message= --reedit-message=
85
- --reset-author " &&
84
+ cur=" $1 " &&
85
+ shift &&
86
+ __gitcomp " $@ " &&
86
87
IFS=" $newline " &&
87
- echo "${COMPREPLY[*]}" > out
88
+ echo " ${COMPREPLY[*]} " > out
88
89
) &&
89
90
test_cmp expected out
91
+ }
92
+
93
+ test_expect_success ' __gitcomp - trailing space - options' '
94
+ test_gitcomp "--re" "--dry-run --reuse-message= --reedit-message=
95
+ --reset-author" <<-EOF
96
+ --reuse-message=Z
97
+ --reedit-message=Z
98
+ --reset-author Z
99
+ EOF
90
100
'
91
101
92
102
test_expect_success ' __gitcomp - trailing space - config keys' '
93
- sed -e "s/Z$//" >expected <<-\EOF &&
103
+ test_gitcomp "br" "branch. branch.autosetupmerge
104
+ branch.autosetuprebase browser." <<-\EOF
94
105
branch.Z
95
106
branch.autosetupmerge Z
96
107
branch.autosetuprebase Z
97
108
browser.Z
98
109
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
110
'
109
111
110
112
test_expect_success ' __gitcomp - option parameter' '
111
- sed -e "s/Z$//" >expected <<-\EOF &&
113
+ test_gitcomp "--strategy=re" "octopus ours recursive resolve subtree" \
114
+ "" "re" <<-\EOF
112
115
recursive Z
113
116
resolve Z
114
117
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
118
'
125
119
126
120
test_expect_success ' __gitcomp - prefix' '
127
- sed -e "s/Z$//" >expected <<-\EOF &&
121
+ test_gitcomp "branch.me" "remote merge mergeoptions rebase" \
122
+ "branch.maint." "me" <<-\EOF
128
123
branch.maint.merge Z
129
124
branch.maint.mergeoptions Z
130
125
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
126
'
141
127
142
128
test_expect_success ' __gitcomp - suffix' '
143
- sed -e "s/Z$//" >expected <<-\EOF &&
129
+ test_gitcomp "branch.me" "master maint next pu" "branch." \
130
+ "ma" "." <<-\EOF
144
131
branch.master.Z
145
132
branch.maint.Z
146
133
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
134
'
157
135
158
136
test_expect_success ' basic' '
0 commit comments