]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
D support: Add a unit test.
authorBruno Haible <bruno@clisp.org>
Tue, 1 Apr 2025 15:20:31 +0000 (17:20 +0200)
committerBruno Haible <bruno@clisp.org>
Tue, 1 Apr 2025 15:34:58 +0000 (17:34 +0200)
* 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.

.gitignore
autogen.sh
gettext-tools/configure.ac
gettext-tools/tests/Makefile.am
gettext-tools/tests/init-env.in
gettext-tools/tests/lang-d [new file with mode: 0644]

index f509eea6f5144169a3eedfe9eba8bf90547f03af..6db330f677af86dd1bc96d2c6fbdd1bae7361077 100644 (file)
@@ -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
index a77372f48962eea1731ac49e0c76d14d69ef8a63..b875ce1e5e7c66fa2d6021ce97b4f3aa119685fd 100755 (executable)
@@ -340,6 +340,8 @@ if ! $skip_gnulib; then
     ansi-c++-opt
     csharpcomp-script
     csharpexec-script
+    d
+    dcomp-script
     java
     javacomp-script
     javaexec-script
index a7c51d40f6d6486f4fe269947c23e6839118522c..09f22c4b42733b700a1464ac99d0ef49aa045c8d 100644 (file)
@@ -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
 
index 543eadde926f60cc108498760939703132118504..8e80f9d02cbc4a2635f820fe1fdd78ce4ece433b 100644 (file)
@@ -242,6 +242,7 @@ TESTS = gettext-1 gettext-2 \
        lang-gawk \
        lang-lua \
        lang-pascal \
+       lang-d \
        lang-smalltalk \
        lang-vala \
        lang-tcl \
index 817dfe05913936c06fd69f09eb6102279cd077a2..f3db86378ee2994c66b84afd55c27396fb50da6a 100644 (file)
@@ -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 (file)
index 0000000..59279d8
--- /dev/null
@@ -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