t5601: remove clear_ssh, refactor setup_ssh_wrapper

Commit 8d3d28f5 added test cases for URLs which should be ssh. Remove the function clear_ssh, use test_when_finished to clean up. Introduce the function setup_ssh_wrapper, which could be factored out together with expect_ssh. Tighten one test and use "foo:bar" instead of "./foo:bar", Helped-by: Jeff King <peff@peff.net> Signed-off-by: Torsten Bögershausen <tboegi@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Torsten Bögershausen committed Nov 28, 2013 at 20:53 UTC 710eb3e22cfe5fb84f41a3ef1d3a91b5cf5d3463
1 file changed +20 -20
t/t5601-clone.sh
+20 -20
@@ -280,25 +280,26 @@ test_expect_success 'clone checking out a tag' '
280 test_cmp fetch.expected fetch.actual
281 '
282
283 -test_expect_success 'setup ssh wrapper' '
284 - write_script "$TRASH_DIRECTORY/ssh-wrapper" <<-\EOF &&
285 - echo >>"$TRASH_DIRECTORY/ssh-output" "ssh: $*" &&
286 - # throw away all but the last argument, which should be the
287 - # command
288 - while test $# -gt 1; do shift; done
289 - eval "$1"
290 - EOF
291 -
292 - GIT_SSH="$TRASH_DIRECTORY/ssh-wrapper" &&
293 - export GIT_SSH &&
294 - export TRASH_DIRECTORY
295 -'
296 -
297 -clear_ssh () {
298 - >"$TRASH_DIRECTORY/ssh-output"
283 +setup_ssh_wrapper () {
284 + test_expect_success 'setup ssh wrapper' '
285 + write_script "$TRASH_DIRECTORY/ssh-wrapper" <<-\EOF &&
286 + echo >>"$TRASH_DIRECTORY/ssh-output" "ssh: $*" &&
287 + # throw away all but the last argument, which should be the
288 + # command
289 + while test $# -gt 1; do shift; done
290 + eval "$1"
291 + EOF
292 + GIT_SSH="$TRASH_DIRECTORY/ssh-wrapper" &&
293 + export GIT_SSH &&
294 + export TRASH_DIRECTORY &&
295 + >"$TRASH_DIRECTORY"/ssh-output
296 + '
297 }
298
299 expect_ssh () {
300 + test_when_finished '
301 + (cd "$TRASH_DIRECTORY" && rm -f ssh-expect && >ssh-output)
302 + ' &&
303 {
304 case "$1" in
305 none)
@@ -310,21 +311,20 @@ expect_ssh () {
311 (cd "$TRASH_DIRECTORY" && test_cmp ssh-expect ssh-output)
312 }
313
314 +setup_ssh_wrapper
315 +
316 test_expect_success 'cloning myhost:src uses ssh' '
314 - clear_ssh &&
317 git clone myhost:src ssh-clone &&
318 expect_ssh myhost src
319 '
320
321 test_expect_success NOT_MINGW,NOT_CYGWIN 'clone local path foo:bar' '
320 - clear_ssh &&
322 cp -R src "foo:bar" &&
322 - git clone "./foo:bar" foobar &&
323 + git clone "foo:bar" foobar &&
324 expect_ssh none
325 '
326
327 test_expect_success 'bracketed hostnames are still ssh' '
327 - clear_ssh &&
328 git clone "[myhost:123]:src" ssh-bracket-clone &&
329 expect_ssh myhost:123 src
330 '