From: Bruno Haible Date: Fri, 25 Apr 2025 01:18:15 +0000 (+0200) Subject: Modula-2 support: Add a unit test. X-Git-Tag: v0.25~45 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=281658406b9d59e0dbdbafbc7ee1b4b047fab175;p=thirdparty%2Fgettext.git Modula-2 support: Add a unit test. * 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. --- diff --git a/autogen.sh b/autogen.sh index 7355f59e9..469341f26 100755 --- a/autogen.sh +++ b/autogen.sh @@ -348,6 +348,8 @@ if ! $skip_gnulib; then javacomp-script javaexec-script manywarnings + modula2 + modula2comp-script stdint-h test-xfail ' diff --git a/gettext-tools/configure.ac b/gettext-tools/configure.ac index 985561172..e930335b1 100644 --- a/gettext-tools/configure.ac +++ b/gettext-tools/configure.ac @@ -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], diff --git a/gettext-tools/tests/Makefile.am b/gettext-tools/tests/Makefile.am index c52d478ed..95ed2537f 100644 --- a/gettext-tools/tests/Makefile.am +++ b/gettext-tools/tests/Makefile.am @@ -244,6 +244,7 @@ TESTS = gettext-1 gettext-2 \ lang-gawk \ lang-lua \ lang-pascal \ + lang-modula2 \ lang-d \ lang-smalltalk \ lang-vala \ diff --git a/gettext-tools/tests/init-env.in b/gettext-tools/tests/init-env.in index f3db86378..f8e8e886e 100644 --- a/gettext-tools/tests/init-env.in +++ b/gettext-tools/tests/init-env.in @@ -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 index 000000000..13d4c9341 --- /dev/null +++ b/gettext-tools/tests/lang-modula2 @@ -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 + . *) + 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