Merge branch 'ab/detox-gettext-tests'

Get rid of "GETTEXT_POISON" support altogether, which may or may
not be controversial.

* ab/detox-gettext-tests:
  tests: remove uses of GIT_TEST_GETTEXT_POISON=false
  tests: remove support for GIT_TEST_GETTEXT_POISON
  ci: remove GETTEXT_POISON jobs
This commit is contained in:
Junio C Hamano 2021-02-10 14:48:33 -08:00
commit 466f94ec45
22 changed files with 29 additions and 173 deletions

View File

@ -289,7 +289,7 @@ jobs:
- jobname: osx-gcc - jobname: osx-gcc
cc: gcc cc: gcc
pool: macos-latest pool: macos-latest
- jobname: GETTEXT_POISON - jobname: linux-gcc-default
cc: gcc cc: gcc
pool: ubuntu-latest pool: ubuntu-latest
env: env:

View File

@ -16,7 +16,7 @@ compiler:
matrix: matrix:
include: include:
- env: jobname=GETTEXT_POISON - env: jobname=linux-gcc-default
os: linux os: linux
compiler: compiler:
addons: addons:

View File

@ -664,7 +664,7 @@ mention the right animal somewhere:
---- ----
test_expect_success 'runs correctly with no args and good output' ' test_expect_success 'runs correctly with no args and good output' '
git psuh >actual && git psuh >actual &&
test_i18ngrep Pony actual grep Pony actual
' '
---- ----

View File

@ -72,7 +72,7 @@ Documentation)
test -n "$ALREADY_HAVE_ASCIIDOCTOR" || test -n "$ALREADY_HAVE_ASCIIDOCTOR" ||
sudo gem install --version 1.5.8 asciidoctor sudo gem install --version 1.5.8 asciidoctor
;; ;;
linux-gcc-4.8|GETTEXT_POISON) linux-gcc-default|linux-gcc-4.8)
sudo apt-get -q update sudo apt-get -q update
sudo apt-get -q -y install $UBUNTU_COMMON_PKGS sudo apt-get -q -y install $UBUNTU_COMMON_PKGS
;; ;;

View File

@ -220,8 +220,7 @@ osx-clang|osx-gcc)
# Travis CI OS X # Travis CI OS X
export GIT_SKIP_TESTS="t9810 t9816" export GIT_SKIP_TESTS="t9810 t9816"
;; ;;
GETTEXT_POISON) linux-gcc-default)
export GIT_TEST_GETTEXT_POISON=true
;; ;;
Linux32) Linux32)
CC=gcc CC=gcc

View File

@ -1155,15 +1155,6 @@ static void die_bad_number(const char *name, const char *value)
if (!value) if (!value)
value = ""; value = "";
if (!strcmp(name, "GIT_TEST_GETTEXT_POISON"))
/*
* We explicitly *don't* use _() here since it would
* cause an infinite loop with _() needing to call
* use_gettext_poison(). This is why marked up
* translations with N_() above.
*/
die(bad_numeric, value, name, error_type);
if (!(cf && cf->name)) if (!(cf && cf->name))
die(_(bad_numeric), value, name, _(error_type)); die(_(bad_numeric), value, name, _(error_type));

View File

