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

Re: [PATCH] Do not fail test if '.' is part of $PATH

From
Jeff King <peff@peff.net>
Date
Dec 1, 2018, 19:38 UTC
Message-ID
<20181201193822.GA28918@sigill.intra.peff.net>
In-Reply-To
<20181201180757.0b2d3c89@pc09.procura.nl>
On Sat, Dec 01, 2018 at 06:07:57PM +0100, H.Merijn Brand wrote:
> When $PATH contains the current directory as .:PATH, PATH:., PATH:.:PATH,
> or (maybe worse) as :PATH, PATH:, or PATH::PATH - as an empty entry is
> identical to having dot in $PATH - this test used to fail

Good catch. The test cares about Git not accidentally adding "." to the PATH, but we can't check that if it is already there.

Show 9 quoted lines
> This patch was tested with PATH=$PATH, PATH=.:$PATH, PATH=$PATH:.,
> PATH=$PATH:.:/bin, PATH=:$PATH, PATH=$PATH:, and PATH=$PATH::/bin
> [...]
> +test_lazy_prereq DOT_IN_PATH '
> +       case ":$PATH:" in
> +       *:.:*|*::*) true  ;;
> +       *)          false ;;
> +       esac
> +'

Since the test is ultimately checking "can we run should-not-run from the current directory", might it be simpler to actually try that as the precondition? I.e., something like:

  test_expect_success 'create program in current directory' '
	write_script should-not-run <<-\EOF &&
	echo yikes
	EOF
  '
  test_lazy_prereq DOT_IN_PATH '
	should-not-run
  '
  test_expect_success !DOT_IN_PATH 'run_command is restricted to PATH' '
	test_must_fail test-tool run-command run-command should-not-run
  '
?

That's more lines, but we don't have to peek into the details of how $PATH works.

-Peff
Previous: H.Merijn BrandNext: Junio C Hamano
Message 2 of 4 in “Do not fail test if '.' is part of $PATH”
  1. Do not fail test if '.' is part of $PATHH.Merijn Brand, Dec 1, 2018
  2. Jeff KingDec 1, 2018
  3. Junio C HamanoDec 3, 2018
  4. Junio C HamanoDec 3, 2018

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.