Add -lm dependency for gettextlib to fix LTO build
[platform/upstream/gettext.git] / gettext-tools / tests / lang-bash
1 #! /bin/sh
2 . "${srcdir=.}/init.sh"; path_prepend_ . ../src ${top_srcdir=..}/../gettext-runtime/src
3
4 # Test of gettext facilities in the bash language.
5 # Assumes an fr_FR locale is installed.
6 # Assumes the following packages are installed: bash 2.0 or newer.
7
8 # This test fails on MacOS X 10.5 because its 'bash' command is built with
9 # an included intl directory without iconv support; hence it produces wrong
10 # output when accessing any .mo file not generated from a .po file in UTF-8
11 # encoding.
12
13 cat <<\EOF > prog.bash
14 #! /bin/bash
15
16 n=$1
17
18 . gettext.sh
19
20 TEXTDOMAIN=prog
21 export TEXTDOMAIN
22 TEXTDOMAINDIR=.
23 export TEXTDOMAINDIR
24
25 $echo $"'Your command, please?', asked the waiter."
26
27 $echo "`eval_ngettext "a piece of cake" "\\$n pieces of cake" $n`"
28 EOF
29
30 : ${XGETTEXT=xgettext}
31 LC_MESSAGES=C LC_ALL= \
32 ${XGETTEXT} -o prog.tmp --omit-header --no-location prog.bash \
33   >prog.err 2>&1
34 result=$?
35 cat prog.err | grep -v 'warning: the syntax \$"\.\.\." is deprecated due to security reasons'
36 test $result = 0 || { exit 1; }
37 LC_ALL=C tr -d '\r' < prog.tmp > prog.pot || exit 1
38
39 cat <<\EOF > prog.ok
40 msgid "'Your command, please?', asked the waiter."
41 msgstr ""
42
43 #, sh-format
44 msgid "a piece of cake"
45 msgid_plural "$n pieces of cake"
46 msgstr[0] ""
47 msgstr[1] ""
48 EOF
49
50 : ${DIFF=diff}
51 ${DIFF} prog.ok prog.pot || exit 1
52
53 cat <<\EOF > fr.po
54 msgid ""
55 msgstr ""
56 "Content-Type: text/plain; charset=ISO-8859-1\n"
57 "Plural-Forms: nplurals=2; plural=(n > 1);\n"
58
59 msgid "'Your command, please?', asked the waiter."
60 msgstr "«Votre commande, s'il vous plait», dit le garçon."
61
62 # Les gateaux allemands sont les meilleurs du monde.
63 #, sh-format
64 msgid "a piece of cake"
65 msgid_plural "$n pieces of cake"
66 msgstr[0] "un morceau de gateau"
67 msgstr[1] "$n morceaux de gateau"
68 EOF
69
70 : ${MSGMERGE=msgmerge}
71 ${MSGMERGE} -q -o fr.po.tmp fr.po prog.pot || exit 1
72 LC_ALL=C tr -d '\r' < fr.po.tmp > fr.po.new || exit 1
73
74 : ${DIFF=diff}
75 ${DIFF} fr.po fr.po.new || exit 1
76
77 test -d fr || mkdir fr
78 test -d fr/LC_MESSAGES || mkdir fr/LC_MESSAGES
79
80 : ${MSGFMT=msgfmt}
81 ${MSGFMT} -o fr/LC_MESSAGES/prog.mo fr.po
82
83 # Test for presence of bash version 2.0 or newer.
84 (bash -c :) >/dev/null 2>/dev/null \
85   || { echo "Skipping test: bash not found"; exit 77; }
86 case `bash -c 'echo $BASH_VERSION'` in
87   [2-9].*) ;;
88   *) echo "Skipping test: bash version too old"; exit 77;;
89 esac
90
91 # Test which of the fr_FR locales are installed.
92 : ${LOCALE_FR=fr_FR}
93 : ${LOCALE_FR_UTF8=fr_FR.UTF-8}
94 if test $LOCALE_FR != none; then
95   LC_ALL=$LOCALE_FR ../testlocale
96   case $? in
97     0) ;;
98     77) LOCALE_FR=none;;
99     *) exit 1;;
100   esac
101 fi
102 if test $LOCALE_FR_UTF8 != none; then
103   LC_ALL=$LOCALE_FR_UTF8 ../testlocale
104   case $? in
105     0) ;;
106     77) LOCALE_FR_UTF8=none;;
107     *) exit 1;;
108   esac
109 fi
110 if test $LOCALE_FR = none && test $LOCALE_FR_UTF8 = none; then
111   if test -f /usr/bin/localedef; then
112     echo "Skipping test: no french locale is installed"
113   else
114     echo "Skipping test: no french locale is supported"
115   fi
116   exit 77
117 fi
118
119 case "$host_os" in
120   darwin*)
121     if test $LOCALE_FR != none; then
122       LC_ALL=$LOCALE_FR bash --help \
123         | grep '^Utilisation' > /dev/null 2>&1 || exit 77
124     fi
125     if test $LOCALE_FR_UTF8 != none; then
126       LC_ALL=$LOCALE_FR_UTF8 bash --help \
127         | grep '^Utilisation' > /dev/null 2>&1 || exit 77
128     fi
129   ;;
130 esac
131
132 # Expected result when bash is built without i18n support.
133 cat <<\EOF > prog.nok
134 'Your command, please?', asked the waiter.
135 2 morceaux de gateau
136 EOF
137 # Expected result when bash is built with i18n support.
138 cat <<\EOF > prog.ok
139 «Votre commande, s'il vous plait», dit le garçon.
140 2 morceaux de gateau
141 EOF
142 cat <<\EOF > prog.oku
143 «Votre commande, s'il vous plait», dit le garçon.
144 2 morceaux de gateau
145 EOF
146
147 : ${LOCALE_FR=fr_FR}
148 : ${LOCALE_FR_UTF8=fr_FR.UTF-8}
149 if test $LOCALE_FR != none; then
150   prepare_locale_ fr $LOCALE_FR
151   LANGUAGE= LC_ALL=$LOCALE_FR bash ./prog.bash 2 > prog.out || exit 1
152   : ${DIFF=diff}
153   ${DIFF} prog.nok prog.out > /dev/null && {
154     echo "Skipping test: bash is built without i18n support"
155     exit 77
156   }
157   ${DIFF} prog.ok prog.out || exit 1
158 fi
159 if test $LOCALE_FR_UTF8 != none; then
160   prepare_locale_ fr $LOCALE_FR_UTF8
161   LANGUAGE= LC_ALL=$LOCALE_FR_UTF8 bash ./prog.bash 2 > prog.out || exit 1
162   : ${DIFF=diff}
163   ${DIFF} prog.nok prog.out > /dev/null && {
164     echo "Skipping test: bash is built without i18n support"
165     exit 77
166   }
167   ${DIFF} prog.oku prog.out || exit 1
168 fi
169
170 exit 0