Merge branch 'fc/completion-test-simplification'
Clean up completion tests. Use of conslidated helper may make instrumenting one particular test during debugging of the test itself, but I think that issue should be addressed in some other way (e.g. making sure individual tests in 9902 can be skipped). * fc/completion-test-simplification: completion: simplify __gitcomp() test helper completion: refactor __gitcomp related tests completion: consolidate test_completion*() tests completion: simplify tests using test_completion_long() completion: standardize final space marker in tests completion: add comment for test_completion()maint
commit
1cab289026
|
@ -54,105 +54,78 @@ run_completion ()
|
||||||
__git_wrap__git_main && print_comp
|
__git_wrap__git_main && print_comp
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Test high-level completion
|
||||||
|
# Arguments are:
|
||||||
|
# 1: typed text so far (cur)
|
||||||
|
# 2: expected completion
|
||||||
test_completion ()
|
test_completion ()
|
||||||
{
|
{
|
||||||
test $# -gt 1 && echo "$2" > expected
|
if test $# -gt 1
|
||||||
run_completion "$@" &&
|
then
|
||||||
|
printf '%s\n' "$2" >expected
|
||||||
|
else
|
||||||
|
sed -e 's/Z$//' >expected
|
||||||
|
fi &&
|
||||||
|
run_completion "$1" &&
|
||||||
test_cmp expected out
|
test_cmp expected out
|
||||||
}
|
}
|
||||||
|
|
||||||
# Like test_completion, but reads expectation from stdin,
|
# Test __gitcomp.
|
||||||
# which is convenient when it is multiline. We also process "_" into
|
# The first argument is the typed text so far (cur); the rest are
|
||||||
# spaces to make test vectors more readable.
|
# passed to __gitcomp. Expected output comes is read from the
|
||||||
test_completion_long ()
|
# standard input, like test_completion().
|
||||||
|
test_gitcomp ()
|
||||||
{
|
{
|
||||||
tr _ " " >expected &&
|
local -a COMPREPLY &&
|
||||||
test_completion "$1"
|
sed -e 's/Z$//' >expected &&
|
||||||
|
cur="$1" &&
|
||||||
|
shift &&
|
||||||
|
__gitcomp "$@" &&
|
||||||
|
print_comp &&
|
||||||
|
test_cmp expected out
|
||||||
}
|
}
|
||||||
|
|
||||||
newline=$'\n'
|
|
||||||
|
|
||||||
test_expect_success '__gitcomp - trailing space - options' '
|
test_expect_success '__gitcomp - trailing space - options' '
|
||||||
sed -e "s/Z$//" >expected <<-\EOF &&
|
test_gitcomp "--re" "--dry-run --reuse-message= --reedit-message=
|
||||||
|
--reset-author" <<-EOF
|
||||||
--reuse-message=Z
|
--reuse-message=Z
|
||||||
--reedit-message=Z
|
--reedit-message=Z
|
||||||
--reset-author Z
|
--reset-author Z
|
||||||
EOF
|
EOF
|
||||||
(
|
|
||||||
local -a COMPREPLY &&
|
|
||||||
cur="--re" &&
|
|
||||||
__gitcomp "--dry-run --reuse-message= --reedit-message=
|
|
||||||
--reset-author" &&
|
|
||||||
IFS="$newline" &&
|
|
||||||
echo "${COMPREPLY[*]}" > out
|
|
||||||
) &&
|
|
||||||
test_cmp expected out
|
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success '__gitcomp - trailing space - config keys' '
|
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.Z
|
||||||
branch.autosetupmerge Z
|
branch.autosetupmerge Z
|
||||||
branch.autosetuprebase Z
|
branch.autosetuprebase Z
|
||||||
browser.Z
|
browser.Z
|
||||||
EOF
|
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' '
|
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
|
recursive Z
|
||||||
resolve Z
|
resolve Z
|
||||||
EOF
|
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' '
|
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.merge Z
|
||||||
branch.maint.mergeoptions Z
|
branch.maint.mergeoptions Z
|
||||||
EOF
|
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' '
|
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.master.Z
|
||||||
branch.maint.Z
|
branch.maint.Z
|
||||||
EOF
|
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' '
|
test_expect_success 'basic' '
|
||||||
|
@ -169,7 +142,7 @@ test_expect_success 'basic' '
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success 'double dash "git" itself' '
|
test_expect_success 'double dash "git" itself' '
|
||||||
sed -e "s/Z$//" >expected <<-\EOF &&
|
test_completion "git --" <<-\EOF
|
||||||
--paginate Z
|
--paginate Z
|
||||||
--no-pager Z
|
--no-pager Z
|
||||||
--git-dir=
|
--git-dir=
|
||||||
|
@ -184,11 +157,10 @@ test_expect_success 'double dash "git" itself' '
|
||||||
--no-replace-objects Z
|
--no-replace-objects Z
|
||||||
--help Z
|
--help Z
|
||||||
EOF
|
EOF
|
||||||
test_completion "git --"
|
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success 'double dash "git checkout"' '
|
test_expect_success 'double dash "git checkout"' '
|
||||||
sed -e "s/Z$//" >expected <<-\EOF &&
|
test_completion "git checkout --" <<-\EOF
|
||||||
--quiet Z
|
--quiet Z
|
||||||
--ours Z
|
--ours Z
|
||||||
--theirs Z
|
--theirs Z
|
||||||
|
@ -199,17 +171,15 @@ test_expect_success 'double dash "git checkout"' '
|
||||||
--orphan Z
|
--orphan Z
|
||||||
--patch Z
|
--patch Z
|
||||||
EOF
|
EOF
|
||||||
test_completion "git checkout --"
|
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success 'general options' '
|
test_expect_success 'general options' '
|
||||||
test_completion "git --ver" "--version " &&
|
test_completion "git --ver" "--version " &&
|
||||||
test_completion "git --hel" "--help " &&
|
test_completion "git --hel" "--help " &&
|
||||||
sed -e "s/Z$//" >expected <<-\EOF &&
|
test_completion "git --exe" <<-\EOF &&
|
||||||
--exec-path Z
|
--exec-path Z
|
||||||
--exec-path=
|
--exec-path=
|
||||||
EOF
|
EOF
|
||||||
test_completion "git --exe" &&
|
|
||||||
test_completion "git --htm" "--html-path " &&
|
test_completion "git --htm" "--html-path " &&
|
||||||
test_completion "git --pag" "--paginate " &&
|
test_completion "git --pag" "--paginate " &&
|
||||||
test_completion "git --no-p" "--no-pager " &&
|
test_completion "git --no-p" "--no-pager " &&
|
||||||
|
@ -247,25 +217,25 @@ test_expect_success 'setup for ref completion' '
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success 'checkout completes ref names' '
|
test_expect_success 'checkout completes ref names' '
|
||||||
test_completion_long "git checkout m" <<-\EOF
|
test_completion "git checkout m" <<-\EOF
|
||||||
master_
|
master Z
|
||||||
mybranch_
|
mybranch Z
|
||||||
mytag_
|
mytag Z
|
||||||
EOF
|
EOF
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success 'show completes all refs' '
|
test_expect_success 'show completes all refs' '
|
||||||
test_completion_long "git show m" <<-\EOF
|
test_completion "git show m" <<-\EOF
|
||||||
master_
|
master Z
|
||||||
mybranch_
|
mybranch Z
|
||||||
mytag_
|
mytag Z
|
||||||
EOF
|
EOF
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success '<ref>: completes paths' '
|
test_expect_success '<ref>: completes paths' '
|
||||||
test_completion_long "git show mytag:f" <<-\EOF
|
test_completion "git show mytag:f" <<-\EOF
|
||||||
file1_
|
file1 Z
|
||||||
file2_
|
file2 Z
|
||||||
EOF
|
EOF
|
||||||
'
|
'
|
||||||
|
|
||||||
|
@ -273,8 +243,8 @@ test_expect_success 'complete tree filename with spaces' '
|
||||||
echo content >"name with spaces" &&
|
echo content >"name with spaces" &&
|
||||||
git add . &&
|
git add . &&
|
||||||
git commit -m spaces &&
|
git commit -m spaces &&
|
||||||
test_completion_long "git show HEAD:nam" <<-\EOF
|
test_completion "git show HEAD:nam" <<-\EOF
|
||||||
name with spaces_
|
name with spaces Z
|
||||||
EOF
|
EOF
|
||||||
'
|
'
|
||||||
|
|
||||||
|
@ -282,9 +252,9 @@ test_expect_failure 'complete tree filename with metacharacters' '
|
||||||
echo content >"name with \${meta}" &&
|
echo content >"name with \${meta}" &&
|
||||||
git add . &&
|
git add . &&
|
||||||
git commit -m meta &&
|
git commit -m meta &&
|
||||||
test_completion_long "git show HEAD:nam" <<-\EOF
|
test_completion "git show HEAD:nam" <<-\EOF
|
||||||
name with ${meta}_
|
name with ${meta} Z
|
||||||
name with spaces_
|
name with spaces Z
|
||||||
EOF
|
EOF
|
||||||
'
|
'
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue