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>

Đoàn Trần Công Danh committed Jun 8, 2021 at 13:56 UTC 482c962de4af32471a5ab770160731a028fcd9d6
6 files changed +32 -22
Makefile
+7
@@ -398,6 +398,10 @@ all::
398 # with a different indexfile format version. If it isn't set the index
399 # file format used is index-v[23].
400 #
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 +#
405 # Define HAVE_CLOCK_GETTIME if your platform has clock_gettime.
406 #
407 # Define HAVE_CLOCK_MONOTONIC if your platform has CLOCK_MONOTONIC.
@@ -2740,6 +2744,9 @@ ifdef GIT_TEST_CMP
2744 endif
2745 ifdef GIT_TEST_CMP_USE_COPIED_CONTEXT
2746 @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)))'\' >>$@+
2750 endif
2751 @echo NO_GETTEXT=\''$(subst ','\'',$(subst ','\'',$(NO_GETTEXT)))'\' >>$@+
2752 ifdef GIT_PERF_REPEAT_COUNT
ci/lib.sh
+1
@@ -229,6 +229,7 @@ linux-musl)
229 CC=gcc
230 MAKEFLAGS="$MAKEFLAGS PYTHON_PATH=/usr/bin/python3 USE_LIBPCRE2=Yes"
231 MAKEFLAGS="$MAKEFLAGS NO_REGEX=Yes ICONV_OMITS_BOM=Yes"
232 + MAKEFLAGS="$MAKEFLAGS GIT_TEST_UTF8_LOCALE=C.UTF-8"
233 ;;
234 esac
235
t/lib-git-svn.sh
+16 -6
@@ -121,12 +121,22 @@ start_svnserve () {
121 --listen-host 127.0.0.1 &
122 }
123
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"
140 then
141 test_set_prereq UTF8
142 else
t/t9100-git-svn-basic.sh
+3 -11
@@ -4,21 +4,13 @@
4 #
5
6 test_description='git svn basic tests'
7 -GIT_SVN_LC_ALL=${LC_ALL:-$LANG}
7
8 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
9 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
10
11 . ./lib-git-svn.sh
12
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
14
15 test_expect_success 'git svn --version works anywhere' '
16 nongit git svn --version
@@ -187,8 +179,8 @@ test_expect_success POSIXPERM,SYMLINKS "$name" '
179 test ! -h "$SVN_TREE"/exec-2.sh &&
180 test_cmp help "$SVN_TREE"/exec-2.sh'
181
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"
184 export LC_ALL
185 # This test relies on the previous test, hence requires POSIXPERM,SYMLINKS
186 test_expect_success UTF8,POSIXPERM,SYMLINKS "$name" "
t/t9115-git-svn-dcommit-funky-renames.sh
+3 -3
@@ -93,9 +93,9 @@ test_expect_success 'git svn rebase works inside a fresh-cloned repository' '
93 # > ... All of the above characters, except for the backslash, are converted
94 # > to special UNICODE characters in the range 0xf000 to 0xf0ff (the
95 # > "Private use area") when creating or accessing files.
96 -prepare_a_utf8_locale
96 +prepare_utf8_locale
97 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 &&
99 export LC_ALL &&
100 neq=$(printf "\201\202") &&
101 git config svn.pathnameencoding cp932 &&
@@ -107,7 +107,7 @@ test_expect_success UTF8,!MINGW,!UTF8_NFD_TO_NFC 'svn.pathnameencoding=cp932 new
107
108 # See the comment on the above test for setting of LC_ALL.
109 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 &&
111 export LC_ALL &&
112 inf=$(printf "\201\207") &&
113 git config svn.pathnameencoding cp932 &&
t/t9129-git-svn-i18n-commitencoding.sh
+2 -2
@@ -14,12 +14,12 @@ compare_git_head_with () {
14 test_cmp current "$1"
15 }
16
17 -prepare_a_utf8_locale
17 +prepare_utf8_locale
18
19 compare_svn_head_with () {
20 # extract just the log message and strip out committer info.
21 # 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 '
23 use bytes;
24 $/ = ("-"x72) . "\n";
25 my @x = <STDIN>;