completion: refactor __gitcomp related tests

Remove lots of duplicated code; no functional changes intended. Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Felipe Contreras committed Nov 11, 2012 at 15:35 UTC e461523892440f378dd7d872cac9fc6094c6492c
1 file changed +28 -50
t/t9902-completion.sh
+28 -50
@@ -72,87 +72,65 @@ test_completion ()
72
73 newline=$'\n'
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 &&
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 "$@" &&
87 IFS="$newline" &&
87 - echo "${COMPREPLY[*]}" > out
88 + echo "${COMPREPLY[*]}" >out
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
100 '
101
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
105 branch.Z
106 branch.autosetupmerge Z
107 branch.autosetuprebase Z
108 browser.Z
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
110 '
111
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
115 recursive Z
116 resolve Z
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
118 '
119
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
123 branch.maint.merge Z
124 branch.maint.mergeoptions Z
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
126 '
127
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
131 branch.master.Z
132 branch.maint.Z
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
134 '
135
136 test_expect_success 'basic' '