Skip to content

Commit 1ff750b

Browse files
avargitster
authored andcommitted
tests: make GIT_TEST_GETTEXT_POISON a boolean
Change the GIT_TEST_GETTEXT_POISON variable from being "non-empty?" to being a more standard boolean variable. Since it needed to be checked in both C code and shellscript (via test -n) it was one of the remaining shellscript-like variables. Now that we have "env--helper" we can change that. There's a couple of tricky edge cases that arise because we're using git_env_bool() early, and the config-reading "env--helper". If GIT_TEST_GETTEXT_POISON is set to an invalid value die_bad_number() will die, but to do so it would usually call gettext(). Let's detect the special case of GIT_TEST_GETTEXT_POISON and always emit that message in the C locale, lest we infinitely loop. As seen in the updated tests in t0017-env-helper.sh there's also a caveat related to "env--helper" needing to read the config for trace2 purposes. Since the C_LOCALE_OUTPUT prerequisite is lazy and relies on "env--helper" we could get invalid results if we failed to read the config (e.g. because we'd loop on includes) when combined with e.g. "test_i18ngrep" wanting to check with "env--helper" if GIT_TEST_GETTEXT_POISON was true or not. I'm crossing my fingers and hoping that a test similar to the one I removed in the earlier "config tests: simplify include cycle test" change in this series won't happen again, and testing for this explicitly in "env--helper"'s own tests. This change breaks existing uses of e.g. GIT_TEST_GETTEXT_POISON=YesPlease, which we've documented in po/README and other places. As noted in [1] we might want to consider also accepting "YesPlease" in "env--helper" as a special-case. But as the lack of uproar over 6cdccfc ("i18n: make GETTEXT_POISON a runtime option", 2018-11-08) demonstrates the audience for this option is a really narrow set of git developers, who shouldn't have much trouble modifying their test scripts, so I think it's better to deal with that minor headache now and make all the relevant GIT_TEST_* variables boolean in the same way than carry the "YesPlease" special-case forward. 1. https://public-inbox.org/git/[email protected]/ Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e3d5e4b commit 1ff750b

File tree

12 files changed

+46
-18
lines changed

12 files changed

+46
-18
lines changed

ci/lib.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ osx-clang|osx-gcc)
184184
export GIT_SKIP_TESTS="t9810 t9816"
185185
;;
186186
GIT_TEST_GETTEXT_POISON)
187-
export GIT_TEST_GETTEXT_POISON=YesPlease
187+
export GIT_TEST_GETTEXT_POISON=true
188188
;;
189189
esac
190190

config.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -956,6 +956,15 @@ static void die_bad_number(const char *name, const char *value)
956956
if (!value)
957957
value = "";
958958

959+
if (!strcmp(name, "GIT_TEST_GETTEXT_POISON"))
960+
/*
961+
* We explicitly *don't* use _() here since it would
962+
* cause an infinite loop with _() needing to call
963+
* use_gettext_poison(). This is why marked up
964+
* translations with N_() above.
965+
*/
966+
die(bad_numeric, value, name, error_type);
967+
959968
if (!(cf && cf->name))
960969
die(_(bad_numeric), value, name, _(error_type));
961970

gettext.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,8 @@ const char *get_preferred_languages(void)
5050
int use_gettext_poison(void)
5151
{
5252
static int poison_requested = -1;
53-
if (poison_requested == -1) {
54-
const char *v = getenv("GIT_TEST_GETTEXT_POISON");
55-
poison_requested = v && strlen(v) ? 1 : 0;
56-
}
53+
if (poison_requested == -1)
54+
poison_requested = git_env_bool("GIT_TEST_GETTEXT_POISON", 0);
5755
return poison_requested;
5856
}
5957

git-sh-i18n.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ export TEXTDOMAINDIR
1717

1818
# First decide what scheme to use...
1919
GIT_INTERNAL_GETTEXT_SH_SCHEME=fallthrough
20-
if test -n "$GIT_TEST_GETTEXT_POISON"
20+
if test -n "$GIT_TEST_GETTEXT_POISON" &&
21+
git env--helper --type=bool --default=0 --exit-code \
22+
GIT_TEST_GETTEXT_POISON
2123
then
2224
GIT_INTERNAL_GETTEXT_SH_SCHEME=poison
2325
elif test -n "@@USE_GETTEXT_SCHEME@@"

