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
Junio C Hamano <gitster@pobox.com>
Date
Dec 3, 2018, 01:00 UTC
Message-ID
<xmqqr2ezh1a5.fsf@gitster-ct.c.googlers.com>
In-Reply-To
<20181201180757.0b2d3c89@pc09.procura.nl>
"H.Merijn Brand" <h.m.brand@xs4all.nl> writes:
> 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

It is totally unclear what "this test" refers to. Let's retitle it to

> Subject: [PATCH] t0061: do not fail test if '.' is part of $PATH
and do something like this:
    t0061 created a script named with an unlikely name in the
    current directory to ensure that it is not found via the
    run_command() API, expecting that $PATH does not contain an
    element that names the current directory (i.e. '.' or '') in a
    sane environment.  This obviously would not work if the $PATH
    does contain such an element.
    Introduce a DOT_IN_PATH lazy prerequisite to catch such a case
    and skip the test when the environment is not so sane.
Show 11 quoted lines
> +test_lazy_prereq DOT_IN_PATH '
> +       case ":$PATH:" in
> +       *:.:*|*::*) true  ;;
> +       *)          false ;;
> +       esac
> +'
> +
> +test_expect_success !DOT_IN_PATH 'run_command is restricted to PATH' '
>         write_script should-not-run <<-\EOF &&
>         echo yikes
>         EOF

I also like Peff's more straight-forward approach that avoids looking into PATH but instead ask the shell what we care about (i.e. would we end up running 'should-not-run' if we asked the system to run it without giving an explicit path to it?). The last paragraph of the above would need to change if we were to go in that direction to something like

    Check if the running shell picks up the script without an
    explicit path to it and skip the test when it does.

perhaps. The code to do so got a bit more compact than what Peff wrote but I think it still retains its main beauty, which is how straight-forward it is.

 t/t0061-run-command.sh | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/t/t0061-run-command.sh b/t/t0061-run-command.sh
index cf932c8514..17b560370e 100755
--- a/t/t0061-run-command.sh
+++ b/t/t0061-run-command.sh
@@ -29,7 +29,15 @@ test_expect_success 'run_command can run a command' '
 	test_must_be_empty err
 '
 
-test_expect_success 'run_command is restricted to PATH' '
+
+test_lazy_prereq RUNS_COMMANDS_FROM_PWD '
+	write_script runs-commands-from-pwd <<-\EOF &&
+	true
+	EOF
+	runs-commands-from-pwd >/dev/null 2>&1
+'
+
+test_expect_success !RUNS_COMMANDS_FROM_PWD 'run_command is restricted to PATH' '
 	write_script should-not-run <<-\EOF &&
 	echo yikes
 	EOF
Previous: Junio C Hamano
Message 4 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.