]> git.ipfire.org Git - thirdparty/git.git/commitdiff
t9902: verify that completion does not print anything
authorPatrick Steinhardt <ps@pks.im>
Mon, 15 Jan 2024 10:36:02 +0000 (11:36 +0100)
committerJunio C Hamano <gitster@pobox.com>
Tue, 16 Jan 2024 17:18:20 +0000 (09:18 -0800)
The Bash completion script must not print anything to either stdout or
stderr. Instead, it is only expected to populate certain variables.
Tighten our `test_completion ()` test helper to verify this requirement.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
t/t9902-completion.sh

index aa9a614de33a17f886b7517daeabad5f48bdc42c..95ec762a7445c8c3ca23aca5caa1f3fca78b0b00 100755 (executable)
@@ -5,6 +5,12 @@
 
 test_description='test bash completion'
 
+# The Bash completion scripts must not print anything to either stdout or
+# stderr, which we try to verify. When tracing is enabled without support for
+# BASH_XTRACEFD this assertion will fail, so we have to mark the test as
+# untraceable with such ancient Bash versions.
+test_untraceable=UnfortunatelyYes
+
 . ./lib-bash.sh
 
 complete ()
@@ -87,9 +93,11 @@ test_completion ()
        else
                sed -e 's/Z$//' |sort >expected
        fi &&
-       run_completion "$1" &&
+       run_completion "$1" >"$TRASH_DIRECTORY"/bash-completion-output 2>&1 &&
        sort out >out_sorted &&
-       test_cmp expected out_sorted
+       test_cmp expected out_sorted &&
+       test_must_be_empty "$TRASH_DIRECTORY"/bash-completion-output &&
+       rm "$TRASH_DIRECTORY"/bash-completion-output
 }
 
 # Test __gitcomp.