Skip to content

Commit e461523

Browse files
felipecgitster
authored andcommitted
completion: refactor __gitcomp related tests
Remove lots of duplicated code; no functional changes intended. Signed-off-by: Felipe Contreras <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2fbaf81 commit e461523

File tree

1 file changed

+28
-50
lines changed

1 file changed

+28
-50
lines changed

t/t9902-completion.sh

Lines changed: 28 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -72,87 +72,65 @@ test_completion ()
7272

7373
newline=$'\n'
7474

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 &&
8182
(
8283
local -a COMPREPLY &&
83-
cur="--re" &&
84-
__gitcomp "--dry-run --reuse-message= --reedit-message=
85-
--reset-author" &&
84+
cur="$1" &&
85+
shift &&
86+
__gitcomp "$@" &&
8687
IFS="$newline" &&
87-
echo "${COMPREPLY[*]}" > out
88+
echo "${COMPREPLY[*]}" >out
8889
) &&
8990
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
90100
'
91101

92102
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
94105
branch.Z
95106
branch.autosetupmerge Z
96107
branch.autosetuprebase Z
97108
browser.Z
98109
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
108110
'
109111

110112
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
112115
recursive Z
113116
resolve Z
114117
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
124118
'
125119

126120
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
128123
branch.maint.merge Z
129124
branch.maint.mergeoptions Z
130125
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
140126
'
141127

142128
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
144131
branch.master.Z
145132
branch.maint.Z
146133
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
156134
'
157135

158136
test_expect_success 'basic' '

0 commit comments

Comments
 (0)