02b9820bb397425e88fbb37dc05f2daf77ad6b4a
[platform/upstream/gettext.git] / gettext-tools / tests / xgettext-perl-6
1 #! /bin/sh
2
3 # Test whether the right number of arguments are extracted.
4
5 tmpfiles=""
6 trap 'rm -fr $tmpfiles' 1 2 3 15
7
8 tmpfiles="$tmpfiles xg-pl-6.pl"
9 cat <<\EOPERL > xg-pl-6.pl
10 use strict;
11
12 # For 'gettext', xgettext needs to extract the first argument.
13
14 # Don't extract further strings (second argument to gettext or unrelated
15 # expressions).
16 print gettext "extracted1", "$shouldnotbeextracted";
17 print gettext ("extracted2"), "$shouldnotbeextracted";
18 print gettext ("extracted3")."$notextracted", "$shouldnotbeextracted";
19 print (gettext ("extracted4")), "$shouldnotbeextracted";
20
21 # Likewise, inside a call to an arbitrary 'foobar' function.
22 print foobar gettext "extracted5", "$shouldnotbeextracted";
23 print foobar gettext ("extracted6"), "$shouldnotbeextracted";
24 print foobar gettext ("extracted7")."$notextracted", "$shouldnotbeextracted";
25 print foobar (gettext ("extracted8")), "$shouldnotbeextracted";
26 print foobar (gettext "extracted9", "$shouldnotbeextracted");
27 print foobar (gettext ("extracted10"), "$shouldnotbeextracted");
28 print foobar (gettext ("extracted11")."$notextracted", "$shouldnotbeextracted");
29
30 # Don't extract strings that are inside a function call to an arbitrary
31 # 'foobar' function, and don't extract a second argument to gettext
32 print gettext foobar "$notextracted", "$shouldnotbeextracted";
33 print gettext foobar ("$notextracted"), "$shouldnotbeextracted";
34 print gettext foobar ("$notextracted")."$notextracted", "$shouldnotbeextracted";
35 print (gettext foobar ("$notextracted")), "$shouldnotbeextracted";
36 print gettext (foobar "$notextracted"), "$shouldnotbeextracted";
37 print gettext (foobar ("$notextracted")), "$shouldnotbeextracted";
38 print gettext (foobar ("$notextracted"))."$notextracted", "$shouldnotbeextracted";
39 print gettext (foobar ("$notextracted")."$notextracted"), "$shouldnotbeextracted";
40 print (gettext (foobar ("$notextracted"))), "$shouldnotbeextracted";
41
42 # For 'dgettext', xgettext needs to extract the second argument.
43
44 # The first argument should not be extracted.
45 print dgettext "$shouldnotbeextracted", "extracted12";
46
47 # For a built-in unary function with parentheses, it's clear where dgettext's
48 # first argument ends.
49 print dgettext sin (17), "extracted13";
50
51 # For a built-in unary function, it's clear where dgettext's first argument
52 # ends.
53 print dgettext sin 17, "extracted14";
54
55 # For a function call with parentheses, it's clear where dgettext's first
56 # argument ends.
57 print dgettext foo (17), "extracted15";
58
59 # This one is hairy. If foo is a function with a prototype and one argument,
60 # this parses like
61 #   print dgettext (foo (17), "extracted16");
62 # otherwise it parses like
63 #   print dgettext (foo (17, "extracted16"));
64 # But in the latter case dgettext has no second argument at all; this is
65 # therefore not the interpretation intended by the programmer.
66 print dgettext foo 17, "extracted16";
67 EOPERL
68
69 tmpfiles="$tmpfiles xg-pl-6.tmp xg-pl-6.pot"
70 : ${XGETTEXT=xgettext}
71 LC_MESSAGES=C LC_ALL= \
72 ${XGETTEXT} --omit-header --no-location -o xg-pl-6.tmp xg-pl-6.pl
73 test $? = 0 || { rm -fr $tmpfiles; exit 1; }
74 LC_ALL=C tr -d '\r' < xg-pl-6.tmp > xg-pl-6.pot
75 test $? = 0 || { rm -fr $tmpfiles; exit 1; }
76
77 tmpfiles="$tmpfiles xg-pl-6.ok"
78 cat <<\EOF > xg-pl-6.ok
79 msgid "extracted1"
80 msgstr ""
81
82 msgid "extracted2"
83 msgstr ""
84
85 msgid "extracted3"
86 msgstr ""
87
88 msgid "extracted4"
89 msgstr ""
90
91 msgid "extracted5"
92 msgstr ""
93
94 msgid "extracted6"
95 msgstr ""
96
97 msgid "extracted7"
98 msgstr ""
99
100 msgid "extracted8"
101 msgstr ""
102
103 msgid "extracted9"
104 msgstr ""
105
106 msgid "extracted10"
107 msgstr ""
108
109 msgid "extracted11"
110 msgstr ""
111
112 msgid "extracted12"
113 msgstr ""
114
115 msgid "extracted13"
116 msgstr ""
117
118 msgid "extracted14"
119 msgstr ""
120
121 msgid "extracted15"
122 msgstr ""
123
124 msgid "extracted16"
125 msgstr ""
126 EOF
127
128 : ${DIFF=diff}
129 ${DIFF} xg-pl-6.ok xg-pl-6.pot
130 result=$?
131
132 rm -fr $tmpfiles
133
134 exit $result