]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
Modula-2 support: Add a unit test.
authorBruno Haible <bruno@clisp.org>
Fri, 25 Apr 2025 01:18:15 +0000 (03:18 +0200)
committerBruno Haible <bruno@clisp.org>
Fri, 25 Apr 2025 01:20:42 +0000 (03:20 +0200)
* autogen.sh (GNULIB_MODULES_TOOLS_OTHER): Add modula2, modula2comp-script.
* gettext-tools/configure.ac: Set and substitute BUILDMODULA2.
* gettext-tools/tests/init-env.in: Propagate MODULA2_CHOICE, BUILDMODULA2, M2C,
M2FLAGS.
* gettext-tools/tests/lang-modula2: New file.
* gettext-tools/tests/Makefile.am (TESTS): Add it.

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

index 7355f59e9db9b3123ad42d6dfd2d70fdb064006a..469341f260d89012627e61fbc2cb8b8da903ea35 100755 (executable)
@@ -348,6 +348,8 @@ if ! $skip_gnulib; then
     javacomp-script
     javaexec-script
     manywarnings
+    modula2
+    modula2comp-script
     stdint-h
     test-xfail
   '
index 985561172f5d4d25fb76ee757aa6de839de9a5d9..e930335b1181377918e829633f13e13ec52c9677 100644 (file)
@@ -428,6 +428,19 @@ AH_BOTTOM([
 dnl Check for nm output filter that yields the exported symbols.
 gt_GLOBAL_SYMBOL_PIPE
 
+gt_MODULA2_CHOICE
+if test "$MODULA2_CHOICE" != no; then
+  gt_MODULA2COMP
+  if test -n "$M2C"; then
+    BUILDMODULA2=yes
+  else
+    BUILDMODULA2=no
+  fi
+else
+  BUILDMODULA2=no
+fi
+AC_SUBST([BUILDMODULA2])
+
 dnl Check for Emacs and where to install .elc files.
 dnl Sometimes Emacs is badly installed. Allow the user to work around it.
 AC_ARG_WITH([emacs],
index c52d478ed5511a6277e94de078791c901ea6bfe9..95ed2537fef2de3b7eaf616faf3e2cb15c1929c7 100644 (file)
@@ -244,6 +244,7 @@ TESTS = gettext-1 gettext-2 \
        lang-gawk \
        lang-lua \
        lang-pascal \
+       lang-modula2 \
        lang-d \
        lang-smalltalk \
        lang-vala \
index f3db86378ee2994c66b84afd55c27396fb50da6a..f8e8e886e285feb054ee50f7cdf0f6fa2d70a3aa 100644 (file)
@@ -22,6 +22,10 @@ GO_CHOICE="@GO_CHOICE@"
 GO="@GO@"
 D_CHOICE="@D_CHOICE@"
 BUILDD="@BUILDD@"
+MODULA2_CHOICE="@MODULA2_CHOICE@"
+BUILDMODULA2="@BUILDMODULA2@"
+M2C="@M2C@"
+M2FLAGS="@M2FLAGS@"
 TESTLIBASPRINTF="@TESTLIBASPRINTF@"
 GLIBC2="@GLIBC2@"
 LOCALE_FR="@LOCALE_FR@"
diff --git a/gettext-tools/tests/lang-modula2 b/gettext-tools/tests/lang-modula2
new file mode 100644 (file)
index 0000000..13d4c93
--- /dev/null
@@ -0,0 +1,172 @@
+#! /bin/sh
+. "${srcdir=.}/init.sh"; path_prepend_ . ../src
+
+# Test of gettext facilities in the Modula-2 language.
+# Assumes an fr_FR locale is installed.
+# Assumes the following packages are installed: gm2.
+
+# Test whether we can build and test Modula-2 programs.
+test "${MODULA2_CHOICE}" != no || {
+  echo "Skipping test: configured with --disable-modula2"
+  Exit 77
+}
+test "${BUILDMODULA2}" = yes || {
+  echo "Skipping test: Modula-2 compiler not found"
+  Exit 77
+}
+
+cat <<\EOF > prog.mod
+MODULE Prog;
+
+FROM Args IMPORT GetArg;
+FROM NumberIO IMPORT StrToCard;
+FROM Terminal IMPORT Write, WriteLn;
+FROM Libintl IMPORT SetLocale, LC_ALL, TextDomain, BindTextDomain, Gettext, NGettext;
+FROM DynamicStrings IMPORT String, Length, char;
+FROM FormatStrings IMPORT Sprintf1;
+
+(* Like Terminal.WriteString, except that it takes a String, not an ARRAY OF CHAR. *)
+PROCEDURE WriteString (s: String);
+VAR
+  l, i: CARDINAL;
+BEGIN
+  l := Length(s);
+  i := 0;
+  WHILE i < l DO
+    Write(char(s, i));
+    INC (i);
+  END;
+END WriteString;
+
+VAR
+  argument: ARRAY[0..1000] OF CHAR;
+  n: CARDINAL;
+
+BEGIN
+  SetLocale(LC_ALL, "");
+  TextDomain("prog");
+  BindTextDomain("prog", ".");
+
+  IF NOT GetArg(argument, 1) THEN HALT(1); END;
+  StrToCard(argument, n);
+
+  WriteString(Gettext("'Your command, please?', asked the waiter."));
+  WriteLn;
+
+  (* Put a space before %u, as a workaround against GCC bug
+     <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119915>. *)
+  WriteString(Sprintf1(NGettext("a piece of cake", " %u pieces of cake", n), n));
+  WriteLn;
+
+END Prog.
+EOF
+
+: ${XGETTEXT=xgettext}
+${XGETTEXT} -o prog.tmp --omit-header --no-location prog.mod \
+  || 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 ""
+
+#, modula2-format
+msgid "a piece of cake"
+msgid_plural " %u pieces of cake"
+msgstr[0] ""
+msgstr[1] ""
+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.
+#, modula2-format
+msgid "a piece of cake"
+msgid_plural " %u pieces of cake"
+msgstr[0] "un morceau de gateau"
+msgstr[1] " %u morceaux de gateau"
+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
+
+${M2C} ${M2FLAGS} -I"$abs_top_srcdir"/../gettext-runtime/intl-modula2 \
+       -c -fscaffold-main prog.mod \
+  || Exit 1
+
+: ${CONFIG_SHELL=${SHELL-/bin/sh}}
+${CONFIG_SHELL} "$top_builddir"/libtool --quiet --tag=CC --mode=link \
+  ${M2C} ${M2FLAGS} -o prog \
+                    prog.${OBJEXT} \
+                    "$top_builddir"/../gettext-runtime/intl-modula2/libintl_m2.la \
+                    ${LTLIBINTL} \
+  || Exit 1
+
+: ${DIFF=diff}
+cat <<\EOF > prog.ok
+«Votre commande, s'il vous plait», dit le garçon.
+ 2 morceaux de gateau
+EOF
+cat <<\EOF > prog.oku
+«Votre commande, s'il vous plait», dit le garçon.
+ 2 morceaux de gateau
+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