t9902: add a few basic completion tests

We were not testing ref or tree completion at all. Let's give them even basic sanity checks to avoid regressions. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Sep 26, 2012 at 17:47 UTC 49ba92b4eaca44ee4d7444b2256d60c2f32268ee
1 file changed +41
t/t9902-completion.sh
+41
@@ -61,6 +61,15 @@ test_completion ()
61 test_cmp expected out
62 }
63
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 ()
68 +{
69 + tr _ " " >expected &&
70 + test_completion "$1"
71 +}
72 +
73 newline=$'\n'
74
75 test_expect_success '__gitcomp - trailing space - options' '
@@ -228,4 +237,36 @@ test_expect_success 'general options plus command' '
237 test_completion "git --no-replace-objects check" "checkout "
238 '
239
240 +test_expect_success 'setup for ref completion' '
241 + echo content >file1 &&
242 + echo more >file2 &&
243 + git add . &&
244 + git commit -m one &&
245 + git branch mybranch &&
246 + git tag mytag
247 +'
248 +
249 +test_expect_success 'checkout completes ref names' '
250 + test_completion_long "git checkout m" <<-\EOF
251 + master_
252 + mybranch_
253 + mytag_
254 + EOF
255 +'
256 +
257 +test_expect_success 'show completes all refs' '
258 + test_completion_long "git show m" <<-\EOF
259 + master_
260 + mybranch_
261 + mytag_
262 + EOF
263 +'
264 +
265 +test_expect_success '<ref>: completes paths' '
266 + test_completion_long "git show mytag:f" <<-\EOF
267 + file1_
268 + file2_
269 + EOF
270 +'
271 +
272 test_done