completion tests: re-source git-completion.bash in a subshell

Change tests of git-completion.bash that re-source it to do so inside a subshell. Re-sourcing it will clobber variables it sets, and in the case of the "GIT_COMPLETION_SHOW_ALL=1" test added in ca2d62b7879 (parse-options: don't complete option aliases by default, 2021-07-16) change the behavior of the completion persistently. Aside from the addition of "(" and ")" on new lines this is an indentation-only change, only the "(" and ")" lines are changed under "git diff -w". So let's change that test, and for good measure do the same for the three tests that precede it, which were added in 8b0eaa41f23 (completion: clear cached --options when sourcing the completion script, 2018-03-22). The may not be wrong, but doing this establishes a more reliable pattern for future tests, which might use these as a template to copy. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ævar Arnfjörð Bjarmason committed Feb 2, 2022 at 12:15 UTC 59d9442f28ca8874db93aca961225489328444ac
1 file changed +29 -21
t/t9902-completion.sh
+29 -21
@@ -2396,27 +2396,33 @@ test_expect_success 'options with value' '
2396 '
2397
2398 test_expect_success 'sourcing the completion script clears cached commands' '
2399 - __git_compute_all_commands &&
2400 - verbose test -n "$__git_all_commands" &&
2401 - . "$GIT_BUILD_DIR/contrib/completion/git-completion.bash" &&
2402 - verbose test -z "$__git_all_commands"
2399 + (
2400 + __git_compute_all_commands &&
2401 + verbose test -n "$__git_all_commands" &&
2402 + . "$GIT_BUILD_DIR/contrib/completion/git-completion.bash" &&
2403 + verbose test -z "$__git_all_commands"
2404 + )
2405 '
2406
2407 test_expect_success 'sourcing the completion script clears cached merge strategies' '
2406 - __git_compute_merge_strategies &&
2407 - verbose test -n "$__git_merge_strategies" &&
2408 - . "$GIT_BUILD_DIR/contrib/completion/git-completion.bash" &&
2409 - verbose test -z "$__git_merge_strategies"
2408 + (
2409 + __git_compute_merge_strategies &&
2410 + verbose test -n "$__git_merge_strategies" &&
2411 + . "$GIT_BUILD_DIR/contrib/completion/git-completion.bash" &&
2412 + verbose test -z "$__git_merge_strategies"
2413 + )
2414 '
2415
2416 test_expect_success 'sourcing the completion script clears cached --options' '
2413 - __gitcomp_builtin checkout &&
2414 - verbose test -n "$__gitcomp_builtin_checkout" &&
2415 - __gitcomp_builtin notes_edit &&
2416 - verbose test -n "$__gitcomp_builtin_notes_edit" &&
2417 - . "$GIT_BUILD_DIR/contrib/completion/git-completion.bash" &&
2418 - verbose test -z "$__gitcomp_builtin_checkout" &&
2419 - verbose test -z "$__gitcomp_builtin_notes_edit"
2417 + (
2418 + __gitcomp_builtin checkout &&
2419 + verbose test -n "$__gitcomp_builtin_checkout" &&
2420 + __gitcomp_builtin notes_edit &&
2421 + verbose test -n "$__gitcomp_builtin_notes_edit" &&
2422 + . "$GIT_BUILD_DIR/contrib/completion/git-completion.bash" &&
2423 + verbose test -z "$__gitcomp_builtin_checkout" &&
2424 + verbose test -z "$__gitcomp_builtin_notes_edit"
2425 + )
2426 '
2427
2428 test_expect_success 'option aliases are not shown by default' '
@@ -2424,12 +2430,14 @@ test_expect_success 'option aliases are not shown by default' '
2430 '
2431
2432 test_expect_success 'option aliases are shown with GIT_COMPLETION_SHOW_ALL' '
2427 - . "$GIT_BUILD_DIR/contrib/completion/git-completion.bash" &&
2428 - GIT_COMPLETION_SHOW_ALL=1 && export GIT_COMPLETION_SHOW_ALL &&
2429 - test_completion "git clone --recurs" <<-\EOF
2430 - --recurse-submodules Z
2431 - --recursive Z
2432 - EOF
2433 + (
2434 + . "$GIT_BUILD_DIR/contrib/completion/git-completion.bash" &&
2435 + GIT_COMPLETION_SHOW_ALL=1 && export GIT_COMPLETION_SHOW_ALL &&
2436 + test_completion "git clone --recurs" <<-\EOF
2437 + --recurse-submodules Z
2438 + --recursive Z
2439 + EOF
2440 + )
2441 '
2442
2443 test_expect_success '__git_complete' '