]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
Go: Add integration test.
authorBruno Haible <bruno@clisp.org>
Fri, 7 Mar 2025 17:41:55 +0000 (18:41 +0100)
committerBruno Haible <bruno@clisp.org>
Fri, 7 Mar 2025 17:44:56 +0000 (18:44 +0100)
* 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.

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

index f2d166cb6698d9629661046f9596a8a433873020..a33f80400947a82cd1b1f17d288a6885857736bd 100644 (file)
@@ -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 7b533702723063869fb091905dbc09b4e8f687dc..c4a39d682374391b42d4fc60a0ac0e4fbd3e716a 100644 (file)
--- 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:
index 24e2c61a33a44dea86daa55f11eb35496a32bbe0..d670dad0caf29ad91a5d8b34017ba13927968e7b 100755 (executable)
@@ -203,6 +203,7 @@ if ! $skip_gnulib; then
     getline
     getopt-gnu
     gettext-h
+    gocomp-script
     hash-map
     hash-set
     iconv
index ab8710d11dce34abe547e47e7909a2a7f07b878d..4a451b1838d0de0924c61b921715420855f2e609 100644 (file)
@@ -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 \
index 096838848dc2f02928f19eb617bd095853068df8..817dfe05913936c06fd69f09eb6102279cd077a2 100644 (file)
@@ -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 (file)
index 0000000..b4b576e
--- /dev/null
@@ -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