From: Bruno Haible Date: Fri, 7 Mar 2025 17:41:55 +0000 (+0100) Subject: Go: Add integration test. X-Git-Tag: v0.25~94 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1fb787067092d94f3f525fe62f3359ed813e0f4b;p=thirdparty%2Fgettext.git Go: Add integration test. * autogen.sh (GNULIB_MODULES_RUNTIME_FOR_SRC): Add gocomp-script. * gettext-tools/tests/init-env.in (GO_CHOICE, GO): New variables. * gettext-tools/tests/lang-go: New file. * gettext-tools/tests/Makefile.am (TESTS): Add it. * HACKING: Document dependencies for lang-go. --- diff --git a/.gitignore b/.gitignore index f2d166cb6..a33f80400 100644 --- a/.gitignore +++ b/.gitignore @@ -31,6 +31,7 @@ /build-aux/csharpexec.sh.in /build-aux/git-version-gen /build-aux/gitlog-to-changelog +/build-aux/gocomp.sh.in /build-aux/install-reloc /build-aux/javacomp.sh.in /build-aux/javaexec.sh.in @@ -650,6 +651,7 @@ autom4te.cache/ /gettext-tools/config.h /gettext-tools/csharpcomp.sh /gettext-tools/csharpexec.sh +/gettext-tools/gocomp.sh /gettext-tools/javacomp.sh /gettext-tools/javaexec.sh /gettext-tools/libtool diff --git a/HACKING b/HACKING index 7b5337027..c4a39d682 100644 --- a/HACKING +++ b/HACKING @@ -234,6 +234,33 @@ are skipped. To this effect, you need to install also: - Other: https://repology.org/project/rust/versions https://repology.org/project/cargo/versions + * Go + Either the golang Go implementation or the GCC Go implementation. + o golang Go implementation + + Recommended where available. + + Homepage: https://go.dev/ + + Documentation: https://go.dev/doc/ + + Pre-built package name: + - On Debian and Debian-based systems: golang-go, + - On Red Hat distributions: golang. + - Other: https://repology.org/project/go/versions + o GCC Go implementation + + Recommended on those platforms where the golang Go implementation + is not available. This includes in particular: + - Linux/alpha, Linux/hppa, Linux/m68k, Linux/sparc, Linux/powerpc (32-bit) + - GNU/Hurd + - Solaris/sparc + - Haiku + + Homepage: https://gcc.gnu.org/ + + Documentation: + - https://go.dev/doc/install/gccgo + - https://gcc.gnu.org/onlinedocs/gccgo/index.html + + Pre-built package name: + - On Debian and Debian-based systems: gccgo, + - On Red Hat distributions: gcc-go. + - Other: https://repology.org/project/gcc/versions + https://repology.org/project/gccgo/versions + * Ruby + Homepage: https://www.ruby-lang.org/en/ + Pre-built package name: diff --git a/autogen.sh b/autogen.sh index 24e2c61a3..d670dad0c 100755 --- a/autogen.sh +++ b/autogen.sh @@ -203,6 +203,7 @@ if ! $skip_gnulib; then getline getopt-gnu gettext-h + gocomp-script hash-map hash-set iconv diff --git a/gettext-tools/tests/Makefile.am b/gettext-tools/tests/Makefile.am index ab8710d11..4a451b183 100644 --- a/gettext-tools/tests/Makefile.am +++ b/gettext-tools/tests/Makefile.am @@ -230,6 +230,7 @@ TESTS = gettext-1 gettext-2 \ lang-javascript \ lang-guile lang-clisp lang-elisp lang-librep \ lang-rust \ + lang-go \ lang-ruby \ lang-sh lang-bash \ lang-gawk \ diff --git a/gettext-tools/tests/init-env.in b/gettext-tools/tests/init-env.in index 096838848..817dfe059 100644 --- a/gettext-tools/tests/init-env.in +++ b/gettext-tools/tests/init-env.in @@ -18,6 +18,8 @@ TESTJAVA="@TESTJAVA@" CSHARP_CHOICE="@CSHARP_CHOICE@" BUILDCSHARP="@BUILDCSHARP@" TESTCSHARP="@TESTCSHARP@" +GO_CHOICE="@GO_CHOICE@" +GO="@GO@" TESTLIBASPRINTF="@TESTLIBASPRINTF@" GLIBC2="@GLIBC2@" LOCALE_FR="@LOCALE_FR@" diff --git a/gettext-tools/tests/lang-go b/gettext-tools/tests/lang-go new file mode 100644 index 000000000..b4b576e3c --- /dev/null +++ b/gettext-tools/tests/lang-go @@ -0,0 +1,153 @@ +#! /bin/sh +. "${srcdir=.}/init.sh"; path_prepend_ . ../src + +# Test of gettext facilities in the Go language. +# Assumes an fr_FR locale is installed. +# Assumes the following packages are installed: golang-go or gccgo. + +# Test whether we can build and test Go programs. +test "${GO_CHOICE}" != no || { + echo "Skipping test: configured with --disable-go" + Exit 77 +} +test -n "${GO}" || { + echo "Skipping test: Go compiler not found" + Exit 77 +} + +cat <<\EOF > go.mod +module hello +go 1.11 +require github.com/leonelquinteros/gotext v1.6.0 +EOF + +cat <<\EOF > program.go +package main + +import ( + "fmt" + "os" + "strconv" + "github.com/leonelquinteros/gotext" +) + +func getUserLanguage() string { + // Look at the POSIX environment variables. + for _, variable := range []string{"LC_ALL", "LC_MESSAGES", "LANG"} { + if value := os.Getenv(variable); value != "" { + return gotext.SimplifiedLocale(value) + } + } + // The "C" locale is essentially the same as the en-US locale. + return "en_US" +} + +func main () { + n, _ := strconv.Atoi(os.Args[1]) + + // Specify locale. + language := getUserLanguage() + + // Specify localedir, domain. + gotext.Configure(".", language, "prog") + + fmt.Println(gotext.Get("'Your command, please?', asked the waiter.")) + fmt.Println(gotext.GetN("%.0sa piece of cake", "%s pieces of cake", n, strconv.Itoa(n))); + fmt.Println(gotext.Get("%s is replaced by %s.", "FF", "EUR")); +} +EOF + +${GO} mod download github.com/leonelquinteros/gotext + +: ${GOCOMP="/bin/sh ../../gocomp.sh"} +${GOCOMP} program.go 2>prog.err \ + || { cat prog.err 1>&2; Exit 1; } + +: ${XGETTEXT=xgettext} +${XGETTEXT} -o prog.tmp --omit-header --no-location program.go || 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 "" + +#, go-format +msgid "%.0sa piece of cake" +msgid_plural "%s pieces of cake" +msgstr[0] "" +msgstr[1] "" + +#, go-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=UTF-8\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. +#, go-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. +#, go-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 + +: ${DIFF=diff} +cat <<\EOF > prog.ok +«Votre commande, s'il vous plait», dit le garçon. +2 morceaux de gateau +EUR remplace FF. +EOF + +# Test which of the fr_FR locales are installed. +: ${LOCALE_FR_UTF8=fr_FR.UTF-8} +if test $LOCALE_FR_UTF8 != none; then + LC_ALL=$LOCALE_FR_UTF8 ../testlocale + case $? in + 0) ;; + 77) LOCALE_FR_UTF8=none;; + *) Exit 1;; + esac +fi +if test $LOCALE_FR_UTF8 = none; then + if test -f /usr/bin/localedef; then + echo "Skipping test: no french Unicode locale is installed" + else + echo "Skipping test: no french Unicode locale is supported" + fi + Exit 77 +fi + +prepare_locale_ fr $LOCALE_FR_UTF8 +LANGUAGE= LC_ALL=$LOCALE_FR_UTF8 ./program 2 > prog.out || Exit 1 +${DIFF} prog.ok prog.out || Exit 1 + +Exit 0