Home | History | Annotate | Line # | Download | only in tests
format-pascal-2 revision 1.1.1.1
      1 #! /bin/sh
      2 
      3 # Test checking of Object Pascal format strings.
      4 
      5 tmpfiles=""
      6 trap 'rm -fr $tmpfiles' 1 2 3 15
      7 
      8 tmpfiles="$tmpfiles f-op-2.data"
      9 cat <<\EOF > f-op-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%0:s%1:g"
     25 # Valid: permutation
     26 msgid  "abc%s%g%cdef"
     27 msgstr "xyz%2:c%1:g%0:s"
     28 # Invalid: too few arguments
     29 msgid  "abc%1:xdef%0:s"
     30 msgstr "xyz%0:s"
     31 # Invalid: too few arguments
     32 msgid  "abc%sdef%x"
     33 msgstr "xyz%s"
     34 # Invalid: too many arguments
     35 msgid  "abc%xdef"
     36 msgstr "xyz%xvw%p"
     37 # Valid: same numbered arguments, with different widths
     38 msgid  "abc%1:5s%0:4s"
     39 msgstr "xyz%1:4s%0:5s"
     40 # Invalid: missing argument
     41 msgid  "abc%1:sdef%0:x"
     42 msgstr "xyz%0:x"
     43 # Invalid: missing argument
     44 msgid  "abc%0:sdef%1:x"
     45 msgstr "xyz%1:x"
     46 # Invalid: added argument
     47 msgid  "abc%0:xdef"
     48 msgstr "xyz%0:xvw%1:p"
     49 # Valid: type compatibility
     50 msgid  "abc%e"
     51 msgstr "xyz%f"
     52 # Valid: type compatibility
     53 msgid  "abc%e"
     54 msgstr "xyz%g"
     55 # Valid: type compatibility
     56 msgid  "abc%e"
     57 msgstr "xyz%n"
     58 # Valid: type compatibility
     59 msgid  "abc%e"
     60 msgstr "xyz%m"
     61 # Invalid: type incompatibility
     62 msgid  "abc%d"
     63 msgstr "xyz%e"
     64 # Invalid: type incompatibility
     65 msgid  "abc%d"
     66 msgstr "xyz%s"
     67 # Invalid: type incompatibility
     68 msgid  "abc%d"
     69 msgstr "xyz%p"
     70 # Invalid: type incompatibility
     71 msgid  "abc%d"
     72 msgstr "xyz%x"
     73 # Invalid: type incompatibility
     74 msgid  "abc%e"
     75 msgstr "xyz%s"
     76 # Invalid: type incompatibility
     77 msgid  "abc%e"
     78 msgstr "xyz%p"
     79 # Invalid: type incompatibility
     80 msgid  "abc%e"
     81 msgstr "xyz%x"
     82 # Invalid: type incompatibility
     83 msgid  "abc%s"
     84 msgstr "xyz%p"
     85 # Invalid: type incompatibility
     86 msgid  "abc%s"
     87 msgstr "xyz%x"
     88 # Invalid: type incompatibility
     89 msgid  "abc%p"
     90 msgstr "xyz%x"
     91 # Invalid: type incompatibility for width
     92 msgid  "abc%g%*g"
     93 msgstr "xyz%*g%g"
     94 EOF
     95 
     96 : ${MSGFMT=msgfmt}
     97 n=0
     98 while read comment; do
     99   read msgid_line
    100   read msgstr_line
    101   n=`expr $n + 1`
    102   tmpfiles="$tmpfiles f-op-2-$n.po f-op-2-$n.mo"
    103   cat <<EOF > f-op-2-$n.po
    104 #, object-pascal-format
    105 ${msgid_line}
    106 ${msgstr_line}
    107 EOF
    108   fail=
    109   if echo "$comment" | grep 'Valid:' > /dev/null; then
    110     if ${MSGFMT} --check-format -o f-op-2-$n.mo f-op-2-$n.po; then
    111       :
    112     else
    113       fail=yes
    114     fi
    115   else
    116     ${MSGFMT} --check-format -o f-op-2-$n.mo f-op-2-$n.po 2> /dev/null
    117     if test $? = 1; then
    118       :
    119     else
    120       fail=yes
    121     fi
    122   fi
    123   if test -n "$fail"; then
    124     echo "Format string checking error:" 1>&2
    125     cat f-op-2-$n.po 1>&2
    126     exit 1
    127   fi
    128   rm -f f-op-2-$n.po f-op-2-$n.mo
    129 done < f-op-2.data
    130 
    131 rm -fr $tmpfiles
    132 
    133 exit 0
    134