po/README

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ To smoke out issues like these, Git tested with a translation mode that
293293
emits gibberish on every call to gettext. To use it run the test suite
294294
with it, e.g.:
295295

296-
cd t && GIT_TEST_GETTEXT_POISON=YesPlease prove -j 9 ./t[0-9]*.sh
296+
cd t && GIT_TEST_GETTEXT_POISON=true prove -j 9 ./t[0-9]*.sh
297297

298298
If tests break with it you should inspect them manually and see if
299299
what you're translating is sane, i.e. that you're not translating

t/README

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -343,8 +343,8 @@ whether this mode is active, and e.g. skip some tests that are hard to
343343
refactor to deal with it. The "SYMLINKS" prerequisite is currently
344344
excluded as so much relies on it, but this might change in the future.
345345

346-
GIT_TEST_GETTEXT_POISON=<non-empty?> turns all strings marked for
347-
translation into gibberish if non-empty (think "test -n"). Used for
346+
GIT_TEST_GETTEXT_POISON=<boolean> turns all strings marked for
347+
translation into gibberish if true. Used for
348348
spotting those tests that need to be marked with a C_LOCALE_OUTPUT
349349
prerequisite when adding more strings for translation. See "Testing
350350
marked strings" in po/README for details.

t/t0017-env-helper.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,20 @@ test_expect_success 'env--helper --type=ulong' '
8080
test_must_be_empty actual.err
8181
'
8282

83+
test_expect_success 'env--helper reads config thanks to trace2' '
84+
mkdir home &&
85+
git config -f home/.gitconfig include.path cycle &&
86+
git config -f home/cycle include.path .gitconfig &&
87+
88+
test_must_fail \
89+
env HOME="$(pwd)/home" GIT_TEST_GETTEXT_POISON=false \
90+
git config -l 2>err &&
91+
grep "exceeded maximum include depth" err &&
92+
93+
test_must_fail \
94+
env HOME="$(pwd)/home" GIT_TEST_GETTEXT_POISON=true \
95+
git -C cycle env--helper --type=bool --default=0 --exit-code GIT_TEST_GETTEXT_POISON 2>err &&
96+
grep "# GETTEXT POISON #" err
97+
'
98+
8399
test_done

t/t0205-gettext-poison.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
test_description='Gettext Shell poison'
77

8-
GIT_TEST_GETTEXT_POISON=YesPlease
8+
GIT_TEST_GETTEXT_POISON=true
99
export GIT_TEST_GETTEXT_POISON
1010
. ./lib-gettext.sh
1111

@@ -31,4 +31,9 @@ test_expect_success 'eval_gettext: our eval_gettext() fallback has poison semant
3131
test_cmp expect actual
3232
'
3333

34+
test_expect_success "gettext: invalid GIT_TEST_GETTEXT_POISON value doesn't infinitely loop" "
35+
test_must_fail env GIT_TEST_GETTEXT_POISON=xyz git version 2>error &&
36+
grep \"fatal: bad numeric config value 'xyz' for 'GIT_TEST_GETTEXT_POISON': invalid unit\" error
37+
"
38+
3439
test_done

t/t1305-config-include.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ test_expect_success 'include cycles are detected' '
314314
git -C cycle config include.path cycle &&
315315
git config -f cycle/cycle include.path config &&
316316
test_must_fail \
317-
env GIT_TEST_GETTEXT_POISON= \
317+
env GIT_TEST_GETTEXT_POISON=false \
318318
git -C cycle config --get-all test.value 2>stderr &&
319319
grep "exceeded maximum include depth" stderr
320320
'

t/t7201-co.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ test_expect_success 'checkout to detach HEAD (with advice declined)' '
249249
test_expect_success 'checkout to detach HEAD' '
250250
git config advice.detachedHead true &&
251251
git checkout -f renamer && git clean -f &&
252-
GIT_TEST_GETTEXT_POISON= git checkout renamer^ 2>messages &&
252+
GIT_TEST_GETTEXT_POISON=false git checkout renamer^ 2>messages &&
253253
grep "HEAD is now at 7329388" messages &&
254254
test_line_count -gt 1 messages &&
255255
H=$(git rev-parse --verify HEAD) &&

0 commit comments

Comments
 (0)