Home | History | Annotate | Line # | Download | only in tests
format-boost-2 revision 1.1
      1 #! /bin/sh
      2 
      3 # Test checking of Boost format strings.
      4 
      5 tmpfiles=""
      6 trap 'rm -fr $tmpfiles' 1 2 3 15
      7 
      8 tmpfiles="$tmpfiles f-bo-2.data"
      9 cat <<\EOF > f-bo-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, despite different syntax
     20 msgid  "abc%s%gdef"
     21 msgstr "xyz%|s|%|g|"
     22 # Valid: same arguments, with different widths
     23 msgid  "abc%2sdef"
     24 msgstr "xyz%3s"
     25 # Valid: same arguments but in numbered syntax
     26 msgid  "abc%s%gdef"
     27 msgstr "xyz%1$s%2$g"
     28 # Valid: same arguments but in numbered syntax
     29 msgid  "abc%s%gdef"
     30 msgstr "xyz%1%%2$g"
     31 # Valid: permutation
     32 msgid  "abc%s%g%cdef"
     33 msgstr "xyz%3$c%2$g%1$s"
     34 # Invalid: too few arguments
     35 msgid  "abc%2$udef%1$s"
     36 msgstr "xyz%1$s"
     37 # Invalid: too few arguments
     38 msgid  "abc%sdef%u"
     39 msgstr "xyz%s"
     40 # Invalid: too many arguments
     41 msgid  "abc%udef"
     42 msgstr "xyz%uvw%c"
     43 # Valid: same numbered arguments, with different widths
     44 msgid  "abc%2$5s%1$4s"
     45 msgstr "xyz%2$4s%1$5s"
     46 # Invalid: missing argument
     47 msgid  "abc%2$sdef%1$u"
     48 msgstr "xyz%1$u"
     49 # Invalid: missing argument
     50 msgid  "abc%1$sdef%2$u"
     51 msgstr "xyz%2$u"
     52 # Invalid: added argument
     53 msgid  "abc%1$udef"
     54 msgstr "xyz%1$uvw%2$c"
     55 # Valid: type compatibility
     56 msgid  "abc%i"
     57 msgstr "xyz%d"
     58 # Valid: type compatibility
     59 msgid  "abc%i"
     60 msgstr "xyz%o"
     61 # Valid: type compatibility
     62 msgid  "abc%i"
     63 msgstr "xyz%u"
     64 # Valid: type compatibility
     65 msgid  "abc%i"
     66 msgstr "xyz%x"
     67 # Valid: type compatibility
     68 msgid  "abc%i"
     69 msgstr "xyz%X"
     70 # Valid: type compatibility
     71 msgid  "abc%e"
     72 msgstr "xyz%E"
     73 # Valid: type compatibility
     74 msgid  "abc%e"
     75 msgstr "xyz%f"
     76 # Valid: type compatibility
     77 msgid  "abc%e"
     78 msgstr "xyz%g"
     79 # Valid: type compatibility
     80 msgid  "abc%e"
     81 msgstr "xyz%G"
     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%e"
     91 # Invalid: type incompatibility
     92 msgid  "abc%c"
     93 msgstr "xyz%p"
     94 # Invalid: different argument count
     95 msgid  "abc%c"
     96 msgstr "xyz%n"
     97 # Invalid: type incompatibility
     98 msgid  "abc%s"
     99 msgstr "xyz%i"
    100 # Invalid: type incompatibility
    101 msgid  "abc%s"
    102 msgstr "xyz%e"
    103 # Invalid: type incompatibility
    104 msgid  "abc%s"
    105 msgstr "xyz%p"
    106 # Invalid: different argument count
    107 msgid  "abc%s"
    108 msgstr "xyz%n"
    109 # Invalid: type incompatibility
    110 msgid  "abc%i"
    111 msgstr "xyz%e"
    112 # Invalid: type incompatibility
    113 msgid  "abc%i"
    114 msgstr "xyz%p"
    115 # Invalid: different argument count
    116 msgid  "abc%i"
    117 msgstr "xyz%n"
    118 # Invalid: type incompatibility
    119 msgid  "abc%e"
    120 msgstr "xyz%p"
    121 # Invalid: different argument count
    122 msgid  "abc%e"
    123 msgstr "xyz%n"
    124 # Invalid: different argument count
    125 msgid  "abc%p"
    126 msgstr "xyz%n"
    127 # Valid: size is ignored
    128 msgid  "abc%i"
    129 msgstr "xyz%hhi"
    130 # Valid: size is ignored
    131 msgid  "abc%i"
    132 msgstr "xyz%hi"
    133 # Valid: size is ignored
    134 msgid  "abc%i"
    135 msgstr "xyz%li"
    136 # Valid: size is ignored
    137 msgid  "abc%i"
    138 msgstr "xyz%lli"
    139 # Valid: size is ignored
    140 msgid  "abc%i"
    141 msgstr "xyz%Li"
    142 # Valid: size is ignored
    143 msgid  "abc%hhi"
    144 msgstr "xyz%hi"
    145 # Valid: size is ignored
    146 msgid  "abc%hhi"
    147 msgstr "xyz%li"
    148 # Valid: size is ignored
    149 msgid  "abc%hhi"
    150 msgstr "xyz%lli"
    151 # Valid: size is ignored
    152 msgid  "abc%hhi"
    153 msgstr "xyz%Li"
    154 # Valid: size is ignored
    155 msgid  "abc%hi"
    156 msgstr "xyz%li"
    157 # Valid: size is ignored
    158 msgid  "abc%hi"
    159 msgstr "xyz%lli"
    160 # Valid: size is ignored
    161 msgid  "abc%hi"
    162 msgstr "xyz%Li"
    163 # Valid: size is ignored
    164 msgid  "abc%li"
    165 msgstr "xyz%lli"
    166 # Valid: size is ignored
    167 msgid  "abc%li"
    168 msgstr "xyz%Li"
    169 # Invalid: type incompatibility for width
    170 msgid  "abc%g%*g"
    171 msgstr "xyz%*g%g"
    172 EOF
    173 
    174 : ${MSGFMT=msgfmt}
    175 n=0
    176 while read comment; do
    177   read msgid_line
    178   read msgstr_line
    179   n=`expr $n + 1`
    180   tmpfiles="$tmpfiles f-bo-2-$n.po f-bo-2-$n.mo"
    181   cat <<EOF > f-bo-2-$n.po
    182 #, boost-format
    183 ${msgid_line}
    184 ${msgstr_line}
    185 EOF
    186   fail=
    187   if echo "$comment" | grep 'Valid:' > /dev/null; then
    188     if ${MSGFMT} --check-format -o f-bo-2-$n.mo f-bo-2-$n.po; then
    189       :
    190     else
    191       fail=yes
    192     fi
    193   else
    194     ${MSGFMT} --check-format -o f-bo-2-$n.mo f-bo-2-$n.po 2> /dev/null
    195     if test $? = 1; then
    196       :
    197     else
    198       fail=yes
    199     fi
    200   fi
    201   if test -n "$fail"; then
    202     echo "Format string checking error:" 1>&2
    203     cat f-bo-2-$n.po 1>&2
    204     exit 1
    205   fi
    206   rm -f f-bo-2-$n.po f-bo-2-$n.mo
    207 done < f-bo-2.data
    208 
    209 rm -fr $tmpfiles
    210 
    211 exit 0
    212