1#! /bin/sh
2
3# Test checking of Lisp format strings.
4
5tmpfiles=""
6trap 'rm -fr $tmpfiles' 1 2 3 15
7
8tmpfiles="$tmpfiles f-l-2.data"
9cat <<\EOF > f-l-2.data
10# Valid: ~~ doesn't count
11msgid  "abc~~def"
12msgstr "xyz"
13# Invalid: invalid msgstr
14msgid  "abc~~def"
15msgstr "xyz~"
16# Valid: same argument
17msgid  "abc~Ddef"
18msgstr "xyz~D"
19# Valid: same arguments
20msgid  "abc~1000000@*~Ddef"
21msgstr "~1000000@*xyz~D"
22# Valid: permutation
23msgid  "abc~D~C~Fdef"
24msgstr "xyz~2@*~F~2:*~C~2:*~D"
25# Invalid: too few arguments
26msgid  "abc~1@*~Sdef~0@*~S"
27msgstr "xyz~S"
28# Invalid: too many arguments
29msgid  "abc~Ddef"
30msgstr "xyz~Duvw~C"
31# Invalid: missing non-final argument
32msgid  "abc~1@*~Sdef~0@*~F"
33msgstr "xyz~1@*~S"
34# Invalid: added non-final argument
35msgid  "abc~1@*~Ddef"
36msgstr "xyz~F~D"
37# Valid: formatting variations
38msgid  "abc~Sdef"
39msgstr "xyz~:S"
40# Valid: formatting variations
41msgid  "abc~4Sdef"
42msgstr "xyz~7S"
43# Valid: type compatibility
44msgid  "abc~Sdef"
45msgstr "xyz~W"
46# Valid: type compatibility
47msgid  "abc~Ddef"
48msgstr "xyz~B"
49# Valid: type compatibility
50msgid  "abc~Ddef"
51msgstr "xyz~O"
52# Valid: type compatibility
53msgid  "abc~Ddef"
54msgstr "xyz~X"
55# Valid: type compatibility
56msgid  "abc~Ddef"
57msgstr "xyz~R"
58# Valid: optional plural
59msgid  "~D egg~:P"
60msgstr "~D Eier"
61# Valid: type compatibility
62msgid  "abc~Fdef"
63msgstr "xyz~E"
64# Valid: type compatibility
65msgid  "abc~Fdef"
66msgstr "xyz~G"
67# Valid: type compatibility
68msgid  "abc~Fdef"
69msgstr "xyz~$"
70# Invalid: type incompatibility
71msgid  "abc~Fdef"
72msgstr "xyz~D"
73# Invalid: type incompatibility
74msgid  "abc~Ddef"
75msgstr "xyz~C"
76# Invalid: type incompatibility
77msgid  "abc~Fdef"
78msgstr "xyz~C"
79# Invalid: type incompatibility
80msgid  "abc~Sdef"
81msgstr "xyz~D"
82# Invalid: type incompatibility
83msgid  "abc~Sdef"
84msgstr "xyz~F"
85# Invalid: type incompatibility
86msgid  "abc~Sdef"
87msgstr "xyz~C"
88# Valid: extra formatting
89msgid  "abc~Ddef~S"
90msgstr "xyz~D~_def~%~S"
91# Valid: FORMAT-GOTO doesn't consume an argument by itself
92msgid  "abc~5@*~Ddef~C"
93msgstr "xyz~6@*~C~2@*uvw~5@*~R"
94# Invalid: @ matters
95msgid  "abc~?"
96msgstr "xyz~@?"
97# Valid: case conversion is optional
98msgid  "abc~(~S~)"
99msgstr "xyz~S"
100# Valid: case conversion is optional
101msgid  "abc~(~D~^ ~D~)"
102msgstr "xyz~D~^ ~D"
103# Invalid: ~^ matters
104msgid  "abc~(~D~^ ~D~)"
105msgstr "xyz~(~D ~D~)"
106# Valid: case conversion is optional, and it doesn't catch ~^
107msgid  "abc~(~D~^ ~D~)def~C"
108msgstr "xyz~D~^ ~Duvw~C"
109# Valid: synonymous conditionals
110msgid  "abc~@[~D~]def~C"
111msgstr "xyz~:[~;~:*~D~]~C"
112# Valid: synonymous conditionals
113msgid  "abc~Ddef"
114msgstr "abc~[null~;eins~:;~:*~D~]def"
115# Valid: conditionals are optional and don't catch ~^
116msgid  "abc~:[~;~]~^~D~C"
117msgstr "xyz~:[uvw~^~R~;~:*~S~^~D~]~C"
118# Invalid: ~:[ requires an argument, ~1@* doesn't
119msgid  "abc~1@*~^~D~C"
120msgstr "xyz~:[uvw~^~R~;~:*~S~^~D~]~C"
121# Invalid: ~{~} is special
122msgid  "abc~{ ~}"
123msgstr "xyz~{~}"
124# Invalid: @ matters
125msgid  "abc~{~S~}"
126msgstr "xyz~@{~S~}"
127# Invalid: @ matters
128msgid  "abc~:{~S~}"
129msgstr "xyz~@:{~S~}"
130# Invalid: : matters
131msgid  "abc~{~S~}"
132msgstr "xyz~:{~S~}"
133# Invalid: : matters
134msgid  "abc~@{~S~}"
135msgstr "xyz~@:{~S~}"
136# Invalid: @: matters
137msgid  "abc~{~S~}"
138msgstr "xyz~@:{~S~}"
139# Valid: permutation inside iteration
140msgid  "abc~{~D ~C~}"
141msgstr "xyz~{~1@*~C~2:*~D~1*~}"
142# Invalid: permutation inside iteration, but wrong position at iteration end
143msgid  "abc~{~D ~C~}"
144msgstr "xyz~{~1@*~C~2:*~D~}"
145# Invalid: ~^ inside iteration matters
146msgid  "abc~{~D ~^~C~}"
147msgstr "xyz~{~D ~C~}"
148# Invalid: ~^ inside iteration depends on position
149msgid  "abc~{~D ~^~C~}"
150msgstr "xyz~{~1@*~C~^~2:*~D~1*~}"
151# Invalid: ~^ inside iteration depends on position
152msgid  "abc~{~D ~^~C~}"
153msgstr "xyz~{~1@*~C~2:*~^~D~1*~}"
154# Invalid: ~^ inside iteration depends on position
155msgid  "abc~{~D ~^~C~}"
156msgstr "xyz~{~1@*~C~2:*~D~^~1*~}"
157# Invalid: ~^ inside iteration depends on position
158msgid  "abc~{~D ~^~C~}"
159msgstr "xyz~{~1@*~C~2:*~D~1*~^~}"
160# Valid: justification is optional
161msgid  "abc~<~D~;~C~>"
162msgstr "xyz~D~C"
163# Valid: justification with different segmentation
164msgid  "abc~<~D ~D~;~C~;~S~S~>"
165msgstr "xyz~<~D~;~D~C~S~;~S~>"
166# Invalid: justification catches ~^
167msgid  "abc~<~D~;~^~D~>~C"
168msgstr "abc~D~^~D~C"
169EOF
170
171: ${MSGFMT=msgfmt}
172n=0
173while read comment; do
174  read msgid_line
175  read msgstr_line
176  n=`expr $n + 1`
177  tmpfiles="$tmpfiles f-l-2-$n.po f-l-2-$n.mo"
178  cat <<EOF > f-l-2-$n.po
179#, lisp-format
180${msgid_line}
181${msgstr_line}
182EOF
183  fail=
184  if echo "$comment" | grep 'Valid:' > /dev/null; then
185    if ${MSGFMT} --check-format -o f-l-2-$n.mo f-l-2-$n.po; then
186      :
187    else
188      fail=yes
189    fi
190  else
191    ${MSGFMT} --check-format -o f-l-2-$n.mo f-l-2-$n.po 2> /dev/null
192    if test $? = 1; then
193      :
194    else
195      fail=yes
196    fi
197  fi
198  if test -n "$fail"; then
199    echo "Format string checking error:" 1>&2
200    cat f-l-2-$n.po 1>&2
201    exit 1
202  fi
203  rm -f f-l-2-$n.po f-l-2-$n.mo
204done < f-l-2.data
205
206rm -fr $tmpfiles
207
208exit 0
209