threads / patch / 16607

patcht9129: Prevent test failure if no UTF-8 locale

Subject: [PATCH] t9129: Prevent test failure if no UTF-8 locale

## tl;dr

2 messages between Dec 6, 2008 and Dec 6, 2008. Diffs are folded; open one to read it.

replies: 1people: 2as markdown or json

applehq· Dec 6, 2008, 01:31 UTC · lore

Commit 16fc08e2d86dad152194829d21bc55b2ef0c8fb1 introduced a test that failed if the en_US.UTF-8 locale was not installed.

Make the test find a UTF-8 locale, and expect failure.
Signed-off-by: applehq <theappleman@gmail.com>
---
 t/t9129-git-svn-i18n-commitencoding.sh |    9 +++++----
 1 files changed, 5 insertions(+), 4 deletions(-)
Show changes to t/t9129-git-svn-i18n-commitencoding.sh +5 −4
diff --git a/t/t9129-git-svn-i18n-commitencoding.sh b/t/t9129-git-svn-i18n-commitencoding.sh
index 938b7fe..87ecdd0 100755
--- a/t/t9129-git-svn-i18n-commitencoding.sh
+++ b/t/t9129-git-svn-i18n-commitencoding.sh
@@ -15,8 +15,9 @@ compare_git_head_with () {
 }
 
 compare_svn_head_with () {
-	LC_ALL=en_US.UTF-8 svn log --limit 1 `git svn info --url` | \
-		sed -e 1,3d -e "/^-\{1,\}\$/d" >current &&
+	LC_ALL=`locale -a | grep -i utf | head -1` \
+		svn log --limit 1 `git svn info --url` | \
+			sed -e 1,3d -e "/^-\{1,\}\$/d" >current &&
 	test_cmp current "$1"
 }
 
@@ -60,7 +61,7 @@ do
 	'
 done
 
-test_expect_success 'ISO-8859-1 should match UTF-8 in svn' '
+test_expect_failure 'ISO-8859-1 should match UTF-8 in svn' '
 (
 	cd ISO-8859-1 &&
 	compare_svn_head_with "$TEST_DIRECTORY"/t3900/1-UTF-8.txt
@@ -69,7 +70,7 @@ test_expect_success 'ISO-8859-1 should match UTF-8 in svn' '
 
 for H in EUCJP ISO-2022-JP
 do
-	test_expect_success '$H should match UTF-8 in svn' '
+	test_expect_failure '$H should match UTF-8 in svn' '
 	(
 		cd $H &&
 		compare_svn_head_with "$TEST_DIRECTORY"/t3900/2-UTF-8.txt
-- 
1.6.1.rc1.53.g455b
Junio C Hamano· Dec 6, 2008, 02:05 UTC · re: applehq · lore

Re: [PATCH] t9129: Prevent test failure if no UTF-8 locale

applehq <theappleman@gmail.com> writes:
> Commit 16fc08e2d86dad152194829d21bc55b2ef0c8fb1 introduced a
> test that failed if the en_US.UTF-8 locale was not installed.
>
> Make the test find a UTF-8 locale, and expect failure.
NAK on the latter one.

test_expect_failure does not mean "This might, and it is Ok to, fail", as you seem to think. It means "This should succeed if our software is not buggy, but there is a known breakage to cause it to fail, so this test is marked as such until the bug is fixed."

Skipping the test on a platform that lacks necessary locale is fine, but if you run the test, they should expect success. Otherwise you cannot tell if it is a platform issue (i.e. not having any UTF-8 locale) or a bug in the software (i.e. git-svn not working as expected).

> Signed-off-by: applehq <theappleman@gmail.com>
Sign off with an unreal name, hmm..., what good would that give us...?
Show 9 quoted lines
> @@ -15,8 +15,9 @@ compare_git_head_with () {
>  }
>  
>  compare_svn_head_with () {
> -	LC_ALL=en_US.UTF-8 svn log --limit 1 `git svn info --url` | \
> -		sed -e 1,3d -e "/^-\{1,\}\$/d" >current &&
> +	LC_ALL=`locale -a | grep -i utf | head -1` \
> +		svn log --limit 1 `git svn info --url` | \
> +			sed -e 1,3d -e "/^-\{1,\}\$/d" >current &&

I think what this part tries to do is good, in that we do not care if it is en_US UTF-8 or any other UTF-8. But cramming that logic all in one pipeline (and an inefficient one at that) makes it harder to read.

Do something like this upfront:
	a_utf8_locale=$(locale -a | sed -ne '/[Uu][Tt][Ff]-*8/{
        	p
                q
	'})

and if that variable is empty then skip the test that relies on having a UTF-8 locale on the platform. Then the function can say:

	LC_ALL="$a_utf8_locale" svn log --limit 1 ...

← back to recent threads