# HG changeset patch # User Bruno Haible # Date 1232936566 -3600 # Node ID fc5faccd30e758afb3bbf5102db39a2b5bb7726d # Parent baa54e3c744fe7b7eb5ba502e2a4c2517ebcef6b Make test-quotearg work on MacOS X and AIX. diff --git a/ChangeLog b/ChangeLog --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,21 @@ +2009-01-25 Bruno Haible + + Make test-quotearg work on MacOS X and AIX. + * tests/test-quotearg.sh: New file. + * tests/locale/fr/LC_MESSAGES/test-quotearg.po: New file. + * tests/locale/fr/LC_MESSAGES/test-quotearg.mo: New file. + * tests/test-quotearg.c: Include and gettext.h. Don't + include . + (fake_locale): Remove variable. + (gettext, dgettext, dcgettext): Remove functions. + (main): Instead of setting a fake locale, set a real locale. Call + textdomain and bindtextdomain. + * modules/quotearg-tests (Files): Add the new files. + (Depends-on): Add gettext, setenv, unsetenv. + (configure.ac): Invoke gt_LOCALE_FR and gt_LOCALE_FR_UTF8. + (Makefile.am): Add test-quotearg.sh to TESTS, remove test-quotearg. + Augment TESTS_ENVIRONMENT. + 2009-01-25 Bruno Haible * m4/locale-fr.m4 (gt_LOCALE_FR): Remove special code that hid the diff --git a/modules/quotearg-tests b/modules/quotearg-tests --- a/modules/quotearg-tests +++ b/modules/quotearg-tests @@ -1,13 +1,24 @@ Files: +tests/test-quotearg.sh tests/test-quotearg.c +tests/locale/fr/LC_MESSAGES/test-quotearg.po +tests/locale/fr/LC_MESSAGES/test-quotearg.mo +m4/locale-fr.m4 +m4/codeset.m4 Depends-on: +gettext progname stdint +setenv +unsetenv configure.ac: +gt_LOCALE_FR +gt_LOCALE_FR_UTF8 Makefile.am: -TESTS += test-quotearg +TESTS += test-quotearg.sh +TESTS_ENVIRONMENT += EXEEXT='@EXEEXT@' srcdir='$(srcdir)' LOCALE_FR='@LOCALE_FR@' LOCALE_FR_UTF8='@LOCALE_FR_UTF8@' check_PROGRAMS += test-quotearg test_quotearg_LDADD = $(LDADD) @LIBINTL@ diff --git a/tests/locale/fr/LC_MESSAGES/test-quotearg.mo b/tests/locale/fr/LC_MESSAGES/test-quotearg.mo new file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..87e97e1e1f043b3af31ec13f49e9bda812b124e3 GIT binary patch literal 90 zc$~W@#4?ou2$+Ca28eZlm=%a^fS3`81E6#eR80t!4rhP>CI$omsZ(c2U^uj!;m~RZ E0Q`~$+yDRo diff --git a/tests/locale/fr/LC_MESSAGES/test-quotearg.po b/tests/locale/fr/LC_MESSAGES/test-quotearg.po new file mode 100644 --- /dev/null +++ b/tests/locale/fr/LC_MESSAGES/test-quotearg.po @@ -0,0 +1,20 @@ +# Message catalog that maps the ASCII replacements for single-quote characters +# to real single-quote characters. +# The header entry is commented out on purpose, so that gettext() performs no +# no character set conversion from the PO file's encoding to the locale +# encoding. This allows us to use the same PO file in various locales. +#msgid "" +#msgstr "" +#"Project-Id-Version: GNU gnulib\n" +#"PO-Revision-Date: 2009-01-26 01:02+01:00\n" +#"Last-Translator: Eric Blake \n" +#"Language-Team: Undetermined \n" +#"MIME-Version: 1.0\n" +#"Content-Type: text/plain; charset=UTF-8\n" +#"Content-Transfer-Encoding: 8bit\n" + +msgid "`" +msgstr "\302\253" + +msgid "'" +msgstr "\302\273" diff --git a/tests/test-quotearg.c b/tests/test-quotearg.c --- a/tests/test-quotearg.c +++ b/tests/test-quotearg.c @@ -22,6 +22,7 @@ #include "quotearg.h" #include +#include #include #include #include @@ -29,20 +30,7 @@ #include #include "progname.h" - -#if ENABLE_NLS -/* On Linux, gettext is optionally defined as a forwarding macro, - which would cause syntax errors in our definition below. But on - platforms that require -lintl, we cannot #undef gettext, since we - want to provide the entry point libintl_gettext. So we disable - optimizations to avoid the Linux macros. */ -# undef __OPTIMIZE__ -# include - -/* These quotes are borrowed from a pt_PT.utf8 translation. */ -# define LQ "\302\253" -# define RQ "\302\273" -#endif +#include "gettext.h" #define ASSERT(expr) \ do \ @@ -163,6 +151,11 @@ }; #if ENABLE_NLS + +/* These quotes are borrowed from a pt_PT.utf8 translation. */ +# define LQ "\302\253" +# define RQ "\302\273" + static struct result_groups locale_results[] = { /* locale_quoting_style */ { { LQ RQ, LQ "\\0001\\0" RQ, 11, LQ "simple" RQ, @@ -180,6 +173,7 @@ { LQ RQ, LQ "\\0001\\0" RQ, 11, LQ "simple" RQ, LQ " \\t\\n'\"\\033?""?/\\\\" RQ, LQ "a\\:b" RQ, LQ "a\\\\b" RQ } } }; + #endif /* ENABLE_NLS */ static void @@ -251,40 +245,6 @@ return p; } -#if ENABLE_NLS -/* True if the locale should be faked. */ -static bool fake_locale; - -/* A replacement gettext that allows testing of locale quotes without - requiring a locale. */ -char * -gettext (char const *str) -{ - if (fake_locale) - { - static char lq[] = LQ; - static char rq[] = RQ; - if (strcmp (str, "`") == 0) - return lq; - if (strcmp (str, "'") == 0) - return rq; - } - return (char *) str; -} - -char * -dgettext (char const *d, char const *str) -{ - return gettext (str); -} - -char * -dcgettext (char const *d, char const *str, int c) -{ - return gettext (str); -} -#endif /* ENABLE_NLS */ - int main (int argc, char *argv[]) { @@ -292,7 +252,7 @@ set_program_name (argv[0]); - /* This program is hard-wired to the C locale since it does not call + /* This program part is hard-wired to the C locale since it does not call setlocale. */ ASSERT (!isprint ('\033')); for (i = literal_quoting_style; i <= clocale_quoting_style; i++) @@ -325,21 +285,37 @@ ASSERT (set_quoting_flags (NULL, 0) == QA_SPLIT_TRIGRAPHS); #if ENABLE_NLS - /* Rather than change locales, and require a .gmo file with - translations for "`" and "'" that match our expectations, we - merely override the gettext function to satisfy the link - dependencies of quotearg.c. */ - fake_locale = true; + /* Clean up environment. */ + unsetenv ("LANGUAGE"); + unsetenv ("LC_ALL"); + unsetenv ("LC_MESSAGES"); + unsetenv ("LC_CTYPE"); + unsetenv ("LANG"); + unsetenv ("OUTPUT_CHARSET"); + + /* This program part runs in a French UTF-8 locale. It uses + the test-quotearg.mo message catalog. */ + { + const char *locale_name = getenv ("LOCALE"); - set_quoting_style (NULL, locale_quoting_style); - compare_strings (use_quotearg_buffer, &locale_results[0].group1); - compare_strings (use_quotearg, &locale_results[0].group2); - compare_strings (use_quotearg_colon, &locale_results[0].group3); + if (locale_name != NULL && strcmp (locale_name, "none") != 0 + && setenv ("LC_ALL", locale_name, 1) == 0 + && setlocale (LC_ALL, "") != NULL) + { + textdomain ("test-quotearg"); + bindtextdomain ("test-quotearg", getenv ("LOCALEDIR")); - set_quoting_style (NULL, clocale_quoting_style); - compare_strings (use_quotearg_buffer, &locale_results[1].group1); - compare_strings (use_quotearg, &locale_results[1].group2); - compare_strings (use_quotearg_colon, &locale_results[1].group3); + set_quoting_style (NULL, locale_quoting_style); + compare_strings (use_quotearg_buffer, &locale_results[0].group1); + compare_strings (use_quotearg, &locale_results[0].group2); + compare_strings (use_quotearg_colon, &locale_results[0].group3); + + set_quoting_style (NULL, clocale_quoting_style); + compare_strings (use_quotearg_buffer, &locale_results[1].group1); + compare_strings (use_quotearg, &locale_results[1].group2); + compare_strings (use_quotearg_colon, &locale_results[1].group3); + } + } #endif /* ENABLE_NLS */ quotearg_free (); diff --git a/tests/test-quotearg.sh b/tests/test-quotearg.sh new file mode 100755 --- /dev/null +++ b/tests/test-quotearg.sh @@ -0,0 +1,16 @@ +#!/bin/sh + +# Choose an existing locale. The locale encoding does not matter; see the +# comment in test-quotearg.po. +if test $LOCALE_FR_UTF8 != none; then + locale=$LOCALE_FR_UTF8 +else + if test $LOCALE_FR != none; then + locale=$LOCALE_FR + else + locale=none + fi +fi + +LOCALE=$locale LOCALEDIR="$srcdir/locale" \ +./test-quotearg${EXEEXT}