tests: remove support for GIT_TEST_GETTEXT_POISON

This removes the ability to inject "poison" gettext() messages via the GIT_TEST_GETTEXT_POISON special test setup. I initially added this as a compile-time option in bb946bba761 (i18n: add GETTEXT_POISON to simulate unfriendly translator, 2011-02-22), and most recently modified to be toggleable at runtime in 6cdccfce1e0 (i18n: make GETTEXT_POISON a runtime option, 2018-11-08).. The reason for its removal is that the trade-off of maintaining it v.s. what it's getting us has long since flipped. When gettext was integrated in 5e9637c6297 (i18n: add infrastructure for translating Git with gettext, 2011-11-18) there was understandable concern on the Git ML that in marking messages for translation en-masse we'd inadvertently mark plumbing messages. The GETTEXT_POISON facility was a way to smoke those out via our test suite. Nowadays however we're done (or almost entirely done) with any marking of messages for translation. New messages are usually marked by their authors, who'll know whether it makes sense to translate them or not. If not any errors in marking the messages are much more likely to be spotted in review than in the the initial deluge of i18n patches in the 2011-2012 era. So let's just remove this. This leaves the test suite in a state where we still have a lot of test_i18n, C_LOCALE_OUTPUT etc. uses. Subsequent commits will remove those too. The change to t/lib-rebase.sh is a selective revert of the relevant part of f2d17068fd (i18n: rebase-interactive: mark comments of squash for translation, 2016-06-17), and the comment in t/t3406-rebase-message.sh is from c7108bf9ed (i18n: rebase: mark messages for translation, 2012-07-25). Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ævar Arnfjörð Bjarmason committed Jan 20, 2021 at 19:27 UTC d162b25f9568c0e874570dfdbdae74f767b6836b
14 files changed +21 -160
Documentation/MyFirstContribution.txt
+1 -1
@@ -664,7 +664,7 @@ mention the right animal somewhere:
664 ----
665 test_expect_success 'runs correctly with no args and good output' '
666 git psuh >actual &&
667 - test_i18ngrep Pony actual
667 + grep Pony actual
668 '
669 ----
670
config.c
-9
@@ -996,15 +996,6 @@ static void die_bad_number(const char *name, const char *value)
996 if (!value)
997 value = "";
998
999 - if (!strcmp(name, "GIT_TEST_GETTEXT_POISON"))
1000 - /*
1001 - * We explicitly *don't* use _() here since it would
1002 - * cause an infinite loop with _() needing to call
1003 - * use_gettext_poison(). This is why marked up
1004 - * translations with N_() above.
1005 - */
1006 - die(bad_numeric, value, name, error_type);
1007 -
999 if (!(cf && cf->name))
1000 die(_(bad_numeric), value, name, _(error_type));
1001
gettext.c
-10
@@ -65,14 +65,6 @@ const char *get_preferred_languages(void)
65 return NULL;
66 }
67
68 -int use_gettext_poison(void)
69 -{
70 - static int poison_requested = -1;
71 - if (poison_requested == -1)
72 - poison_requested = git_env_bool("GIT_TEST_GETTEXT_POISON", 0);
73 - return poison_requested;
74 -}
75 -
68 #ifndef NO_GETTEXT
69 static int test_vsnprintf(const char *fmt, ...)
70 {
@@ -181,8 +173,6 @@ void git_setup_gettext(void)
173 if (!podir)
174 podir = p = system_path(GIT_LOCALE_PATH);
175
184 - use_gettext_poison(); /* getenv() reentrancy paranoia */
185 -
176 if (!is_directory(podir)) {
177 free(p);
178 return;
gettext.h
+1 -6
@@ -28,15 +28,12 @@
28
29 #define FORMAT_PRESERVING(n) __attribute__((format_arg(n)))
30
31 -int use_gettext_poison(void);
32 -
31 #ifndef NO_GETTEXT
32 void git_setup_gettext(void);
33 int gettext_width(const char *s);
34 #else
35 static inline void git_setup_gettext(void)
36 {
39 - use_gettext_poison(); /* getenv() reentrancy paranoia */
37 }
38 static inline int gettext_width(const char *s)
39 {
@@ -48,14 +45,12 @@ static inline FORMAT_PRESERVING(1) const char *_(const char *msgid)
45 {
46 if (!*msgid)
47 return "";
51 - return use_gettext_poison() ? "# GETTEXT POISON #" : gettext(msgid);
48 + return gettext(msgid);
49 }
50
51 static inline FORMAT_PRESERVING(1) FORMAT_PRESERVING(2)
52 const char *Q_(const char *msgid, const char *plu, unsigned long n)
53 {
57 - if (use_gettext_poison())
58 - return "# GETTEXT POISON #";
54 return ngettext(msgid, plu, n);
55 }
56
git-sh-i18n.sh
+1 -21
@@ -17,12 +17,7 @@ export TEXTDOMAINDIR
17
18 # First decide what scheme to use...
19 GIT_INTERNAL_GETTEXT_SH_SCHEME=fallthrough
20 -if test -n "$GIT_TEST_GETTEXT_POISON" &&
21 - git env--helper --type=bool --default=0 --exit-code \
22 - GIT_TEST_GETTEXT_POISON
23 -then
24 - GIT_INTERNAL_GETTEXT_SH_SCHEME=poison
25 -elif test -n "@@USE_GETTEXT_SCHEME@@"
20 +if test -n "@@USE_GETTEXT_SCHEME@@"
21 then
22 GIT_INTERNAL_GETTEXT_SH_SCHEME="@@USE_GETTEXT_SCHEME@@"
23 elif test -n "$GIT_INTERNAL_GETTEXT_TEST_FALLBACKS"
@@ -63,21 +58,6 @@ gettext_without_eval_gettext)
58 )
59 }
60 ;;
66 -poison)
67 - # Emit garbage so that tests that incorrectly rely on translatable
68 - # strings will fail.
69 - gettext () {
70 - printf "%s" "# GETTEXT POISON #"
71 - }
72 -
73 - eval_gettext () {
74 - printf "%s" "# GETTEXT POISON #"
75 - }
76 -
77 - eval_ngettext () {
78 - printf "%s" "# GETTEXT POISON #"
79 - }
80 - ;;
61 *)
62 gettext () {
63 printf "%s" "$1"
po/README
+2 -20
@@ -284,23 +284,5 @@ Perl:
284 Testing marked strings
285 ----------------------
286
287 -Even if you've correctly marked porcelain strings for translation
288 -something in the test suite might still depend on the US English
289 -version of the strings, e.g. to grep some error message or other
290 -output.
291 -
292 -To smoke out issues like these, Git tested with a translation mode that
293 -emits gibberish on every call to gettext. To use it run the test suite
294 -with it, e.g.:
295 -
296 - cd t && GIT_TEST_GETTEXT_POISON=true prove -j 9 ./t[0-9]*.sh
297 -
298 -If tests break with it you should inspect them manually and see if
299 -what you're translating is sane, i.e. that you're not translating
300 -plumbing output.
301 -
302 -If not you should replace calls to grep with test_i18ngrep, or
303 -test_cmp calls with test_i18ncmp. If that's not enough you can skip
304 -the whole test by making it depend on the C_LOCALE_OUTPUT
305 -prerequisite. See existing test files with this prerequisite for
306 -examples.
287 +Git's tests are run under LANG=C LC_ALL=C. So the tests do not need be
288 +changed to account for translations as they're added.
t/README
-6
@@ -358,12 +358,6 @@ whether this mode is active, and e.g. skip some tests that are hard to
358 refactor to deal with it. The "SYMLINKS" prerequisite is currently
359 excluded as so much relies on it, but this might change in the future.
360
361 -GIT_TEST_GETTEXT_POISON=<boolean> turns all strings marked for
362 -translation into gibberish if true. Used for spotting those tests that
363 -need to be marked with a C_LOCALE_OUTPUT prerequisite when adding more
364 -strings for translation. See "Testing marked strings" in po/README for
365 -details.
366 -
361 GIT_TEST_SPLIT_INDEX=<boolean> forces split-index mode on the whole
362 test suite. Accept any boolean values that are accepted by git-config.
363
t/lib-gettext.sh
+1 -1
@@ -17,7 +17,7 @@ else
17 . "$GIT_BUILD_DIR"/git-sh-i18n
18 fi
19
20 -if test_have_prereq GETTEXT && test_have_prereq C_LOCALE_OUTPUT
20 +if test_have_prereq GETTEXT
21 then
22 # is_IS.UTF-8 on Solaris and FreeBSD, is_IS.utf8 on Debian
23 is_IS_locale=$(locale -a 2>/dev/null |
t/lib-rebase.sh
-1
@@ -29,7 +29,6 @@ set_fake_editor () {
29 */COMMIT_EDITMSG)
30 test -z "$EXPECT_HEADER_COUNT" ||
31 test "$EXPECT_HEADER_COUNT" = "$(sed -n '1s/^# This is a combination of \(.*\) commits\./\1/p' < "$1")" ||
32 - test "# # GETTEXT POISON #" = "$(sed -n '1p' < "$1")" ||
32 exit
33 test -z "$FAKE_COMMIT_MESSAGE" || echo "$FAKE_COMMIT_MESSAGE" > "$1"
34 test -z "$FAKE_COMMIT_AMEND" || echo "$FAKE_COMMIT_AMEND" >> "$1"
t/t0017-env-helper.sh
+4 -4
@@ -86,14 +86,14 @@ test_expect_success 'env--helper reads config thanks to trace2' '
86 git config -f home/cycle include.path .gitconfig &&
87
88 test_must_fail \
89 - env HOME="$(pwd)/home" GIT_TEST_GETTEXT_POISON=false \
89 + env HOME="$(pwd)/home" \
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
94 + env HOME="$(pwd)/home" GIT_TEST_ENV_HELPER=true \
95 + git -C cycle env--helper --type=bool --default=0 --exit-code GIT_TEST_ENV_HELPER 2>err &&
96 + grep "exceeded maximum include depth" err
97 '
98
99 test_done
t/t0205-gettext-poison.sh deleted
-39
@@ -1,39 +0,0 @@
1 -#!/bin/sh
2 -#
3 -# Copyright (c) 2010 Ævar Arnfjörð Bjarmason
4 -#
5 -
6 -test_description='Gettext Shell poison'
7 -
8 -GIT_TEST_GETTEXT_POISON=true
9 -export GIT_TEST_GETTEXT_POISON
10 -. ./lib-gettext.sh
11 -
12 -test_expect_success 'sanity: $GIT_INTERNAL_GETTEXT_SH_SCHEME" is poison' '
13 - test "$GIT_INTERNAL_GETTEXT_SH_SCHEME" = "poison"
14 -'
15 -
16 -test_expect_success 'gettext: our gettext() fallback has poison semantics' '
17 - printf "# GETTEXT POISON #" >expect &&
18 - gettext "test" >actual &&
19 - test_cmp expect actual &&
20 - printf "# GETTEXT POISON #" >expect &&
21 - gettext "test more words" >actual &&
22 - test_cmp expect actual
23 -'
24 -
25 -test_expect_success 'eval_gettext: our eval_gettext() fallback has poison semantics' '
26 - printf "# GETTEXT POISON #" >expect &&
27 - eval_gettext "test" >actual &&
28 - test_cmp expect actual &&
29 - printf "# GETTEXT POISON #" >expect &&
30 - eval_gettext "test more words" >actual &&
31 - test_cmp expect actual
32 -'
33 -
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 -
39 -test_done
t/t3406-rebase-message.sh
-7
@@ -64,13 +64,6 @@ test_expect_success 'rebase -n overrides config rebase.stat config' '
64 ! grep "^ fileX | *1 +$" diffstat.txt
65 '
66
67 -# Output to stderr:
68 -#
69 -# "Does not point to a valid commit: invalid-ref"
70 -#
71 -# NEEDSWORK: This "grep" is fine in real non-C locales, but
72 -# GIT_TEST_GETTEXT_POISON poisons the refname along with the enclosing
73 -# error message.
67 test_expect_success 'rebase --onto outputs the invalid ref' '
68 test_must_fail git rebase --onto invalid-ref HEAD HEAD 2>err &&
69 test_i18ngrep "invalid-ref" err
t/test-lib-functions.sh
+7 -16
@@ -988,19 +988,16 @@ test_cmp_bin () {
988 cmp "$@"
989 }
990
991 -# Use this instead of test_cmp to compare files that contain expected and
992 -# actual output from git commands that can be translated. When running
993 -# under GIT_TEST_GETTEXT_POISON this pretends that the command produced expected
994 -# results.
991 +# Wrapper for test_cmp which used to be used for
992 +# GIT_TEST_GETTEXT_POISON=false. Only here as a shim for other
993 +# in-flight changes. Should not be used and will be removed soon.
994 test_i18ncmp () {
996 - ! test_have_prereq C_LOCALE_OUTPUT || test_cmp "$@"
995 + test_cmp "$@"
996 }
997
999 -# Use this instead of "grep expected-string actual" to see if the
1000 -# output from a git command that can be translated either contains an
1001 -# expected string, or does not contain an unwanted one. When running
1002 -# under GIT_TEST_GETTEXT_POISON this pretends that the command produced expected
1003 -# results.
998 +# Wrapper for grep which used to be used for
999 +# GIT_TEST_GETTEXT_POISON=false. Only here as a shim for other
1000 +# in-flight changes. Should not be used and will be removed soon.
1001 test_i18ngrep () {
1002 eval "last_arg=\${$#}"
1003
@@ -1013,12 +1010,6 @@ test_i18ngrep () {
1010 BUG "too few parameters to test_i18ngrep"
1011 fi
1012
1016 - if test_have_prereq !C_LOCALE_OUTPUT
1017 - then
1018 - # pretend success
1019 - return 0
1020 - fi
1021 -
1013 if test "x!" = "x$1"
1014 then
1015 shift
t/test-lib.sh
+4 -19
@@ -404,15 +404,6 @@ TZ=UTC
404 export LANG LC_ALL PAGER TZ
405 EDITOR=:
406
407 -# GIT_TEST_GETTEXT_POISON should not influence git commands executed
408 -# during initialization of test-lib and the test repo. Back it up,
409 -# unset and then restore after initialization is finished.
410 -if test -n "$GIT_TEST_GETTEXT_POISON"
411 -then
412 - GIT_TEST_GETTEXT_POISON_ORIG=$GIT_TEST_GETTEXT_POISON
413 - unset GIT_TEST_GETTEXT_POISON
414 -fi
415 -
407 # A call to "unset" with no arguments causes at least Solaris 10
408 # /usr/xpg4/bin/sh and /bin/ksh to bail out. So keep the unsets
409 # deriving from the command substitution clustered with the other
@@ -1529,16 +1520,10 @@ test -n "$USE_LIBPCRE1" && test_set_prereq LIBPCRE1
1520 test -n "$USE_LIBPCRE2" && test_set_prereq LIBPCRE2
1521 test -z "$NO_GETTEXT" && test_set_prereq GETTEXT
1522
1532 -if test -n "$GIT_TEST_GETTEXT_POISON_ORIG"
1533 -then
1534 - GIT_TEST_GETTEXT_POISON=$GIT_TEST_GETTEXT_POISON_ORIG
1535 - export GIT_TEST_GETTEXT_POISON
1536 - unset GIT_TEST_GETTEXT_POISON_ORIG
1537 -fi
1538 -
1539 -test_lazy_prereq C_LOCALE_OUTPUT '
1540 - ! test_bool_env GIT_TEST_GETTEXT_POISON false
1541 -'
1523 +# Used to be used for GIT_TEST_GETTEXT_POISON=false. Only here as a
1524 +# shim for other in-flight changes. Should not be used and will be
1525 +# removed soon.
1526 +test_set_prereq C_LOCALE_OUTPUT
1527
1528 if test -z "$GIT_TEST_CHECK_CACHE_TREE"
1529 then