Skip to content

Commit 9549326

Browse files
committed
Merge branch 'ab/dynamic-gettext-poison'
Our testing framework uses a special i18n "poisoned localization" feature to find messages that ought to stay constant but are incorrectly marked to be translated. This feature has been made into a runtime option (it used to be a compile-time option). * ab/dynamic-gettext-poison: Makefile: ease dynamic-gettext-poison transition i18n: make GETTEXT_POISON a runtime option
2 parents 0e94dab + c6a9a30 commit 9549326

16 files changed

+59
-49
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ compiler:
1414

1515
matrix:
1616
include:
17-
- env: jobname=GETTEXT_POISON
17+
- env: jobname=GIT_TEST_GETTEXT_POISON
1818
os: linux
1919
compiler:
2020
addons:

Makefile

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -365,11 +365,6 @@ all::
365365
# Define HAVE_DEV_TTY if your system can open /dev/tty to interact with the
366366
# user.
367367
#
368-
# Define GETTEXT_POISON if you are debugging the choice of strings marked
369-
# for translation. In a GETTEXT_POISON build, you can turn all strings marked
370-
# for translation into gibberish by setting the GIT_GETTEXT_POISON variable
371-
# (to any value) in your environment.
372-
#
373368
# Define JSMIN to point to JavaScript minifier that functions as
374369
# a filter to have gitweb.js minified.
375370
#
@@ -1454,7 +1449,7 @@ ifdef NO_SYMLINK_HEAD
14541449
BASIC_CFLAGS += -DNO_SYMLINK_HEAD
14551450
endif
14561451
ifdef GETTEXT_POISON
1457-
BASIC_CFLAGS += -DGETTEXT_POISON
1452+
$(warning The GETTEXT_POISON option has been removed in favor of runtime GIT_TEST_GETTEXT_POISON. See t/README!)
14581453
endif
14591454
ifdef NO_GETTEXT
14601455
BASIC_CFLAGS += -DNO_GETTEXT
@@ -2604,7 +2599,6 @@ ifdef GIT_TEST_CMP_USE_COPIED_CONTEXT
26042599
@echo GIT_TEST_CMP_USE_COPIED_CONTEXT=YesPlease >>$@+
26052600
endif
26062601
@echo NO_GETTEXT=\''$(subst ','\'',$(subst ','\'',$(NO_GETTEXT)))'\' >>$@+
2607-
@echo GETTEXT_POISON=\''$(subst ','\'',$(subst ','\'',$(GETTEXT_POISON)))'\' >>$@+
26082602
ifdef GIT_PERF_REPEAT_COUNT
26092603
@echo GIT_PERF_REPEAT_COUNT=\''$(subst ','\'',$(subst ','\'',$(GIT_PERF_REPEAT_COUNT)))'\' >>$@+
26102604
endif

ci/lib-travisci.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ osx-clang|osx-gcc)
123123
# Travis CI OS X
124124
export GIT_SKIP_TESTS="t9810 t9816"
125125
;;
126-
GETTEXT_POISON)
127-
export GETTEXT_POISON=YesPlease
126+
GIT_TEST_GETTEXT_POISON)
127+
export GIT_TEST_GETTEXT_POISON=YesPlease
128128
;;
129129
esac

gettext.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "gettext.h"
88
#include "strbuf.h"
99
#include "utf8.h"
10+
#include "config.h"
1011

1112
#ifndef NO_GETTEXT
1213
# include <locale.h>
@@ -46,15 +47,15 @@ const char *get_preferred_languages(void)
4647
return NULL;
4748
}
4849

49-
#ifdef GETTEXT_POISON
5050
int use_gettext_poison(void)
5151
{
5252
static int poison_requested = -1;
53-
if (poison_requested == -1)
54-
poison_requested = getenv("GIT_GETTEXT_POISON") ? 1 : 0;
53+
if (poison_requested == -1) {
54+
const char *v = getenv("GIT_TEST_GETTEXT_POISON");
55+
poison_requested = v && strlen(v) ? 1 : 0;
56+
}
5557
return poison_requested;
5658
}
57-
#endif
5859

