From: Bruno Haible Date: Tue, 1 Apr 2025 15:20:31 +0000 (+0200) Subject: D support: Add a unit test. X-Git-Tag: v0.25~69 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=0f1ebb78713c50f55f6e5f436d75ba4be9791d87;p=thirdparty%2Fgettext.git D support: Add a unit test. * autogen.sh (GNULIB_MODULES_TOOLS_OTHER): Add d, dcomp-script. * gettext-tools/configure.ac: Set and substitute BUILDD. * gettext-tools/tests/init-env.in: Propagate D_CHOICE, BUILDD. * gettext-tools/tests/lang-d: New file. * gettext-tools/tests/Makefile.am (TESTS): Add it. --- diff --git a/.gitignore b/.gitignore index f509eea6f..6db330f67 100644 --- a/.gitignore +++ b/.gitignore @@ -655,6 +655,7 @@ autom4te.cache/ /gettext-tools/config.h /gettext-tools/csharpcomp.sh /gettext-tools/csharpexec.sh +/gettext-tools/dcomp.sh /gettext-tools/gocomp.sh /gettext-tools/javacomp.sh /gettext-tools/javaexec.sh diff --git a/autogen.sh b/autogen.sh index a77372f48..b875ce1e5 100755 --- a/autogen.sh +++ b/autogen.sh @@ -340,6 +340,8 @@ if ! $skip_gnulib; then ansi-c++-opt csharpcomp-script csharpexec-script + d + dcomp-script java javacomp-script javaexec-script diff --git a/gettext-tools/configure.ac b/gettext-tools/configure.ac index a7c51d40f..09f22c4b4 100644 --- a/gettext-tools/configure.ac +++ b/gettext-tools/configure.ac @@ -102,6 +102,20 @@ else fi AC_SUBST([TESTCSHARP]) +gt_D_CHOICE +gt_DCOMP +if test "$D_CHOICE" != no; then + AC_CHECK_TOOL([DC], [gdc ldc2 dmd]) + if test -n "$DC"; then + BUILDD=yes + else + BUILDD=no + fi +else + BUILDD=no +fi +AC_SUBST([BUILDD]) + dnl Check for host type. AC_CANONICAL_HOST diff --git a/gettext-tools/tests/Makefile.am b/gettext-tools/tests/Makefile.am index 543eadde9..8e80f9d02 100644 --- a/gettext-tools/tests/Makefile.am +++ b/gettext-tools/tests/Makefile.am @@ -242,6 +242,7 @@ TESTS = gettext-1 gettext-2 \ lang-gawk \ lang-lua \ lang-pascal \ + lang-d \ lang-smalltalk \ lang-vala \ lang-tcl \ diff --git a/gettext-tools/tests/init-env.in b/gettext-tools/tests/init-env.in index 817dfe059..f3db86378 100644 --- a/gettext-tools/tests/init-env.in +++ b/gettext-tools/tests/init-env.in @@ -20,6 +20,8 @@ BUILDCSHARP="@BUILDCSHARP@" TESTCSHARP="@TESTCSHARP@" GO_CHOICE="@GO_CHOICE@" GO="@GO@" +D_CHOICE="@D_CHOICE@" +BUILDD="@BUILDD@" TESTLIBASPRINTF="@TESTLIBASPRINTF@" GLIBC2="@GLIBC2@" LOCALE_FR="@LOCALE_FR@" diff --git a/gettext-tools/tests/lang-d b/gettext-tools/tests/lang-d new file mode 100644 index 000000000..59279d85d --- /dev/null +++ b/gettext-tools/tests/lang-d @@ -0,0 +1,180 @@ +#! /bin/sh +. "${srcdir=.}/init.sh"; path_prepend_ . ../src + +# Test of gettext facilities in the D language. +# Assumes an fr_FR locale is installed. +# Assumes the following packages are installed: gdc or ldc or dmd. + +# Test whether we can build and test D programs. +test "${D_CHOICE}" != no || { + echo "Skipping test: configured with --disable-d" + Exit 77 +} +test "${BUILDD}" = yes || { + echo "Skipping test: D compiler not found" + Exit 77 +} + +cat <<\EOF > prog.d +// Get writeln. +import std.stdio; +// Get format. +import std.format; +// Get to, text. +import std.conv; +// Get locale constants. +import core.stdc.locale : LC_ALL; +// Get exit. +import core.stdc.stdlib : exit; +// Get textdomain, bindtextdomain, gettext, ngettext, setlocale. +import gnu.libintl : textdomain, bindtextdomain, gettext, ngettext, setlocale; + +// Define _() as a shorthand for gettext(). +alias _ = gettext; + +void main (string[] args) +{ + int n = to!int (args[1]); + + if (!setlocale (LC_ALL, "")) + /* Couldn't set locale. */ + exit (77); + + textdomain ("prog"); + bindtextdomain ("prog", "."); + + // Any of these three is valid syntax. + // Cf. https://dlang.org/spec/function.html#pseudo-member + //writeln (_("'Your command, please?', asked the waiter.")); + //"'Your command, please?', asked the waiter.".gettext().writeln; + "'Your command, please?', asked the waiter.".gettext.writeln; + + writeln (format (ngettext ("%.0sa piece of cake", "%s pieces of cake", n), text(n))); + writeln (format (_ ("%s is replaced by %s."), "FF", "EUR")); +} +EOF + +: ${XGETTEXT=xgettext} +${XGETTEXT} -o prog.tmp --omit-header --no-location \ + -k_ --flag=_:1:pass-c-format --flag=_:1:pass-d-format \ + prog.d \ + || Exit 1 +LC_ALL=C tr -d '\r' < prog.tmp > prog.pot || Exit 1 + +cat <<\EOF > prog.ok +msgid "'Your command, please?', asked the waiter." +msgstr "" + +#, d-format +msgid "%.0sa piece of cake" +msgid_plural "%s pieces of cake" +msgstr[0] "" +msgstr[1] "" + +#, d-format +msgid "%s is replaced by %s." +msgstr "" +EOF + +: ${DIFF=diff} +${DIFF} prog.ok prog.pot || Exit 1 + +cat <<\EOF > fr.po +msgid "" +msgstr "" +"Content-Type: text/plain; charset=ISO-8859-1\n" +"Plural-Forms: nplurals=2; plural=(n > 1);\n" + +msgid "'Your command, please?', asked the waiter." +msgstr "«Votre commande, s'il vous plait», dit le garçon." + +# Les gateaux allemands sont les meilleurs du monde. +#, d-format +msgid "%.0sa piece of cake" +msgid_plural "%s pieces of cake" +msgstr[0] "%.0sun morceau de gateau" +msgstr[1] "%s morceaux de gateau" + +# Reverse the arguments. +#, d-format +msgid "%s is replaced by %s." +msgstr "%2$s remplace %1$s." +EOF + +: ${MSGMERGE=msgmerge} +${MSGMERGE} -q -o fr.po.tmp fr.po prog.pot || Exit 1 +LC_ALL=C tr -d '\r' < fr.po.tmp > fr.po.new || Exit 1 + +: ${DIFF=diff} +${DIFF} fr.po fr.po.new || Exit 1 + +test -d fr || mkdir fr +test -d fr/LC_MESSAGES || mkdir fr/LC_MESSAGES + +: ${MSGFMT=msgfmt} +${MSGFMT} -o fr/LC_MESSAGES/prog.mo fr.po + +${SHELL-/bin/sh} "$top_builddir"/dcomp.sh \ + -I"$abs_top_srcdir"/../gettext-runtime/intl-d \ + -c prog.d \ + || Exit 1 + +: ${CONFIG_SHELL=${SHELL-/bin/sh}} +${CONFIG_SHELL} "$top_builddir"/libtool --quiet --tag=CC --mode=link \ + ${SHELL-/bin/sh} "$top_builddir"/dcomp.sh \ + -o prog \ + prog.${OBJEXT} \ + "$top_builddir"/../gettext-runtime/intl-d/libintl_d.a \ + ${LTLIBINTL} \ + || Exit 1 + +: ${DIFF=diff} +cat <<\EOF > prog.ok +«Votre commande, s'il vous plait», dit le garçon. +2 morceaux de gateau +EUR remplace FF. +EOF +cat <<\EOF > prog.oku +«Votre commande, s'il vous plait», dit le garçon. +2 morceaux de gateau +EUR remplace FF. +EOF + +: ${LOCALE_FR=fr_FR} +: ${LOCALE_FR_UTF8=fr_FR.UTF-8} +if test $LOCALE_FR != none; then + prepare_locale_ fr $LOCALE_FR + LC_ALL=$LOCALE_FR LANGUAGE= ./prog 2 > prog.tmp + case $? in + 0) case "$host_os" in + mingw*) LC_ALL=C tr -d '\r' < prog.tmp > prog.out || Exit 1 ;; + *) cp prog.tmp prog.out || Exit 1 ;; + esac + ${DIFF} prog.ok prog.out || Exit 1;; + 77) LOCALE_FR=none;; + *) Exit 1;; + esac +fi +if test $LOCALE_FR_UTF8 != none; then + prepare_locale_ fr $LOCALE_FR_UTF8 + LC_ALL=$LOCALE_FR_UTF8 LANGUAGE= ./prog 2 > prog.tmp + case $? in + 0) case "$host_os" in + mingw*) LC_ALL=C tr -d '\r' < prog.tmp > prog.out || Exit 1 ;; + *) cp prog.tmp prog.out || Exit 1 ;; + esac + ${DIFF} prog.oku prog.out || Exit 1;; + 77) LOCALE_FR_UTF8=none;; + *) Exit 1;; + esac +fi +if test $LOCALE_FR = none && test $LOCALE_FR_UTF8 = none; then + if test -f /usr/bin/localedef; then + echo "Skipping test: no french locale is installed" + else + echo "Skipping test: no french locale is supported" + fi + Exit 77 +fi + +Exit 0