Skip to content

Commit 482c962

Browse files
sgngitster
authored andcommitted
t: use user-specified utf-8 locale for testing svn
In some test-cases, UTF-8 locale is required. To find such locale, we're using the first available UTF-8 locale that returned by "locale -a". However, the locale(1) utility is unavailable on some systems, e.g. Linux with musl libc. However, without "locale -a", we can't guess provided UTF-8 locale. Add a Makefile knob GIT_TEST_UTF8_LOCALE and activate it for linux-musl in our CI system. Rename t/lib-git-svn.sh:prepare_a_utf8_locale to prepare_utf8_locale, since we no longer prepare the variable named "a_utf8_locale", but set up a fallback value for GIT_TEST_UTF8_LOCALE instead. The fallback will be LC_ALL, LANG environment variable, or the first UTF-8 locale from output of "locale -a", in that order. Signed-off-by: Đoàn Trần Công Danh <congdanhqx@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 48bf2fa commit 482c962

File tree

6 files changed

+32
-22
lines changed

6 files changed

+32
-22
lines changed

Makefile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,10 @@ all::
398398
# with a different indexfile format version. If it isn't set the index
399399
# file format used is index-v[23].
400400
#
401+
# Define GIT_TEST_UTF8_LOCALE to preferred utf-8 locale for testing.
402+
# If it isn't set, fallback to $LC_ALL, $LANG or use the first utf-8
403+
# locale returned by "locale -a".
404+
#
401405
# Define HAVE_CLOCK_GETTIME if your platform has clock_gettime.
402406
#
403407
# Define HAVE_CLOCK_MONOTONIC if your platform has CLOCK_MONOTONIC.
@@ -2740,6 +2744,9 @@ ifdef GIT_TEST_CMP
27402744
endif
27412745
ifdef GIT_TEST_CMP_USE_COPIED_CONTEXT
27422746
@echo GIT_TEST_CMP_USE_COPIED_CONTEXT=YesPlease >>$@+
2747+
endif
2748+
ifdef GIT_TEST_UTF8_LOCALE
2749+
@echo GIT_TEST_UTF8_LOCALE=\''$(subst ','\'',$(subst ','\'',$(GIT_TEST_UTF8_LOCALE)))'\' >>$@+
27432750
endif
27442751
@echo NO_GETTEXT=\''$(subst ','\'',$(subst ','\'',$(NO_GETTEXT)))'\' >>$@+
27452752
ifdef GIT_PERF_REPEAT_COUNT

ci/lib.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ linux-musl)
229229
CC=gcc
230230
MAKEFLAGS="$MAKEFLAGS PYTHON_PATH=/usr/bin/python3 USE_LIBPCRE2=Yes"
231231
MAKEFLAGS="$MAKEFLAGS NO_REGEX=Yes ICONV_OMITS_BOM=Yes"
232+
MAKEFLAGS="$MAKEFLAGS GIT_TEST_UTF8_LOCALE=C.UTF-8"
232233
;;
233234
esac
234235

t/lib-git-svn.sh

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,22 @@ start_svnserve () {
121121
--listen-host 127.0.0.1 &
122122
}
123123

124-
prepare_a_utf8_locale () {
125-
a_utf8_locale=$(locale -a | sed -n '/\.[uU][tT][fF]-*8$/{
126-
p
127-
q
128-
}')
129-
if test -n "$a_utf8_locale"
124+
prepare_utf8_locale () {
125+
if test -z "$GIT_TEST_UTF8_LOCALE"
126+
then
127+
case "${LC_ALL:-$LANG}" in
128+
*.[Uu][Tt][Ff]8 | *.[Uu][Tt][Ff]-8)
129+
GIT_TEST_UTF8_LOCALE="${LC_ALL:-$LANG}"
130+
;;
131+
*)
132+
GIT_TEST_UTF8_LOCALE=$(locale -a | sed -n '/\.[uU][tT][fF]-*8$/{
133+
p
134+
q
135+
}')
136+
;;
137+
esac
138+
fi
139+
if test -n "$GIT_TEST_UTF8_LOCALE"
130140
then
131141
test_set_prereq UTF8
132142
else

