summaryrefslogtreecommitdiff
path: root/t/t9902-completion.sh
diff options
context:
space:
mode:
authorLibravatar Felipe Contreras <felipe.contreras@gmail.com>2012-11-11 15:35:57 +0100
committerLibravatar Junio C Hamano <gitster@pobox.com>2012-11-16 11:16:12 -0800
commite461523892440f378dd7d872cac9fc6094c6492c (patch)
tree9d783c36e8d6afb5edaa15a84323fdea4398ff49 /t/t9902-completion.sh
parentcompletion: consolidate test_completion*() tests (diff)
downloadtgif-e461523892440f378dd7d872cac9fc6094c6492c.tar.xz
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>
Diffstat (limited to 't/t9902-completion.sh')
-rwxr-xr-xt/t9902-completion.sh78
1 files changed, 28 insertions, 50 deletions
diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh
index 173cd740ee..f754de3122 100755
--- a/t/t9902-completion.sh
+++ b/t/t9902-completion.sh
@@ -72,87 +72,65 @@ test_completion ()
newline=$'\n'
-test_expect_success '__gitcomp - trailing space - options' '
- sed -e "s/Z$//" >expected <<-\EOF &&
- --reuse-message=Z
- --reedit-message=Z
- --reset-author Z
- EOF
+# Test __gitcomp.
+# The first argument is the typed text so far (cur); the rest are
+# passed to __gitcomp. Expected output comes is read from the
+# standard input, like test_completion().
+test_gitcomp ()
+{
+ sed -e 's/Z$//' >expected &&
(
local -a COMPREPLY &&
- cur="--re" &&
- __gitcomp "--dry-run --reuse-message= --reedit-message=
- --reset-author" &&
+ cur="$1" &&
+ shift &&
+ __gitcomp "$@" &&
IFS="$newline" &&
- echo "${COMPREPLY[*]}" > out
+ echo "${COMPREPLY[*]}" >out
) &&
test_cmp expected out
+}
+
+test_expect_success '__gitcomp - trailing space - options' '
+ test_gitcomp "--re" "--dry-run --reuse-message= --reedit-message=
+ --reset-author" <<-EOF
+ --reuse-message=Z
+ --reedit-message=Z
+ --reset-author Z
+ EOF
'
test_expect_success '__gitcomp - trailing space - config keys' '
- sed -e "s/Z$//" >expected <<-\EOF &&
+ test_gitcomp "br" "branch. branch.autosetupmerge
+ branch.autosetuprebase browser." <<-\EOF
branch.Z
branch.autosetupmerge Z
branch.autosetuprebase Z
browser.Z
EOF
- (
- local -a COMPREPLY &&
- cur="br" &&
- __gitcomp "branch. branch.autosetupmerge
- branch.autosetuprebase browser." &&
- IFS="$newline" &&
- echo "${COMPREPLY[*]}" > out
- ) &&
- test_cmp expected out
'
test_expect_success '__gitcomp - option parameter' '
- sed -e "s/Z$//" >expected <<-\EOF &&
+ test_gitcomp "--strategy=re" "octopus ours recursive resolve subtree" \
+ "" "re" <<-\EOF
recursive Z
resolve Z
EOF
- (
- local -a COMPREPLY &&
- cur="--strategy=re" &&
- __gitcomp "octopus ours recursive resolve subtree
- " "" "re" &&
- IFS="$newline" &&
- echo "${COMPREPLY[*]}" > out
- ) &&
- test_cmp expected out
'
test_expect_success '__gitcomp - prefix' '
- sed -e "s/Z$//" >expected <<-\EOF &&
+ test_gitcomp "branch.me" "remote merge mergeoptions rebase" \
+ "branch.maint." "me" <<-\EOF
branch.maint.merge Z
branch.maint.mergeoptions Z
EOF
- (
- local -a COMPREPLY &&
- cur="branch.me" &&
- __gitcomp "remote merge mergeoptions rebase
- " "branch.maint." "me" &&
- IFS="$newline" &&
- echo "${COMPREPLY[*]}" > out
- ) &&
- test_cmp expected out
'
test_expect_success '__gitcomp - suffix' '
- sed -e "s/Z$//" >expected <<-\EOF &&
+ test_gitcomp "branch.me" "master maint next pu" "branch." \
+ "ma" "." <<-\EOF
branch.master.Z
branch.maint.Z
EOF
- (
- local -a COMPREPLY &&
- cur="branch.me" &&
- __gitcomp "master maint next pu
- " "branch." "ma" "." &&
- IFS="$newline" &&
- echo "${COMPREPLY[*]}" > out
- ) &&
- test_cmp expected out
'
test_expect_success 'basic' '