t/interop: allow tests to run "git env--helper"
PATCH 1/1 t/interop: allow tests to run "git env--helper"
The interop test library sets up wrappers "git.a" and "git.b" to represent the two versions to be tested. It also wraps vanilla "git" to report an error, with the goal of catching tests which accidentally fail to use one of the version-specific wrappers (which could invalidate the tests in a very subtle way).
As a result, t/interop/i5700 has refused to run since 3b072c577b (tests:
replace test_tristate with "git env--helper", 2019-06-21). The problem is that lib-git-daemon.sh uses "git env--helper" to decide whether to run daemon tests, which triggers the vanilla wrapper. That produces an error, and we think that the daemon tests are disabled.
Let's make our wrapper a little smarter, and allow env--helper specifically. It's not an interesting part of Git to test for interop, and it's used extensively in test setup. The matching is rudimentary (e.g., it would not catch "git --some-arg env--helper", but it's enough for our small set of interop tests).
Let's likewise improve the error message from the wrapper (when it does complain) to show the arguments to git. That makes debugging a situation like this much easier, since otherwise you are clueless about who is calling "git" and why.
---
Obviously nobody has run these for a while. I just happened to do so today while investigating something else. Maybe they're not worth keeping around, and we should consider it all a failed experiment. But it's easy enough to fix in the meantime.
Arguably "git env--helper" should be "test-tool", which wouldn't run into this problem, but it's probably not worth refactoring it for the sake of these tests.
By the way, if you do try to run the whole set of tests, note that Git v1.0.0 no longer builds with modern openssl (you can't declare a BIGNUM anymore; you have to get it from BN_new()), and thus i5500 fails. You can work around it with:
# this gets baked into GIT-BUILD-OPTIONS make GIT_INTEROP_MAKE_OPTS=NO_OPENSSL=Nope
# and now interop tests will use it for building other versions cd t/interop make
t/interop/interop-lib.sh | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)
t/interop/interop-lib.sh +11 -2
@@ -67,9 +67,18 @@ generate_wrappers () { mkdir -p .bin && wrap_git .bin/git.a "$DIR_A" && wrap_git .bin/git.b "$DIR_B" && + GENERIC_GIT="$TEST_DIRECTORY/../bin-wrappers/git" && + export GENERIC_GIT && write_script .bin/git <<-\EOF && - echo >&2 fatal: test tried to run generic git - exit 1 + case "$1" in + env--helper) + exec "$GENERIC_GIT" "$@" + ;; + *) + echo >&2 fatal: test tried to run generic git: $* + exit 1 + ;; + esac EOF PATH=$(pwd)/.bin:$PATH }
Signature · 1 line
2.39.0.508.g93b13bde48
PATCH 1/1 env-helper: move this built-in to to "test-tool env-helper"
Since [1] there has been no reason for keeping "git env--helper" a built-in. The reason it was a built-in to begin with was to support the GIT_TEST_GETTEXT_POISON mode removed in that commit. I.e. unlike the rest of "test-tool" it would potentially be called by the installed git via "git-sh-i18n.sh".
As none of that applies since [1] we should stop carrying this technical debt, and move it to t/helper/*. As this mostly move-only change shows this has the nice bonus that we'll stop wasting time translating the internal-only strings it emits.
Even though this was a built-in, it was intentionally never documented, see its introduction in [2]. It never saw use outside of the test suite, except for the "GIT_TEST_GETTEXT_POISON" use-case noted above.
1. d162b25f956 (tests: remove support for GIT_TEST_GETTEXT_POISON, 2021-01-20)
2. b4f207f3394 (env--helper: new undocumented builtin wrapping git_env_*(), 2019-06-21)
---
Quoted 30 lines · Jeff King
The interop test library sets up wrappers "git.a" and "git.b" to represent the two versions to be tested. It also wraps vanilla "git" to report an error, with the goal of catching tests which accidentally fail to use one of the version-specific wrappers (which could invalidate the tests in a very subtle way).
As a result, t/interop/i5700 has refused to run since
3b072c577b(tests:
replacetest_tristatewith "git env--helper", 2019-06-21). The problem is thatlib-git-daemon.shuses "git env--helper" to decide whether to run daemon tests, which triggers the vanilla wrapper. That produces an error, and we think that the daemon tests are disabled.Let's make our wrapper a little smarter, and allow env--helper specifically. It's not an interesting part of Git to test for interop, and it's used extensively in test setup. The matching is rudimentary (e.g., it would not catch "git --some-arg env--helper", but it's enough for our small set of interop tests).
Let's likewise improve the error message from the wrapper (when it does complain) to show the arguments to git. That makes debugging a situation like this much easier, since otherwise you are clueless about who is calling "git" and why.
Signed-off-by Jeff King <[email protected]>---
Obviously nobody has run these for a while. I just happened to do so today while investigating something else. Maybe they're not worth keeping around, and we should consider it all a failed experiment. But it's easy enough to fix in the meantime.
Quoted 3 lines
Arguably "git env--helper" should be "test-tool", which wouldn't run into this problem, but it's probably not worth refactoring it for the sake of these tests.
I think it's worth doing that, i.e. to take this alternate approach. When I removed the GIT_TEST_GETTEXT_POISON facility I didn't want to make that series any larger, and keeping it a built-in seemed harmless, as there wasn't any practical difference between an undocumented built-in and a test-tool.
But as your patch shows there is, I think we should just pay down that technical debt, rather than adding to it by accumulating workarounds (however small those are...).
.gitignore | 1 - Makefile | 2 +- git.c | 1 - .../helper/test-env-helper.c | 24 +++---- t/helper/test-tool.c | 1 + t/helper/test-tool.h | 1 + t/t0017-env-helper.sh | 62 +++++++++---------- t/test-lib-functions.sh | 2 +- t/test-lib.sh | 6 +- 9 files changed, 50 insertions(+), 50 deletions(-) rename builtin/env--helper.c => t/helper/test-env-helper.c (71%)
.gitignore +0 -1
@@ -59,7 +59,6 @@ /git-difftool /git-difftool--helper /git-describe -/git-env--helper /git-fast-export /git-fast-import /git-fetch
Makefile +1 -1
@@ -799,6 +799,7 @@ TEST_BUILTINS_OBJS += test-dump-fsmonitor.o TEST_BUILTINS_OBJS += test-dump-split-index.o TEST_BUILTINS_OBJS += test-dump-untracked-cache.o TEST_BUILTINS_OBJS += test-example-decorate.o +TEST_BUILTINS_OBJS += test-env-helper.o TEST_BUILTINS_OBJS += test-fast-rebase.o TEST_BUILTINS_OBJS += test-fsmonitor-client.o TEST_BUILTINS_OBJS += test-genrandom.o
@@ -1231,7 +1232,6 @@ BUILTIN_OBJS += builtin/diff-index.o BUILTIN_OBJS += builtin/diff-tree.o BUILTIN_OBJS += builtin/diff.o BUILTIN_OBJS += builtin/difftool.o -BUILTIN_OBJS += builtin/env--helper.o BUILTIN_OBJS += builtin/fast-export.o BUILTIN_OBJS += builtin/fast-import.o BUILTIN_OBJS += builtin/fetch-pack.o
git.c +0 -1
@@ -507,7 +507,6 @@ static struct cmd_struct commands[] = { { "diff-index", cmd_diff_index, RUN_SETUP | NO_PARSEOPT }, { "diff-tree", cmd_diff_tree, RUN_SETUP | NO_PARSEOPT }, { "difftool", cmd_difftool, RUN_SETUP_GENTLY }, - { "env--helper", cmd_env__helper }, { "fast-export", cmd_fast_export, RUN_SETUP }, { "fast-import", cmd_fast_import, RUN_SETUP | NO_PARSEOPT }, { "fetch", cmd_fetch, RUN_SETUP },
t/helper/test-env-helper.c renamed from builtin/env--helper.c +12 -12
@@ -1,9 +1,9 @@ -#include "builtin.h" +#include "test-tool.h" #include "config.h" #include "parse-options.h" static char const *const env__helper_usage[] = { -N_ ("git env--helper --type=[bool|ulong] <options> <env-var>" ), +"test-tool env-helper --type=[bool|ulong] <options> <env-var>" ,NULL };
@@ -24,12 +24,12 @@ static int option_parse_type(const struct option *opt, const char *arg,else if (!strcmp (arg,"ulong" )) *cmdmode =ENV_HELPER_TYPE_ULONG ;else -die (_ ("unrecognized --type argument, %s" ), arg); +die ("unrecognized --type argument, %s" , arg);return 0 ; } -int cmd_env__helper (int argc,const char **argv,const char *prefix) +int cmd__env_helper (int argc,const char **argv) {int exit_code =0 ;const char *env_variable =NULL ;
@@ -39,17 +39,17 @@ int cmd_env__helper(int argc, const char **argv, const char *prefix)unsigned long ret_ulong, default_ulong;enum cmdmode cmdmode =0 ;struct option opts[] = { -OPT_CALLBACK_F (0 ,"type" , &cmdmode,N_ ("type" ), -N_ ("value is given this type" ),PARSE_OPT_NONEG , +OPT_CALLBACK_F (0 ,"type" , &cmdmode,"type" , +"value is given this type" ,PARSE_OPT_NONEG , option_parse_type), -OPT_STRING (0 ,"default" , &env_default,N_ ("value" ), -N_ ("default for git_env_*(...) to fall back on" )), +OPT_STRING (0 ,"default" , &env_default,"value" , +"default for git_env_*(...) to fall back on" ),OPT_BOOL (0 ,"exit-code" , &exit_code, -N_ ("be quiet only use git_env_*() value as exit code" )), +"be quiet only use git_env_*() value as exit code" ),OPT_END (), }; - argc =parse_options (argc, argv, prefix, opts, env__helper_usage, + argc =parse_options (argc, argv,NULL , opts, env__helper_usage,PARSE_OPT_KEEP_UNKNOWN_OPT );if (env_default && !*env_default)usage_with_options (env__helper_usage, opts);
@@ -64,7 +64,7 @@ int cmd_env__helper(int argc, const char **argv, const char *prefix)if (env_default) { default_int =git_parse_maybe_bool (env_default);if (default_int ==-1 ) { -error (_ ("option `--default' expects a boolean value with `--type=bool`, not `%s`" ), +error ("option `--default' expects a boolean value with `--type=bool`, not `%s`" , env_default);usage_with_options (env__helper_usage, opts); }
@@ -79,7 +79,7 @@ int cmd_env__helper(int argc, const char **argv, const char *prefix)case ENV_HELPER_TYPE_ULONG :if (env_default) {if (!git_parse_ulong (env_default, &default_ulong)) { -error (_ ("option `--default' expects an unsigned long value with `--type=ulong`, not `%s`" ), +error ("option `--default' expects an unsigned long value with `--type=ulong`, not `%s`" , env_default);usage_with_options (env__helper_usage, opts); }
t/helper/test-tool.c +1 -0
@@ -28,6 +28,7 @@ static struct test_cmd cmds[] = { { "dump-fsmonitor", cmd__dump_fsmonitor }, { "dump-split-index", cmd__dump_split_index }, { "dump-untracked-cache", cmd__dump_untracked_cache }, + { "env-helper", cmd__env_helper }, { "example-decorate", cmd__example_decorate }, { "fast-rebase", cmd__fast_rebase }, { "fsmonitor-client", cmd__fsmonitor_client },
t/helper/test-tool.h +1 -0
@@ -22,6 +22,7 @@ int cmd__dump_fsmonitor(int argc, const char **argv);int cmd__dump_split_index (int argc,const char **argv);int cmd__dump_untracked_cache (int argc,const char **argv);int cmd__dump_reftable (int argc,const char **argv); +int cmd__env_helper (int argc,const char **argv);int cmd__example_decorate (int argc,const char **argv);int cmd__fast_rebase (int argc,const char **argv);int cmd__fsmonitor_client (int argc,const char **argv);
t/t0017-env-helper.sh +31 -31
125 lines not on this page · raw message
t/test-lib-functions.sh +1 -1
@@ -1422,7 +1422,7 @@ test_bool_env () { BUG "test_bool_env requires two parameters (variable name and default value)" fi - git env--helper --type=bool --default="$2" --exit-code "$1" + test-tool env-helper --type=bool --default="$2" --exit-code "$1" ret=$? case $ret in 0|1) # unset or valid bool value
t/test-lib.sh +3 -3
@@ -1542,8 +1542,8 @@ then # Normalize with test_bool_env passes_sanitize_leak= - # We need to see TEST_PASSES_SANITIZE_LEAK in "git - # env--helper" (via test_bool_env) + # We need to see TEST_PASSES_SANITIZE_LEAK in "test-tool + # env-helper" (via test_bool_env) export TEST_PASSES_SANITIZE_LEAK if test_bool_env TEST_PASSES_SANITIZE_LEAK false then
@@ -1682,7 +1682,7 @@ yes () { # The GIT_TEST_FAIL_PREREQS code hooks into test_set_prereq(), and # thus needs to be set up really early, and set an internal variable # for convenience so the hot test_set_prereq() codepath doesn't need -# to call "git env--helper" (via test_bool_env). Only do that work +# to call "test-tool env-helper" (via test_bool_env). Only do that work # if needed by seeing if GIT_TEST_FAIL_PREREQS is set at all. GIT_TEST_FAIL_PREREQS_INTERNAL= if test -n "$GIT_TEST_FAIL_PREREQS"
Signature · 1 line
2.39.0.1215.g1ba3f685d4f
Re: [PATCH] env-helper: move this built-in to to "test-tool env-helper"
Quoted 10 lines · Ævar Arnfjörð Bjarmason
Quoted 3 lines
Arguably "git env--helper" should be "test-tool", which wouldn't run into this problem, but it's probably not worth refactoring it for the sake of these tests.
I think it's worth doing that, i.e. to take this alternate approach. When I removed the
GIT_TEST_GETTEXT_POISONfacility I didn't want to make that series any larger, and keeping it a built-in seemed harmless, as there wasn't any practical difference between an undocumented built-in and a test-tool.
Quoted 3 lines
But as your patch shows there is, I think we should just pay down that technical debt, rather than adding to it by accumulating workarounds (however small those are...).
Yeah, I am totally fine with this direction. My reservations were:
1. It was work somebody had to do. But now you've done it.
2. It's _possible_ that some script somewhere is depending on it. But I think the "--" in the name plus the lack of documentation means that it's unlikely, and that we're morally absolved if somebody's script does break.
Quoted 11 lines
.gitignore | 1 - Makefile | 2 +- git.c | 1 - .../helper/test-env-helper.c | 24 +++---- t/helper/test-tool.c | 1 + t/helper/test-tool.h | 1 + t/t0017-env-helper.sh | 62 +++++++++---------- t/test-lib-functions.sh | 2 +- t/test-lib.sh | 6 +- 9 files changed, 50 insertions(+), 50 deletions(-) rename builtin/env--helper.c => t/helper/test-env-helper.c (71%)
The patch itself looks obviously correct to me.
Review
Quoted 2 lines
(quoted diff) +1
-1- test_must_fail git env--helper --type=bool --default=false --exit-code MISSING >actual.out 2>actual.err && + test_must_fail test-tool env-helper --type=bool --default=false --exit-code MISSING >actual.out 2>actual.err &&
Long lines like these made me wonder if it should simply be "test-tool env", which is shorter. We do not need "helper" to avoid polluting the main git-command namespace, and everything in test-tool is a helper anyway. But it probably doesn't matter much either way. It's not like that line wasn't already overly long. :)
If we do take this, then my t/interop patch can be dropped, though we might want to salvage the error message bit:
-- >8 --
Subject: [PATCH] t/interop: report which vanilla git command failed
The interop test library sets up wrappers "git.a" and "git.b" to represent the two versions to be tested. It also wraps vanilla "git" to report an error, with the goal of catching tests which accidentally fail to use one of the version-specific wrappers (which could invalidate the tests in a very subtle way).
But when it catches an invocation of vanilla git, it doesn't give any details, which makes it very hard to debug exactly which invocation is responsible (especially if it's buried in a function invocation, etc). Let's report the arguments passed to git, which helps narrow it down.
--- t/interop/interop-lib.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
t/interop/interop-lib.sh +1 -1
@@ -68,7 +68,7 @@ generate_wrappers () { wrap_git .bin/git.a "$DIR_A" && wrap_git .bin/git.b "$DIR_B" && write_script .bin/git <<-\EOF && - echo >&2 fatal: test tried to run generic git + echo >&2 fatal: test tried to run generic git: $* exit 1 EOF PATH=$(pwd)/.bin:$PATH
Signature · 1 line
2.39.0.508.g93b13bde48
Re: [PATCH] env-helper: move this built-in to to "test-tool env-helper"
Quoted 8 lines · Jeff King
Yeah, I am totally fine with this direction. My reservations were:
1. It was work somebody had to do. But now you've done it.
2. It's _possible_ that some script somewhere is depending on it. But I think the "--" in the name plus the lack of documentation means that it's unlikely, and that we're morally absolved if somebody's script does break.
That's how we burned some folks who depend on submodule--helper, isn't it? ;-)
Quoted 10 lines
The patch itself looks obviously correct to me.
Review
Quoted 2 lines
(quoted diff) +1
-1- test_must_fail git env--helper --type=bool --default=false --exit-code MISSING >actual.out 2>actual.err && + test_must_fail test-tool env-helper --type=bool --default=false --exit-code MISSING >actual.out 2>actual.err &&Long lines like these made me wonder if it should simply be "test-tool env", which is shorter. We do not need "helper" to avoid polluting the main git-command namespace, and everything in test-tool is a helper anyway. But it probably doesn't matter much either way. It's not like that line wasn't already overly long. :)
I agree that the "-helper" looks a bit irritating, not because the line is long, but because test-tool is by definition about helpers used in tests, so the suffix is redundant.
Let's have a small update before queuing it.
Quoted 2 lines
If we do take this, then my t/interop patch can be dropped, though we might want to salvage the error message bit:
Yup, that does make sense. Will queue what is below the scissors line.
Thanks, both.
Quoted 33 lines
-- >8 --
Subject: [PATCH] t/interop: report which vanilla git command failedThe interop test library sets up wrappers "git.a" and "git.b" to represent the two versions to be tested. It also wraps vanilla "git" to report an error, with the goal of catching tests which accidentally fail to use one of the version-specific wrappers (which could invalidate the tests in a very subtle way).
But when it catches an invocation of vanilla git, it doesn't give any details, which makes it very hard to debug exactly which invocation is responsible (especially if it's buried in a function invocation, etc). Let's report the arguments passed to git, which helps narrow it down.
Signed-off-by Jeff King <[email protected]>--- t/interop/interop-lib.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)t/interop/interop-lib.sh +1
-1@@ -68,7 +68,7 @@ generate_wrappers () { wrap_git .bin/git.a "$DIR_A" && wrap_git .bin/git.b "$DIR_B" && write_script .bin/git <<-\EOF && - echo >&2 fatal: test tried to run generic git + echo >&2 fatal: test tried to run generic git: $* exit 1 EOF PATH=$(pwd)/.bin:$PATH
Re: [PATCH] env-helper: move this built-in to to "test-tool env-helper"
In reply to Ævar Arnfjörð BjarmasonHi Ævar,
Here's a drive-by nitpick:
Makefile TEST_BUILTINS_OBJS += test-dump-fsmonitor.o · line 802
Quoted 9 lines · Ævar Arnfjörð Bjarmason
Makefile +1
-0@@ -799,6 +799,7 @@ TEST_BUILTINS_OBJS += test-dump-fsmonitor.o TEST_BUILTINS_OBJS += test-dump-split-index.o TEST_BUILTINS_OBJS += test-dump-untracked-cache.o TEST_BUILTINS_OBJS += test-example-decorate.o +TEST_BUILTINS_OBJS += test-env-helper.o
The .o files are sorted alphabetically in TEST_BUILTINS_OBJS, so test-env-helper.o should be above test-example-decorate.o
Compare it to changes in t/helper/test-tool.[ch]:
Quoted 24 lines
t/helper/test-tool.c +1
-0@@ -28,6 +28,7 @@ static struct test_cmd cmds[] = { { "dump-fsmonitor", cmd__dump_fsmonitor }, { "dump-split-index", cmd__dump_split_index }, { "dump-untracked-cache", cmd__dump_untracked_cache }, + { "env-helper", cmd__env_helper }, { "example-decorate", cmd__example_decorate }, { "fast-rebase", cmd__fast_rebase }, { "fsmonitor-client", cmd__fsmonitor_client },t/helper/test-tool.h +1
-0@@ -22,6 +22,7 @@ int cmd__dump_fsmonitor(int argc, const char **argv);int cmd__dump_split_index (int argc,const char **argv);int cmd__dump_untracked_cache (int argc,const char **argv);int cmd__dump_reftable (int argc,const char **argv); +int cmd__env_helper (int argc,const char **argv);int cmd__example_decorate (int argc,const char **argv);int cmd__fast_rebase (int argc,const char **argv);int cmd__fsmonitor_client (int argc,const char **argv);
Re: [PATCH] env-helper: move this built-in to to "test-tool env-helper"
Quoted 10 lines · Andrei Rybak
Makefile TEST_BUILTINS_OBJS += test-dump-fsmonitor.o · line 802
Quoted 7 lines
Makefile +1
-0@@ -799,6 +799,7 @@ TEST_BUILTINS_OBJS += test-dump-fsmonitor.o TEST_BUILTINS_OBJS += test-dump-split-index.o TEST_BUILTINS_OBJS += test-dump-untracked-cache.o TEST_BUILTINS_OBJS += test-example-decorate.o +TEST_BUILTINS_OBJS += test-env-helper.oThe .o files are sorted alphabetically in
TEST_BUILTINS_OBJS, so test-env-helper.o should be above test-example-decorate.o
I'll locally tweak to correct this, to prevent this patch from making it worse, but the ordering of other entries are already broken at other places (e.g. around test-rot13-filter.o). Somebody may want to send in a clean-up patch, or alternatively we may not care too deeply and doing nothing about it ;-).
Thanks.