git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 01/12] tests: add initial bash completion tests

From
Jeff King <peff@peff.net>
Date
Apr 8, 2012, 05:01 UTC
Message-ID
<20120408050140.GA5862@sigill.intra.peff.net>
In-Reply-To
<1333854479-23260-2-git-send-email-felipe.contreras@gmail.com>
On Sun, Apr 08, 2012 at 06:07:48AM +0300, Felipe Contreras wrote:
Show 8 quoted lines
> +	cat >expected <<-\EOF &&
> +	fetch 
> +	filter-branch 
> +	filter-branch.sh 
> +	format-patch 
> +	fsck 
> +	EOF
> +	test_completion "git f"

This test fails for me. The problem is that I have other git-f* programs in my PATH, and the completion finds and displays them. In other words, the environment outside the test suite can pollute the result.

I'm not sure of the right solution. We can't just sanitize the PATH in test-lib.sh, since those git programs might be in /usr/bin or some other directory containing other commands necessary to run the test suite. We could sanitize it temporarily just for the _git completion invocation, which consists only of builtins (and we know we're running under bash, so we can trust that things like "test" are builtins). But it still feels horribly hacky.

That patch might look like this:
diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh
index 7eb80dd..713f4b1 100755
--- a/t/t9902-completion.sh
+++ b/t/t9902-completion.sh
@@ -58,8 +58,11 @@ test_completion ()
 	_words=( $1 )
 	test $# -gt 1 && echo "$2" > expected
 	(( _cword = ${#_words[@]} - 1 ))
+	saved_path=$PATH
+	PATH=$MINIMAL_PATH
 	_git && print_comp &&
 	test_cmp expected out
+	PATH=$saved_path
 }
 
 test_expect_success 'basic' '
diff --git a/t/test-lib.sh b/t/test-lib.sh
index b7d7100..348b68d 100644
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
@@ -466,12 +466,14 @@ then
 	IFS=$OLDIFS
 	PATH=$GIT_VALGRIND/bin:$PATH
 	GIT_EXEC_PATH=$GIT_VALGRIND/bin
+	MINIMAL_PATH=$GIT_VALGRIND/bin
 	export GIT_VALGRIND
 elif test -n "$GIT_TEST_INSTALLED" ; then
 	GIT_EXEC_PATH=$($GIT_TEST_INSTALLED/git --exec-path)  ||
 	error "Cannot run git from $GIT_TEST_INSTALLED."
 	PATH=$GIT_TEST_INSTALLED:$GIT_BUILD_DIR:$PATH
 	GIT_EXEC_PATH=${GIT_TEST_EXEC_PATH:-$GIT_EXEC_PATH}
+	MINIMAL_PATH=$GIT_TEST_INSTALLED:$GIT_BUILD_DIR
 else # normal case, use ../bin-wrappers only unless $with_dashes:
 	git_bin_dir="$GIT_BUILD_DIR/bin-wrappers"
 	if ! test -x "$git_bin_dir/git" ; then
@@ -482,8 +484,10 @@ else # normal case, use ../bin-wrappers only unless $with_dashes:
 	fi
 	PATH="$git_bin_dir:$PATH"
 	GIT_EXEC_PATH=$GIT_BUILD_DIR
+	MINIMAL_PATH=$git_bin_dir
 	if test -n "$with_dashes" ; then
 		PATH="$GIT_BUILD_DIR:$PATH"
+		MINIMAL_PATH=$MINIMAL_PATH:$GIT_BUILD_DIR
 	fi
 fi
 GIT_TEMPLATE_DIR="$GIT_BUILD_DIR"/templates/blt
Previous: Junio C HamanoNext: Jonathan Nieder
Message 12 of 48 in “Bash completion rework”
  1. 00/12 Bash completion reworkFelipe Contreras, Apr 8, 2012
  2. 01/12 tests: add initial bash completion testsFelipe Contreras, Apr 8, 2012
  3. Junio C HamanoApr 8, 2012
  4. Jeff KingApr 8, 2012
  5. Junio C HamanoApr 8, 2012
  6. Jeff KingApr 8, 2012
  7. Jeff KingApr 8, 2012
  8. Andreas SchwabApr 8, 2012
  9. Jeff KingApr 8, 2012
  10. Felipe ContrerasApr 11, 2012
  11. Junio C HamanoApr 11, 2012
  12. Jeff KingApr 8, 2012
  13. Jonathan NiederApr 8, 2012
  14. Jeff KingApr 8, 2012
  15. Junio C HamanoApr 9, 2012
  16. John KeepingApr 8, 2012
  17. 02/12 completion: simplify __gitcompFelipe Contreras, Apr 8, 2012
  18. SZEDER GáborApr 8, 2012
  19. Felipe ContrerasApr 8, 2012
  20. Jonathan NiederApr 8, 2012
  21. Felipe ContrerasApr 8, 2012
  22. Jonathan NiederApr 8, 2012
  23. Felipe ContrerasApr 8, 2012
  24. Johannes SixtApr 9, 2012
  25. Felipe ContrerasApr 9, 2012
  26. Felipe ContrerasApr 8, 2012
  27. Jonathan NiederApr 8, 2012
  28. Junio C HamanoApr 9, 2012
  29. 03/12 completion: simplify __gitcomp_1Felipe Contreras, Apr 8, 2012
  30. 04/12 completion: trivial simplificationFelipe Contreras, Apr 8, 2012
  31. 05/12 completion: add missing global optionsFelipe Contreras, Apr 8, 2012
  32. John KeepingApr 8, 2012
  33. SZEDER GáborApr 8, 2012
  34. 06/12 tests: add more bash completion testsFelipe Contreras, Apr 8, 2012
  35. 07/12 completion: simplify command stuffFelipe Contreras, Apr 8, 2012
  36. SZEDER GáborApr 11, 2012
  37. Felipe ContrerasApr 11, 2012
  38. SZEDER GáborApr 11, 2012
  39. Felipe ContrerasApr 11, 2012
  40. Felipe ContrerasApr 12, 2012
  41. 08/12 completion: simplify _git_bundleFelipe Contreras, Apr 8, 2012
  42. 09/12 completion: calculate argument position properlyFelipe Contreras, Apr 8, 2012
  43. 10/12 completion: add new git_complete helperFelipe Contreras, Apr 8, 2012
  44. SZEDER GáborApr 11, 2012
  45. Felipe ContrerasApr 11, 2012
  46. 11/12 test: add tests for aliases in bash completionFelipe Contreras, Apr 8, 2012
  47. Felipe ContrerasApr 8, 2012
  48. 12/12 completion: rename _git and _gitkFelipe Contreras, Apr 8, 2012

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.