5960
#ifndef NO_GETTEXT
6061
static int test_vsnprintf(const char *fmt, ...)
@@ -164,6 +165,8 @@ void git_setup_gettext(void)
164165
if (!podir)
165166
podir = p = system_path(GIT_LOCALE_PATH);
166167

168+
use_gettext_poison(); /* getenv() reentrancy paranoia */
169+
167170
if (!is_directory(podir)) {
168171
free(p);
169172
return;

gettext.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,25 +28,22 @@
2828

2929
#define FORMAT_PRESERVING(n) __attribute__((format_arg(n)))
3030

31+
extern int use_gettext_poison(void);
32+
3133
#ifndef NO_GETTEXT
3234
extern void git_setup_gettext(void);
3335
extern int gettext_width(const char *s);
3436
#else
3537
static inline void git_setup_gettext(void)
3638
{
39+
use_gettext_poison(); /* getenv() reentrancy paranoia */
3740
}
3841
static inline int gettext_width(const char *s)
3942
{
4043
return strlen(s);
4144
}
4245
#endif
4346

44-
#ifdef GETTEXT_POISON
45-
extern int use_gettext_poison(void);
46-
#else
47-
#define use_gettext_poison() 0
48-
#endif
49-
5047
static inline FORMAT_PRESERVING(1) const char *_(const char *msgid)
5148
{
5249
if (!*msgid)

git-sh-i18n.sh

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

1818
# First decide what scheme to use...
1919
GIT_INTERNAL_GETTEXT_SH_SCHEME=fallthrough
20-
if test -n "$GIT_GETTEXT_POISON"
20+
if test -n "$GIT_TEST_GETTEXT_POISON"
2121
then
2222
GIT_INTERNAL_GETTEXT_SH_SCHEME=poison
2323
elif test -n "@@USE_GETTEXT_SCHEME@@"

po/README

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -289,16 +289,11 @@ something in the test suite might still depend on the US English
289289
version of the strings, e.g. to grep some error message or other
290290
output.
291291

292-
To smoke out issues like these Git can be compiled with gettext poison
293-
support, at the top-level:
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.:
294295

295-
make GETTEXT_POISON=YesPlease
296-
297-
That'll give you a git which emits gibberish on every call to
298-
gettext. It's obviously not meant to be installed, but you should run
299-
the test suite with it:
300-
301-
cd t && prove -j 9 ./t[0-9]*.sh
296+
cd t && GIT_TEST_GETTEXT_POISON=YesPlease prove -j 9 ./t[0-9]*.sh
302297

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

t/README

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,12 @@ that cannot be easily covered by a few specific test cases. These
302302
could be enabled by running the test suite with correct GIT_TEST_
303303
environment set.
304304

305+
GIT_TEST_GETTEXT_POISON=<non-empty?> turns all strings marked for
306+
translation into gibberish if non-empty (think "test -n"). Used for
307+
spotting those tests that need to be marked with a C_LOCALE_OUTPUT
308+
prerequisite when adding more strings for translation. See "Testing
309+
marked strings" in po/README for details.
310+
305311
GIT_TEST_SPLIT_INDEX=<boolean> forces split-index mode on the whole
306312
test suite. Accept any boolean values that are accepted by git-config.
307313

t/lib-gettext.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export GIT_TEXTDOMAINDIR GIT_PO_PATH
1212

1313
. "$GIT_BUILD_DIR"/git-sh-i18n
1414

15-
if test_have_prereq GETTEXT && ! test_have_prereq GETTEXT_POISON
15+
if test_have_prereq GETTEXT && test_have_prereq C_LOCALE_OUTPUT
1616
then
1717
# is_IS.UTF-8 on Solaris and FreeBSD, is_IS.utf8 on Debian
1818
is_IS_locale=$(locale -a 2>/dev/null |

t/t0000-basic.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ test_expect_success 'pretend we have a mix of all possible results' "
274274
EOF
275275
"
276276

277-
test_expect_success 'test --verbose' '
277+
test_expect_success C_LOCALE_OUTPUT 'test --verbose' '
278278
test_must_fail run_sub_test_lib_test \
279279
test-verbose "test verbose" --verbose <<-\EOF &&
280280
test_expect_success "passing test" true

0 commit comments

Comments
 (0)