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