• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#! /bin/sh
2. "${srcdir=.}/init.sh"; path_prepend_ . ../src
3
4# Test checking of awk format strings.
5
6cat <<\EOF > f-a-2.data
7# Valid: %% doesn't count
8msgid  "abc%%def"
9msgstr "xyz"
10# Invalid: invalid msgstr
11msgid  "abc%%def"
12msgstr "xyz%"
13# Valid: same arguments
14msgid  "abc%s%gdef"
15msgstr "xyz%s%g"
16# Valid: same arguments, with different widths
17msgid  "abc%2sdef"
18msgstr "xyz%3s"
19# Valid: same arguments but in numbered syntax
20msgid  "abc%s%gdef"
21msgstr "xyz%1$s%2$g"
22# Valid: permutation
23msgid  "abc%s%g%cdef"
24msgstr "xyz%3$c%2$g%1$s"
25# Invalid: too few arguments
26msgid  "abc%2$udef%1$s"
27msgstr "xyz%1$s"
28# Invalid: too few arguments
29msgid  "abc%sdef%u"
30msgstr "xyz%s"
31# Invalid: too many arguments
32msgid  "abc%udef"
33msgstr "xyz%uvw%c"
34# Valid: same numbered arguments, with different widths
35msgid  "abc%2$5s%1$4s"
36msgstr "xyz%2$4s%1$5s"
37# Invalid: missing argument
38msgid  "abc%2$sdef%1$u"
39msgstr "xyz%1$u"
40# Invalid: missing argument
41msgid  "abc%1$sdef%2$u"
42msgstr "xyz%2$u"
43# Invalid: added argument
44msgid  "abc%1$udef"
45msgstr "xyz%1$uvw%2$c"
46# Valid: type compatibility
47msgid  "abc%i"
48msgstr "xyz%d"
49# Valid: type compatibility
50msgid  "abc%o"
51msgstr "xyz%u"
52# Valid: type compatibility
53msgid  "abc%u"
54msgstr "xyz%x"
55# Valid: type compatibility
56msgid  "abc%u"
57msgstr "xyz%X"
58# Valid: type compatibility
59msgid  "abc%e"
60msgstr "xyz%E"
61# Valid: type compatibility
62msgid  "abc%e"
63msgstr "xyz%f"
64# Valid: type compatibility
65msgid  "abc%e"
66msgstr "xyz%g"
67# Valid: type compatibility
68msgid  "abc%e"
69msgstr "xyz%G"
70# Invalid: type incompatibility
71msgid  "abc%c"
72msgstr "xyz%s"
73# Invalid: type incompatibility
74msgid  "abc%c"
75msgstr "xyz%i"
76# Invalid: type incompatibility
77msgid  "abc%c"
78msgstr "xyz%o"
79# Invalid: type incompatibility
80msgid  "abc%c"
81msgstr "xyz%e"
82# Invalid: type incompatibility
83msgid  "abc%s"
84msgstr "xyz%i"
85# Invalid: type incompatibility
86msgid  "abc%s"
87msgstr "xyz%o"
88# Invalid: type incompatibility
89msgid  "abc%s"
90msgstr "xyz%e"
91# Invalid: type incompatibility
92msgid  "abc%i"
93msgstr "xyz%o"
94# Invalid: type incompatibility
95msgid  "abc%i"
96msgstr "xyz%e"
97# Invalid: type incompatibility
98msgid  "abc%u"
99msgstr "xyz%e"
100# Invalid: type incompatibility for width
101msgid  "abc%g%*g"
102msgstr "xyz%*g%g"
103EOF
104
105: ${MSGFMT=msgfmt}
106n=0
107while read comment; do
108  read msgid_line
109  read msgstr_line
110  n=`expr $n + 1`
111  cat <<EOF > f-a-2-$n.po
112#, awk-format
113${msgid_line}
114${msgstr_line}
115EOF
116  fail=
117  if echo "$comment" | grep 'Valid:' > /dev/null; then
118    if ${MSGFMT} --check-format -o f-a-2-$n.mo f-a-2-$n.po; then
119      :
120    else
121      fail=yes
122    fi
123  else
124    ${MSGFMT} --check-format -o f-a-2-$n.mo f-a-2-$n.po 2> /dev/null
125    if test $? = 1; then
126      :
127    else
128      fail=yes
129    fi
130  fi
131  if test -n "$fail"; then
132    echo "Format string checking error:" 1>&2
133    cat f-a-2-$n.po 1>&2
134    Exit 1
135  fi
136  rm -f f-a-2-$n.po f-a-2-$n.mo
137done < f-a-2.data
138
139Exit 0
140