Skip to contentSkip to conversation

t0200: "locale" may not exist

PATCH In review Junio C Hamano 2 participants 4 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 t0200: "locale" may not exist

On systems without "locale" installed, t0200-gettext-basic.sh leaked error messages when checking if some test locales are available. Hide them, as they are not very useful.

---
 t/lib-gettext.sh | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
t/lib-gettext.sh +4 -2
index 0f76f6c..ae8883a 100644
@@ -14,12 +14,14 @@ export GIT_TEXTDOMAINDIR GIT_PO_PATH
 if test_have_prereq GETTEXT && ! test_have_prereq GETTEXT_POISON
 then
 	# is_IS.UTF-8 on Solaris and FreeBSD, is_IS.utf8 on Debian
-	is_IS_locale=$(locale -a | sed -n '/^is_IS\.[uU][tT][fF]-*8$/{
+	is_IS_locale=$(locale -a 2>/dev/null |
+		sed -n '/^is_IS\.[uU][tT][fF]-*8$/{
 		p
 		q
 	}')
 	# is_IS.ISO8859-1 on Solaris and FreeBSD, is_IS.iso88591 on Debian
-	is_IS_iso_locale=$(locale -a | sed -n '/^is_IS\.[iI][sS][oO]8859-*1$/{
+	is_IS_iso_locale=$(locale -a 2>/dev/null |
+		sed -n '/^is_IS\.[iI][sS][oO]8859-*1$/{
 		p
 		q
 	}')
Signature · 1 line
1.8.1.rc2.196.g654d69e
#1 lore raw
Quoted 3 lines · Junio C Hamano

On systems without "locale" installed, t0200-gettext-basic.sh leaked error messages when checking if some test locales are available. Hide them, as they are not very useful.

Obviously correct, though there is another way:

t/lib-gettext.sh export GIT_TEXTDOMAINDIR GIT_PO_PATH · line 14

Quoted 6 lines
t/lib-gettext.sh +0 -0
index 0f76f6c..ae8883a 100644
@@ -14,12 +14,14 @@ export GIT_TEXTDOMAINDIR GIT_PO_PATH
 if test_have_prereq GETTEXT && ! test_have_prereq GETTEXT_POISON

If we turn this line into:

test_expect_success GETTEXT,!GETTEXT_POISON 'setup locale' '

then people can see the error output of the setup step in verbose mode.

Annoyingly, though, it means tweaking the quoting throughout the block to handle embedded single-quotes (if there is one feature I could take from perl back into shell, it would be arbitrary quote delimiters).

Patch is below. I don't know if it is worth the complexity.

-Peff

t/lib-gettext.sh +8 -9
index 0f76f6c..d962c00 100644
@@ -11,18 +11,17 @@ then
 
 . "$GIT_BUILD_DIR"/git-sh-i18n
 
-if test_have_prereq GETTEXT && ! test_have_prereq GETTEXT_POISON
-then
+test_expect_success GETTEXT,!GETTEXT_POISON 'setup locale' '
 	# is_IS.UTF-8 on Solaris and FreeBSD, is_IS.utf8 on Debian
-	is_IS_locale=$(locale -a | sed -n '/^is_IS\.[uU][tT][fF]-*8$/{
+	is_IS_locale=$(locale -a | sed -n "/^is_IS\.[uU][tT][fF]-*8\$/{
 		p
 		q
-	}')
+	}")
 	# is_IS.ISO8859-1 on Solaris and FreeBSD, is_IS.iso88591 on Debian
-	is_IS_iso_locale=$(locale -a | sed -n '/^is_IS\.[iI][sS][oO]8859-*1$/{
+	is_IS_iso_locale=$(locale -a | sed -n "/^is_IS\.[iI][sS][oO]8859-*1\$/{
 		p
 		q
-	}')
+	}")
 
 	# Export them as an environment variable so the t0202/test.pl Perl
 	# test can use it too
@@ -37,7 +36,7 @@ then
 		# Exporting for t0202/test.pl
 		GETTEXT_LOCALE=1
 		export GETTEXT_LOCALE
-		say "# lib-gettext: Found '$is_IS_locale' as an is_IS UTF-8 locale"
+		say "# lib-gettext: Found \"$is_IS_locale\" as an is_IS UTF-8 locale"
 	else
 		say "# lib-gettext: No is_IS UTF-8 locale available"
 	fi
@@ -48,8 +47,8 @@ then
 		# Some of the tests need the reference Icelandic locale
 		test_set_prereq GETTEXT_ISO_LOCALE
 
-		say "# lib-gettext: Found '$is_IS_iso_locale' as an is_IS ISO-8859-1 locale"
+		say "# lib-gettext: Found \"$is_IS_iso_locale\" as an is_IS ISO-8859-1 locale"
 	else
 		say "# lib-gettext: No is_IS ISO-8859-1 locale available"
 	fi
-fi
+'
#2 lore raw
Quoted 17 lines · Jeff King
Quoted 3 lines · Junio C Hamano

On systems without "locale" installed, t0200-gettext-basic.sh leaked error messages when checking if some test locales are available. Hide them, as they are not very useful.

Obviously correct, though there is another way:

t/lib-gettext.sh export GIT_TEXTDOMAINDIR GIT_PO_PATH · line 14

Quoted 6 lines
t/lib-gettext.sh +0 -0
index 0f76f6c..ae8883a 100644
@@ -14,12 +14,14 @@ export GIT_TEXTDOMAINDIR GIT_PO_PATH
 if test_have_prereq GETTEXT && ! test_have_prereq GETTEXT_POISON

If we turn this line into:

Quoted 3 lines

test_expect_success GETTEXT,!GETTEXT_POISON 'setup locale' '

then people can see the error output of the setup step in verbose mode.

Ok, so it was not obviously "correct" after all ;-)

t/lib-gettext.sh then · line 16

Quoted 4 lines
t/lib-gettext.sh +2 -1
+test_expect_success GETTEXT,!GETTEXT_POISON 'setup locale' '
 	# is_IS.UTF-8 on Solaris and FreeBSD, is_IS.utf8 on Debian
-	is_IS_locale=$(locale -a | sed -n '/^is_IS\.[uU][tT][fF]-*8$/{
+	is_IS_locale=$(locale -a | sed -n "/^is_IS\.[uU][tT][fF]-*8\$/{

Do we need to do this \$?

Quoted 15 lines
t/lib-gettext.sh +3 -3
 		p
 		q
-	}')
+	}")
 	# is_IS.ISO8859-1 on Solaris and FreeBSD, is_IS.iso88591 on Debian
-	is_IS_iso_locale=$(locale -a | sed -n '/^is_IS\.[iI][sS][oO]8859-*1$/{
+	is_IS_iso_locale=$(locale -a | sed -n "/^is_IS\.[iI][sS][oO]8859-*1\$/{
 		p
 		q
-	}')
+	}")
 
 	# Export them as an environment variable so the t0202/test.pl Perl
 	# test can use it too

t/lib-gettext.sh then · line 39

Quoted 5 lines
t/lib-gettext.sh +1 -1
@@ -37,7 +36,7 @@ then
 		# Exporting for t0202/test.pl
 		GETTEXT_LOCALE=1
 		export GETTEXT_LOCALE
-		say "# lib-gettext: Found '$is_IS_locale' as an is_IS UTF-8 locale"
+		say "# lib-gettext: Found \"$is_IS_locale\" as an is_IS UTF-8 locale"

'\''?

#3 lore raw
Quoted 6 lines · Junio C Hamano

t/lib-gettext.sh then · line 16

Quoted 4 lines
t/lib-gettext.sh +2 -1
+test_expect_success GETTEXT,!GETTEXT_POISON 'setup locale' '
 	# is_IS.UTF-8 on Solaris and FreeBSD, is_IS.utf8 on Debian
-	is_IS_locale=$(locale -a | sed -n '/^is_IS\.[uU][tT][fF]-*8$/{
+	is_IS_locale=$(locale -a | sed -n "/^is_IS\.[uU][tT][fF]-*8\$/{

Do we need to do this \$?

I'm not sure. Sane shells leave "$/" untouched, but I do not know if we need to be conservative.

Quoted 4 lines

t/lib-gettext.sh then · line 39

Quoted 2 lines
t/lib-gettext.sh +1 -1
-		say "# lib-gettext: Found '$is_IS_locale' as an is_IS UTF-8 locale"
+		say "# lib-gettext: Found \"$is_IS_locale\" as an is_IS UTF-8 locale"

'\''?

Fine by me. I do not care either way in the output, and the escaped dq is marginally more readable in the source. But either way the source is pretty ugly. :)

-Peff