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

Re: [PATCH v2] t0001: fix broken not-quite getcwd(3) test in bed67874e2

From
Junio C Hamano <gitster@pobox.com>
Date
Jul 30, 2021, 17:16 UTC
Message-ID
<xmqqmtq3203g.fsf@gitster.g>
In-Reply-To
<patch-v2-1.1-d7d071441b0-20210730T161540Z-avarab@gmail.com>
Ævar Arnfjörð Bjarmason  <avarab@gmail.com> writes:
Show 8 quoted lines
> The problem with that fix is that while its analysis of the problem is
> correct, it doesn't actually call getcwd(3), instead it invokes "pwd
> -P". There is no guarantee that "pwd -P" is going to call getcwd(3),
> as opposed to e.g. being a shell built-in.
>
> On AIX under both bash and ksh this test breaks because "pwd -P" will
> happily display the current working directory, but getcwd(3) called by
> the "git init" we're testing here will fail to get it.

Well described. And logically it leads to "when we want to know getcwd() is OK to use, trying to run getcwd() to see it works is the right way to do so", which is your test-getcwd.c? Nice.

Will queue.
Show 40 quoted lines
> diff --git a/t/helper/test-tool.c b/t/helper/test-tool.c
> index 490ac026c51..3ce5585e53a 100644
> --- a/t/helper/test-tool.c
> +++ b/t/helper/test-tool.c
> @@ -33,6 +33,7 @@ static struct test_cmd cmds[] = {
>  	{ "fast-rebase", cmd__fast_rebase },
>  	{ "genrandom", cmd__genrandom },
>  	{ "genzeros", cmd__genzeros },
> +	{ "getcwd", cmd__getcwd },
>  	{ "hashmap", cmd__hashmap },
>  	{ "hash-speed", cmd__hash_speed },
>  	{ "index-version", cmd__index_version },
> diff --git a/t/helper/test-tool.h b/t/helper/test-tool.h
> index f8dc266721f..9f0f5228508 100644
> --- a/t/helper/test-tool.h
> +++ b/t/helper/test-tool.h
> @@ -23,6 +23,7 @@ int cmd__example_decorate(int argc, const char **argv);
>  int cmd__fast_rebase(int argc, const char **argv);
>  int cmd__genrandom(int argc, const char **argv);
>  int cmd__genzeros(int argc, const char **argv);
> +int cmd__getcwd(int argc, const char **argv);
>  int cmd__hashmap(int argc, const char **argv);
>  int cmd__hash_speed(int argc, const char **argv);
>  int cmd__index_version(int argc, const char **argv);
> diff --git a/t/t0001-init.sh b/t/t0001-init.sh
> index acd662e403b..df544bb321f 100755
> --- a/t/t0001-init.sh
> +++ b/t/t0001-init.sh
> @@ -356,7 +356,10 @@ test_lazy_prereq GETCWD_IGNORES_PERMS '
>  	chmod 100 $base ||
>  	BUG "cannot prepare $base"
>  
> -	(cd $base/dir && /bin/pwd -P)
> +	(
> +		cd $base/dir &&
> +		test-tool getcwd
> +	)
>  	status=$?
>  
>  	chmod 700 $base &&
Previous: Ævar Arnfjörð BjarmasonNext: Junio C Hamano
Message 14 of 17 in “tests: don't give unportable ">" to "test" built-in, use -gt”
  1. tests: don't give unportable ">" to "test" built-in, use -gtÆvar Arnfjörð Bjarmason, Aug 6, 2017
  2. brian m. carlsonAug 7, 2017
  3. René ScharfeAug 7, 2017
  4. Ævar Arnfjörð BjarmasonAug 7, 2017
  5. t0001: skip test with restrictive permissions if getpwd(3) respects themRené Scharfe, Aug 7, 2017
  6. t0001: fix broken not-quite getcwd(3) test in bed67874e2Ævar Arnfjörð Bjarmason, Jun 1, 2021
  7. René ScharfeJun 1, 2021
  8. Junio C HamanoJun 1, 2021
  9. Ævar Arnfjörð BjarmasonJun 7, 2021
  10. Ævar Arnfjörð BjarmasonJun 7, 2021
  11. René ScharfeJun 7, 2021
  12. Ævar Arnfjörð BjarmasonJun 7, 2021
  13. t0001: fix broken not-quite getcwd(3) test in bed67874e2Ævar Arnfjörð Bjarmason, Jul 30, 2021
  14. Junio C HamanoJul 30, 2021
  15. Junio C HamanoAug 7, 2017
  16. Junio C HamanoAug 7, 2017
  17. Andreas SchwabAug 7, 2017

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.