Home | History | Annotate | Line # | Download | only in tests
      1 #! /bin/sh
      2 
      3 # Test checking of C format strings.
      4 
      5 tmpfiles=""
      6 trap 'rm -fr $tmpfiles' 1 2 3 15
      7 
      8 tmpfiles="$tmpfiles f-c-2.data"
      9 cat <<\EOF > f-c-2.data
     10 # Valid: %% doesn't count
     11 msgid  "abc%%def"
     12 msgstr "xyz"
     13 # Invalid: invalid msgstr
     14 msgid  "abc%%def"
     15 msgstr "xyz%"
     16 # Valid: same arguments
     17 msgid  "abc%s%gdef"
     18 msgstr "xyz%s%g"
     19 # Valid: same arguments, with different widths
     20 msgid  "abc%2sdef"
     21 msgstr "xyz%3s"
     22 # Valid: same arguments but in numbered syntax
     23 msgid  "abc%s%gdef"
     24 msgstr "xyz%1$s%2$g"
     25 # Valid: permutation
     26 msgid  "abc%s%g%cdef"
     27 msgstr "xyz%3$c%2$g%1$s"
     28 # Invalid: too few arguments
     29 msgid  "abc%2$udef%1$s"
     30 msgstr "xyz%1$s"
     31 # Invalid: too few arguments
     32 msgid  "abc%sdef%u"
     33 msgstr "xyz%s"
     34 # Invalid: too many arguments
     35 msgid  "abc%udef"
     36 msgstr "xyz%uvw%c"
     37 # Valid: same numbered arguments, with different widths
     38 msgid  "abc%2$5s%1$4s"
     39 msgstr "xyz%2$4s%1$5s"
     40 # Invalid: missing argument
     41 msgid  "abc%2$sdef%1$u"
     42 msgstr "xyz%1$u"
     43 # Invalid: missing argument
     44 msgid  "abc%1$sdef%2$u"
     45 msgstr "xyz%2$u"
     46 # Invalid: added argument
     47 msgid  "abc%1$udef"
     48 msgstr "xyz%1$uvw%2$c"
     49 # Valid: type compatibility
     50 msgid  "abc%i"
     51 msgstr "xyz%d"
     52 # Valid: type compatibility
     53 msgid  "abc%o"
     54 msgstr "xyz%u"
     55 # Valid: type compatibility
     56 msgid  "abc%u"
     57 msgstr "xyz%x"
     58 # Valid: type compatibility
     59 msgid  "abc%u"
     60 msgstr "xyz%X"
     61 # Valid: type compatibility
     62 msgid  "abc%e"
     63 msgstr "xyz%E"
     64 # Valid: type compatibility
     65 msgid  "abc%e"
     66 msgstr "xyz%f"
     67 # Valid: type compatibility
     68 msgid  "abc%e"
     69 msgstr "xyz%F"
     70 # Valid: type compatibility
     71 msgid  "abc%e"
     72 msgstr "xyz%g"
     73 # Valid: type compatibility
     74 msgid  "abc%e"
     75 msgstr "xyz%G"
     76 # Valid: type compatibility
     77 msgid  "abc%e"
     78 msgstr "xyz%a"
     79 # Valid: type compatibility
     80 msgid  "abc%e"
     81 msgstr "xyz%A"
     82 # Invalid: type incompatibility
     83 msgid  "abc%c"
     84 msgstr "xyz%s"
     85 # Invalid: type incompatibility
     86 msgid  "abc%c"
     87 msgstr "xyz%i"
     88 # Invalid: type incompatibility
     89 msgid  "abc%c"
     90 msgstr "xyz%o"
     91 # Invalid: type incompatibility
     92 msgid  "abc%c"
     93 msgstr "xyz%e"
     94 # Invalid: type incompatibility
     95 msgid  "abc%c"
     96 msgstr "xyz%p"
     97 # Invalid: type incompatibility
     98 msgid  "abc%c"
     99 msgstr "xyz%n"
    100 # Invalid: type incompatibility
    101 msgid  "abc%s"
    102 msgstr "xyz%i"
    103 # Invalid: type incompatibility
    104 msgid  "abc%s"
    105 msgstr "xyz%o"
    106 # Invalid: type incompatibility
    107 msgid  "abc%s"
    108 msgstr "xyz%e"
    109 # Invalid: type incompatibility
    110 msgid  "abc%s"
    111 msgstr "xyz%p"
    112 # Invalid: type incompatibility
    113 msgid  "abc%s"
    114 msgstr "xyz%n"
    115 # Invalid: type incompatibility
    116 msgid  "abc%i"
    117 msgstr "xyz%o"
    118 # Invalid: type incompatibility
    119 msgid  "abc%i"
    120 msgstr "xyz%e"
    121 # Invalid: type incompatibility
    122 msgid  "abc%i"
    123 msgstr "xyz%p"
    124 # Invalid: type incompatibility
    125 msgid  "abc%i"
    126 msgstr "xyz%n"
    127 # Invalid: type incompatibility
    128 msgid  "abc%u"
    129 msgstr "xyz%e"
    130 # Invalid: type incompatibility
    131 msgid  "abc%u"
    132 msgstr "xyz%p"
    133 # Invalid: type incompatibility
    134 msgid  "abc%u"
    135 msgstr "xyz%n"
    136 # Invalid: type incompatibility
    137 msgid  "abc%e"
    138 msgstr "xyz%p"
    139 # Invalid: type incompatibility
    140 msgid  "abc%e"
    141 msgstr "xyz%n"
    142 # Invalid: type incompatibility
    143 msgid  "abc%p"
    144 msgstr "xyz%n"
    145 # Invalid: type incompatibility due to size
    146 msgid  "abc%i"
    147 msgstr "xyz%hhi"
    148 # Invalid: type incompatibility due to size
    149 msgid  "abc%i"
    150 msgstr "xyz%hi"
    151 # Invalid: type incompatibility due to size
    152 msgid  "abc%i"
    153 msgstr "xyz%li"
    154 # Invalid: type incompatibility due to size
    155 msgid  "abc%i"
    156 msgstr "xyz%lli"
    157 # Invalid: type incompatibility due to size
    158 msgid  "abc%i"
    159 msgstr "xyz%Li"
    160 # Invalid: type incompatibility due to size
    161 msgid  "abc%i"
    162 msgstr "xyz%qi"
    163 # Invalid: type incompatibility due to size
    164 msgid  "abc%i"
    165 msgstr "xyz%ji"
    166 # Invalid: type incompatibility due to size
    167 msgid  "abc%i"
    168 msgstr "xyz%zi"
    169 # Invalid: type incompatibility due to size
    170 msgid  "abc%i"
    171 msgstr "xyz%ti"
    172 # Invalid: type incompatibility due to size
    173 msgid  "abc%hhi"
    174 msgstr "xyz%hi"
    175 # Invalid: type incompatibility due to size
    176 msgid  "abc%hhi"
    177 msgstr "xyz%li"
    178 # Invalid: type incompatibility due to size
    179 msgid  "abc%hhi"
    180 msgstr "xyz%lli"
    181 # Invalid: type incompatibility due to size
    182 msgid  "abc%hhi"
    183 msgstr "xyz%Li"
    184 # Invalid: type incompatibility due to size
    185 msgid  "abc%hhi"
    186 msgstr "xyz%qi"
    187 # Invalid: type incompatibility due to size
    188 msgid  "abc%hhi"
    189 msgstr "xyz%ji"
    190 # Invalid: type incompatibility due to size
    191 msgid  "abc%hhi"
    192 msgstr "xyz%zi"
    193 # Invalid: type incompatibility due to size
    194 msgid  "abc%hhi"
    195 msgstr "xyz%ti"
    196 # Invalid: type incompatibility due to size
    197 msgid  "abc%hi"
    198 msgstr "xyz%li"
    199 # Invalid: type incompatibility due to size
    200 msgid  "abc%hi"
    201 msgstr "xyz%lli"
    202 # Invalid: type incompatibility due to size
    203 msgid  "abc%hi"
    204 msgstr "xyz%Li"
    205 # Invalid: type incompatibility due to size
    206 msgid  "abc%hi"
    207 msgstr "xyz%qi"
    208 # Invalid: type incompatibility due to size
    209 msgid  "abc%hi"
    210 msgstr "xyz%ji"
    211 # Invalid: type incompatibility due to size
    212 msgid  "abc%hi"
    213 msgstr "xyz%zi"
    214 # Invalid: type incompatibility due to size
    215 msgid  "abc%hi"
    216 msgstr "xyz%ti"
    217 # Invalid: type incompatibility due to size
    218 msgid  "abc%li"
    219 msgstr "xyz%lli"
    220 # Invalid: type incompatibility due to size
    221 msgid  "abc%li"
    222 msgstr "xyz%Li"
    223 # Invalid: type incompatibility due to size
    224 msgid  "abc%li"
    225 msgstr "xyz%qi"
    226 # Invalid: type incompatibility due to size
    227 msgid  "abc%li"
    228 msgstr "xyz%ji"
    229 # Invalid: type incompatibility due to size
    230 msgid  "abc%li"
    231 msgstr "xyz%zi"
    232 # Invalid: type incompatibility due to size
    233 msgid  "abc%li"
    234 msgstr "xyz%ti"
    235 # Invalid: type incompatibility due to size
    236 msgid  "abc%lli"
    237 msgstr "xyz%ji"
    238 # Invalid: type incompatibility due to size
    239 msgid  "abc%lli"
    240 msgstr "xyz%zi"
    241 # Invalid: type incompatibility due to size
    242 msgid  "abc%lli"
    243 msgstr "xyz%ti"
    244 # Invalid: type incompatibility due to size
    245 msgid  "abc%Li"
    246 msgstr "xyz%ji"
    247 # Invalid: type incompatibility due to size
    248 msgid  "abc%Li"
    249 msgstr "xyz%zi"
    250 # Invalid: type incompatibility due to size
    251 msgid  "abc%Li"
    252 msgstr "xyz%ti"
    253 # Invalid: type incompatibility due to size
    254 msgid  "abc%qi"
    255 msgstr "xyz%ji"
    256 # Invalid: type incompatibility due to size
    257 msgid  "abc%qi"
    258 msgstr "xyz%zi"
    259 # Invalid: type incompatibility due to size
    260 msgid  "abc%qi"
    261 msgstr "xyz%ti"
    262 # Invalid: type incompatibility due to size
    263 msgid  "abc%ji"
    264 msgstr "xyz%zi"
    265 # Invalid: type incompatibility due to size
    266 msgid  "abc%ji"
    267 msgstr "xyz%ti"
    268 # Invalid: type incompatibility due to size
    269 msgid  "abc%zi"
    270 msgstr "xyz%ti"
    271 # Invalid: type incompatibility for width
    272 msgid  "abc%g%*g"
    273 msgstr "xyz%*g%g"
    274 EOF
    275 
    276 : ${MSGFMT=msgfmt}
    277 n=0
    278 while read comment; do
    279   read msgid_line
    280   read msgstr_line
    281   n=`expr $n + 1`
    282   tmpfiles="$tmpfiles f-c-2-$n.po f-c-2-$n.mo"
    283   cat <<EOF > f-c-2-$n.po
    284 #, c-format
    285 ${msgid_line}
    286 ${msgstr_line}
    287 EOF
    288   fail=
    289   if echo "$comment" | grep 'Valid:' > /dev/null; then
    290     if ${MSGFMT} --check-format -o f-c-2-$n.mo f-c-2-$n.po; then
    291       :
    292     else
    293       fail=yes
    294     fi
    295   else
    296     ${MSGFMT} --check-format -o f-c-2-$n.mo f-c-2-$n.po 2> /dev/null
    297     if test $? = 1; then
    298       :
    299     else
    300       fail=yes
    301     fi
    302   fi
    303   if test -n "$fail"; then
    304     echo "Format string checking error:" 1>&2
    305     cat f-c-2-$n.po 1>&2
    306     exit 1
    307   fi
    308   rm -f f-c-2-$n.po f-c-2-$n.mo
    309 done < f-c-2.data
    310 
    311 rm -fr $tmpfiles
    312 
    313 exit 0
    314