t/t9100-git-svn-basic.sh

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,13 @@
44
#
55

66
test_description='git svn basic tests'
7-
GIT_SVN_LC_ALL=${LC_ALL:-$LANG}
87

98
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
109
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
1110

1211
. ./lib-git-svn.sh
1312

14-
case "$GIT_SVN_LC_ALL" in
15-
*.UTF-8)
16-
test_set_prereq UTF8
17-
;;
18-
*)
19-
say "# UTF-8 locale not set, some tests skipped ($GIT_SVN_LC_ALL)"
20-
;;
21-
esac
13+
prepare_utf8_locale
2214

2315
test_expect_success 'git svn --version works anywhere' '
2416
nongit git svn --version
@@ -187,8 +179,8 @@ test_expect_success POSIXPERM,SYMLINKS "$name" '
187179
test ! -h "$SVN_TREE"/exec-2.sh &&
188180
test_cmp help "$SVN_TREE"/exec-2.sh'
189181

190-
name="commit with UTF-8 message: locale: $GIT_SVN_LC_ALL"
191-
LC_ALL="$GIT_SVN_LC_ALL"
182+
name="commit with UTF-8 message: locale: $GIT_TEST_UTF8_LOCALE"
183+
LC_ALL="$GIT_TEST_UTF8_LOCALE"
192184
export LC_ALL
193185
# This test relies on the previous test, hence requires POSIXPERM,SYMLINKS
194186
test_expect_success UTF8,POSIXPERM,SYMLINKS "$name" "

t/t9115-git-svn-dcommit-funky-renames.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,9 @@ test_expect_success 'git svn rebase works inside a fresh-cloned repository' '
9393
# > ... All of the above characters, except for the backslash, are converted
9494
# > to special UNICODE characters in the range 0xf000 to 0xf0ff (the
9595
# > "Private use area") when creating or accessing files.
96-
prepare_a_utf8_locale
96+
prepare_utf8_locale
9797
test_expect_success UTF8,!MINGW,!UTF8_NFD_TO_NFC 'svn.pathnameencoding=cp932 new file on dcommit' '
98-
LC_ALL=$a_utf8_locale &&
98+
LC_ALL=$GIT_TEST_UTF8_LOCALE &&
9999
export LC_ALL &&
100100
neq=$(printf "\201\202") &&
101101
git config svn.pathnameencoding cp932 &&
@@ -107,7 +107,7 @@ test_expect_success UTF8,!MINGW,!UTF8_NFD_TO_NFC 'svn.pathnameencoding=cp932 new
107107

108108
# See the comment on the above test for setting of LC_ALL.
109109
test_expect_success !MINGW,!UTF8_NFD_TO_NFC 'svn.pathnameencoding=cp932 rename on dcommit' '
110-
LC_ALL=$a_utf8_locale &&
110+
LC_ALL=$GIT_TEST_UTF8_LOCALE &&
111111
export LC_ALL &&
112112
inf=$(printf "\201\207") &&
113113
git config svn.pathnameencoding cp932 &&

t/t9129-git-svn-i18n-commitencoding.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ compare_git_head_with () {
1414
test_cmp current "$1"
1515
}
1616

17-
prepare_a_utf8_locale
17+
prepare_utf8_locale
1818

1919
compare_svn_head_with () {
2020
# extract just the log message and strip out committer info.
2121
# don't use --limit here since svn 1.1.x doesn't have it,
22-
LC_ALL="$a_utf8_locale" svn log $(git svn info --url) | perl -w -e '
22+
LC_ALL="$GIT_TEST_UTF8_LOCALE" svn log $(git svn info --url) | perl -w -e '
2323
use bytes;
2424
$/ = ("-"x72) . "\n";
2525
my @x = <STDIN>;

0 commit comments

Comments
 (0)