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

Re: [PATCH v2] t9146: replace test -d/-e/-f with appropriate test_path_is_* function

From
Junio C Hamano <gitster@pobox.com>
Date
Feb 12, 2024, 20:31 UTC
Message-ID
<xmqq7cj95ssb.fsf@gitster.g>
In-Reply-To
<pull.1661.v2.git.1707765433663.gitgitgadget@gmail.com>
"Chandra Pratap via GitGitGadget" <gitgitgadget@gmail.com> writes:
> From: Chandra Pratap <chandrapratap3519@gmail.com>
>
> The helper functions test_path_is_* provide better debugging
> information than test -d/-e/-f.
Correct.
> Replace "if ! test -d then <error message>" with "test_path_exists"
> and "test -d" with "test_path_is_dir" at places where we check for
> existent directories.

The former could result in misconversion, if the intention of the test was "we cannot have directory here; a regular file is OK", so we have to be a bit more careful than mechanical conversion.

> Replace "test -f" with "test_path_is_file" at places where we check
> for existent files.
OK.
> Replace "test ! -e" with "test_path_is_missing" where we check for
> non-existent directories.
OK.
Show 8 quoted lines
>  		for i in a b c d d/e d/e/f "weird file name"
>  		do
> -			if ! test -d "$i"
> -			then
> -				echo >&2 "$i does not exist" &&
> -				exit 1
> -			fi
> +			test_path_exists "$i" || exit 1

We were saying that we are OK if "$i" existed as a file (not a directory), but now we complain regardless of what "$i" is. Is that closer to what the test originally wanted to do? Just checking.

Show 13 quoted lines
>  		done
>  	)
>  '
> @@ -37,11 +33,7 @@ test_expect_success 'option automkdirs set to false' '
>  		git svn fetch &&
>  		for i in a b c d d/e d/e/f "weird file name"
>  		do
> -			if test -d "$i"
> -			then
> -				echo >&2 "$i exists" &&
> -				exit 1
> -			fi
> +			test_path_is_missing "$i" || exit 1

Ditto; are we sure the intention of the original is that nothing should be at "$i" (instead of "as long as it is not a directory, we are OK")? Just checking.

The same comment applies to all conversions to test_path_exists and test_path_is_missing where the original was not "test -e" or "! test -e". The other ones, like the change from "test -f" to "test_path_is_file", looked all correct.

Thanks.
Previous: Chandra Pratap via GitGitGadgetNext: Chandra Pratap via GitGitGadget
Message 4 of 5 in “t9146: replace test -d/-f with appropriate test_path_is_* function”
  1. t9146: replace test -d/-f with appropriate test_path_is_* functionChandra Pratap via GitGitGadget, Feb 11, 2024
  2. Eric SunshineFeb 11, 2024
  3. t9146: replace test -d/-e/-f with appropriate test_path_is_* functionChandra Pratap via GitGitGadget, Feb 12, 2024
  4. Junio C HamanoFeb 12, 2024
  5. t9146: replace test -d/-e/-f with appropriate test_path_is_* functionChandra Pratap via GitGitGadget, Feb 14, 2024

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.