@ -65,14 +65,6 @@ const char *get_preferred_languages(void)
return NULL; return NULL;
} }
int use_gettext_poison(void)
{
static int poison_requested = -1;
if (poison_requested == -1)
poison_requested = git_env_bool("GIT_TEST_GETTEXT_POISON", 0);
return poison_requested;
}
#ifndef NO_GETTEXT #ifndef NO_GETTEXT
static int test_vsnprintf(const char *fmt, ...) static int test_vsnprintf(const char *fmt, ...)
{ {
@ -117,8 +109,6 @@ void git_setup_gettext(void)
if (!podir) if (!podir)
podir = p = system_path(GIT_LOCALE_PATH); podir = p = system_path(GIT_LOCALE_PATH);
use_gettext_poison(); /* getenv() reentrancy paranoia */
if (!is_directory(podir)) { if (!is_directory(podir)) {
free(p); free(p);
return; return;

View File

@ -28,15 +28,12 @@
#define FORMAT_PRESERVING(n) __attribute__((format_arg(n))) #define FORMAT_PRESERVING(n) __attribute__((format_arg(n)))
int use_gettext_poison(void);
#ifndef NO_GETTEXT #ifndef NO_GETTEXT
void git_setup_gettext(void); void git_setup_gettext(void);
int gettext_width(const char *s); int gettext_width(const char *s);
#else #else
static inline void git_setup_gettext(void) static inline void git_setup_gettext(void)
{ {
use_gettext_poison(); /* getenv() reentrancy paranoia */
} }
static inline int gettext_width(const char *s) static inline int gettext_width(const char *s)
{ {
@ -48,14 +45,12 @@ static inline FORMAT_PRESERVING(1) const char *_(const char *msgid)
{ {
if (!*msgid) if (!*msgid)
return ""; return "";
return use_gettext_poison() ? "# GETTEXT POISON #" : gettext(msgid); return gettext(msgid);
} }
static inline FORMAT_PRESERVING(1) FORMAT_PRESERVING(2) static inline FORMAT_PRESERVING(1) FORMAT_PRESERVING(2)
const char *Q_(const char *msgid, const char *plu, unsigned long n) const char *Q_(const char *msgid, const char *plu, unsigned long n)
{ {
if (use_gettext_poison())
return "# GETTEXT POISON #";
return ngettext(msgid, plu, n); return ngettext(msgid, plu, n);
} }

View File

@ -17,12 +17,7 @@ export TEXTDOMAINDIR
# First decide what scheme to use... # First decide what scheme to use...
GIT_INTERNAL_GETTEXT_SH_SCHEME=fallthrough GIT_INTERNAL_GETTEXT_SH_SCHEME=fallthrough
if test -n "$GIT_TEST_GETTEXT_POISON" && if test -n "@@USE_GETTEXT_SCHEME@@"
git env--helper --type=bool --default=0 --exit-code \
GIT_TEST_GETTEXT_POISON
then
GIT_INTERNAL_GETTEXT_SH_SCHEME=poison
elif test -n "@@USE_GETTEXT_SCHEME@@"
then then
GIT_INTERNAL_GETTEXT_SH_SCHEME="@@USE_GETTEXT_SCHEME@@" GIT_INTERNAL_GETTEXT_SH_SCHEME="@@USE_GETTEXT_SCHEME@@"
elif test -n "$GIT_INTERNAL_GETTEXT_TEST_FALLBACKS" elif test -n "$GIT_INTERNAL_GETTEXT_TEST_FALLBACKS"
@ -63,21 +58,6 @@ gettext_without_eval_gettext)
) )
} }
;; ;;
poison)
# Emit garbage so that tests that incorrectly rely on translatable
# strings will fail.
gettext () {
printf "%s" "# GETTEXT POISON #"
}
eval_gettext () {
printf "%s" "# GETTEXT POISON #"
}
eval_ngettext () {
printf "%s" "# GETTEXT POISON #"
}
;;
*) *)
gettext () { gettext () {
printf "%s" "$1" printf "%s" "$1"

View File

@ -284,23 +284,5 @@ Perl:
Testing marked strings Testing marked strings
---------------------- ----------------------
Even if you've correctly marked porcelain strings for translation Git's tests are run under LANG=C LC_ALL=C. So the tests do not need be
something in the test suite might still depend on the US English changed to account for translations as they're added.
version of the strings, e.g. to grep some error message or other
output.
To smoke out issues like these, Git tested with a translation mode that
emits gibberish on every call to gettext. To use it run the test suite
with it, e.g.:
cd t && GIT_TEST_GETTEXT_POISON=true prove -j 9 ./t[0-9]*.sh
If tests break with it you should inspect them manually and see if
what you're translating is sane, i.e. that you're not translating
plumbing output.
If not you should replace calls to grep with test_i18ngrep, or
test_cmp calls with test_i18ncmp. If that's not enough you can skip
the whole test by making it depend on the C_LOCALE_OUTPUT
prerequisite. See existing test files with this prerequisite for
examples.

View File

@ -358,12 +358,6 @@ whether this mode is active, and e.g. skip some tests that are hard to
refactor to deal with it. The "SYMLINKS" prerequisite is currently refactor to deal with it. The "SYMLINKS" prerequisite is currently
excluded as so much relies on it, but this might change in the future. excluded as so much relies on it, but this might change in the future.
GIT_TEST_GETTEXT_POISON=<boolean> turns all strings marked for
translation into gibberish if true. Used for spotting those tests that
need to be marked with a C_LOCALE_OUTPUT prerequisite when adding more
strings for translation. See "Testing marked strings" in po/README for
details.
GIT_TEST_SPLIT_INDEX=<boolean> forces split-index mode on the whole GIT_TEST_SPLIT_INDEX=<boolean> forces split-index mode on the whole
test suite. Accept any boolean values that are accepted by git-config. test suite. Accept any boolean values that are accepted by git-config.

View File

@ -17,7 +17,7 @@ else
. "$GIT_BUILD_DIR"/git-sh-i18n . "$GIT_BUILD_DIR"/git-sh-i18n
fi fi
if test_have_prereq GETTEXT && test_have_prereq C_LOCALE_OUTPUT if test_have_prereq GETTEXT
then then
# is_IS.UTF-8 on Solaris and FreeBSD, is_IS.utf8 on Debian # is_IS.UTF-8 on Solaris and FreeBSD, is_IS.utf8 on Debian
is_IS_locale=$(locale -a 2>/dev/null | is_IS_locale=$(locale -a 2>/dev/null |

View File

@ -29,7 +29,6 @@ set_fake_editor () {
*/COMMIT_EDITMSG) */COMMIT_EDITMSG)
test -z "$EXPECT_HEADER_COUNT" || test -z "$EXPECT_HEADER_COUNT" ||
test "$EXPECT_HEADER_COUNT" = "$(sed -n '1s/^# This is a combination of \(.*\) commits\./\1/p' < "$1")" || test "$EXPECT_HEADER_COUNT" = "$(sed -n '1s/^# This is a combination of \(.*\) commits\./\1/p' < "$1")" ||
test "# # GETTEXT POISON #" = "$(sed -n '1p' < "$1")" ||
exit exit
test -z "$FAKE_COMMIT_MESSAGE" || echo "$FAKE_COMMIT_MESSAGE" > "$1" test -z "$FAKE_COMMIT_MESSAGE" || echo "$FAKE_COMMIT_MESSAGE" > "$1"
test -z "$FAKE_COMMIT_AMEND" || echo "$FAKE_COMMIT_AMEND" >> "$1" test -z "$FAKE_COMMIT_AMEND" || echo "$FAKE_COMMIT_AMEND" >> "$1"

View File

@ -86,14 +86,14 @@ test_expect_success 'env--helper reads config thanks to trace2' '
git config -f home/cycle include.path .gitconfig && git config -f home/cycle include.path .gitconfig &&
test_must_fail \ test_must_fail \
env HOME="$(pwd)/home" GIT_TEST_GETTEXT_POISON=false \ env HOME="$(pwd)/home" \
git config -l 2>err && git config -l 2>err &&
grep "exceeded maximum include depth" err && grep "exceeded maximum include depth" err &&
test_must_fail \ test_must_fail \
env HOME="$(pwd)/home" GIT_TEST_GETTEXT_POISON=true \ env HOME="$(pwd)/home" GIT_TEST_ENV_HELPER=true \
git -C cycle env--helper --type=bool --default=0 --exit-code GIT_TEST_GETTEXT_POISON 2>err && git -C cycle env--helper --type=bool --default=0 --exit-code GIT_TEST_ENV_HELPER 2>err &&
grep "# GETTEXT POISON #" err grep "exceeded maximum include depth" err
' '
test_done test_done

View File

@ -1,39 +0,0 @@
#!/bin/sh
#
# Copyright (c) 2010 Ævar Arnfjörð Bjarmason
#
test_description='Gettext Shell poison'
GIT_TEST_GETTEXT_POISON=true
export GIT_TEST_GETTEXT_POISON
. ./lib-gettext.sh
test_expect_success 'sanity: $GIT_INTERNAL_GETTEXT_SH_SCHEME" is poison' '
test "$GIT_INTERNAL_GETTEXT_SH_SCHEME" = "poison"
'
test_expect_success 'gettext: our gettext() fallback has poison semantics' '
printf "# GETTEXT POISON #" >expect &&
gettext "test" >actual &&
test_cmp expect actual &&
printf "# GETTEXT POISON #" >expect &&
gettext "test more words" >actual &&
test_cmp expect actual
'
test_expect_success 'eval_gettext: our eval_gettext() fallback has poison semantics' '
printf "# GETTEXT POISON #" >expect &&
eval_gettext "test" >actual &&
test_cmp expect actual &&
printf "# GETTEXT POISON #" >expect &&
eval_gettext "test more words" >actual &&
test_cmp expect actual
'
test_expect_success "gettext: invalid GIT_TEST_GETTEXT_POISON value doesn't infinitely loop" "
test_must_fail env GIT_TEST_GETTEXT_POISON=xyz git version 2>error &&
grep \"fatal: bad numeric config value 'xyz' for 'GIT_TEST_GETTEXT_POISON': invalid unit\" error
"
test_done

View File

@ -352,9 +352,7 @@ test_expect_success 'include cycles are detected' '
git init --bare cycle && git init --bare cycle &&
git -C cycle config include.path cycle && git -C cycle config include.path cycle &&
git config -f cycle/cycle include.path config && git config -f cycle/cycle include.path config &&
test_must_fail \ test_must_fail git -C cycle config --get-all test.value 2>stderr &&
env GIT_TEST_GETTEXT_POISON=false \
git -C cycle config --get-all test.value 2>stderr &&
grep "exceeded maximum include depth" stderr grep "exceeded maximum include depth" stderr
' '

View File

@ -67,13 +67,6 @@ test_expect_success 'rebase -n overrides config rebase.stat config' '
! grep "^ fileX | *1 +$" diffstat.txt ! grep "^ fileX | *1 +$" diffstat.txt
' '
# Output to stderr:
#
# "Does not point to a valid commit: invalid-ref"
#
# NEEDSWORK: This "grep" is fine in real non-C locales, but
# GIT_TEST_GETTEXT_POISON poisons the refname along with the enclosing
# error message.
test_expect_success 'rebase --onto outputs the invalid ref' ' test_expect_success 'rebase --onto outputs the invalid ref' '
test_must_fail git rebase --onto invalid-ref HEAD HEAD 2>err && test_must_fail git rebase --onto invalid-ref HEAD HEAD 2>err &&
test_i18ngrep "invalid-ref" err test_i18ngrep "invalid-ref" err

View File

@ -36,9 +36,8 @@ create_commits_in () {
# without having to worry about future changes of the commit ID and spaces # without having to worry about future changes of the commit ID and spaces
# of the output. Single quotes are replaced with double quotes, because # of the output. Single quotes are replaced with double quotes, because
# it is boring to prepare unquoted single quotes in expect text. We also # it is boring to prepare unquoted single quotes in expect text. We also
# remove some locale error messages, which break test if we turn on # remove some locale error messages. The emitted human-readable errors are
# `GIT_TEST_GETTEXT_POISON=true` in order to test unintentional translations # redundant to the more machine-readable output the tests already assert.
# on plumbing commands.
make_user_friendly_and_stable_output () { make_user_friendly_and_stable_output () {
sed \ sed \
-e "s/ *\$//" \ -e "s/ *\$//" \

View File

@ -248,7 +248,7 @@ test_expect_success 'checkout to detach HEAD' '
rev=$(git rev-parse --short renamer^) && rev=$(git rev-parse --short renamer^) &&
git checkout -f renamer && git checkout -f renamer &&
git clean -f && git clean -f &&
GIT_TEST_GETTEXT_POISON=false git checkout renamer^ 2>messages && git checkout renamer^ 2>messages &&
grep "HEAD is now at $rev" messages && grep "HEAD is now at $rev" messages &&
test_line_count -gt 1 messages && test_line_count -gt 1 messages &&
H=$(git rev-parse --verify HEAD) && H=$(git rev-parse --verify HEAD) &&

View File

@ -2366,7 +2366,6 @@ test_expect_success 'sourcing the completion script clears cached commands' '
' '
test_expect_success 'sourcing the completion script clears cached merge strategies' ' test_expect_success 'sourcing the completion script clears cached merge strategies' '
GIT_TEST_GETTEXT_POISON=false &&
__git_compute_merge_strategies && __git_compute_merge_strategies &&
verbose test -n "$__git_merge_strategies" && verbose test -n "$__git_merge_strategies" &&
. "$GIT_BUILD_DIR/contrib/completion/git-completion.bash" && . "$GIT_BUILD_DIR/contrib/completion/git-completion.bash" &&

View File

@ -1016,19 +1016,16 @@ test_cmp_bin () {
cmp "$@" cmp "$@"
} }
# Use this instead of test_cmp to compare files that contain expected and # Wrapper for test_cmp which used to be used for
# actual output from git commands that can be translated. When running # GIT_TEST_GETTEXT_POISON=false. Only here as a shim for other
# under GIT_TEST_GETTEXT_POISON this pretends that the command produced expected # in-flight changes. Should not be used and will be removed soon.
# results.
test_i18ncmp () { test_i18ncmp () {
! test_have_prereq C_LOCALE_OUTPUT || test_cmp "$@" test_cmp "$@"
} }
# Use this instead of "grep expected-string actual" to see if the # Wrapper for grep which used to be used for
# output from a git command that can be translated either contains an # GIT_TEST_GETTEXT_POISON=false. Only here as a shim for other
# expected string, or does not contain an unwanted one. When running # in-flight changes. Should not be used and will be removed soon.
# under GIT_TEST_GETTEXT_POISON this pretends that the command produced expected
# results.
test_i18ngrep () { test_i18ngrep () {
eval "last_arg=\${$#}" eval "last_arg=\${$#}"
@ -1041,12 +1038,6 @@ test_i18ngrep () {
BUG "too few parameters to test_i18ngrep" BUG "too few parameters to test_i18ngrep"
fi fi
if test_have_prereq !C_LOCALE_OUTPUT
then
# pretend success
return 0
fi
if test "x!" = "x$1" if test "x!" = "x$1"
then then
shift shift

View File

@ -404,15 +404,6 @@ TZ=UTC
export LANG LC_ALL PAGER TZ export LANG LC_ALL PAGER TZ
EDITOR=: EDITOR=:
# GIT_TEST_GETTEXT_POISON should not influence git commands executed
# during initialization of test-lib and the test repo. Back it up,
# unset and then restore after initialization is finished.
if test -n "$GIT_TEST_GETTEXT_POISON"
then
GIT_TEST_GETTEXT_POISON_ORIG=$GIT_TEST_GETTEXT_POISON
unset GIT_TEST_GETTEXT_POISON
fi
# A call to "unset" with no arguments causes at least Solaris 10 # A call to "unset" with no arguments causes at least Solaris 10
# /usr/xpg4/bin/sh and /bin/ksh to bail out. So keep the unsets # /usr/xpg4/bin/sh and /bin/ksh to bail out. So keep the unsets
# deriving from the command substitution clustered with the other # deriving from the command substitution clustered with the other
@ -1528,16 +1519,10 @@ test -n "$USE_LIBPCRE2" && test_set_prereq PCRE
test -n "$USE_LIBPCRE2" && test_set_prereq LIBPCRE2 test -n "$USE_LIBPCRE2" && test_set_prereq LIBPCRE2
test -z "$NO_GETTEXT" && test_set_prereq GETTEXT test -z "$NO_GETTEXT" && test_set_prereq GETTEXT
if test -n "$GIT_TEST_GETTEXT_POISON_ORIG" # Used to be used for GIT_TEST_GETTEXT_POISON=false. Only here as a
then # shim for other in-flight changes. Should not be used and will be
GIT_TEST_GETTEXT_POISON=$GIT_TEST_GETTEXT_POISON_ORIG # removed soon.
export GIT_TEST_GETTEXT_POISON test_set_prereq C_LOCALE_OUTPUT
unset GIT_TEST_GETTEXT_POISON_ORIG
fi
test_lazy_prereq C_LOCALE_OUTPUT '
! test_bool_env GIT_TEST_GETTEXT_POISON false
'
if test -z "$GIT_TEST_CHECK_CACHE_TREE" if test -z "$GIT_TEST_CHECK_CACHE_TREE"
then then