Home | History | Annotate | Line # | Download | only in tests
      1 #! /bin/sh
      2 
      3 # Test checking of YCP format strings.
      4 
      5 tmpfiles=""
      6 trap 'rm -fr $tmpfiles' 1 2 3 15
      7 
      8 tmpfiles="$tmpfiles f-y-2.data"
      9 cat <<\EOF > f-y-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%2def"
     18 msgstr "xyz%2"
     19 # Valid: permutation
     20 msgid  "abc%3%1%2def"
     21 msgstr "xyz%2%1%3"
     22 # Invalid: too few arguments
     23 msgid  "abc%2def%1"
     24 msgstr "xyz%1"
     25 # Invalid: too many arguments
     26 msgid  "abc%1def"
     27 msgstr "xyz%1uvw%2"
     28 # Invalid: missing non-final argument
     29 msgid  "abc%2def%1"
     30 msgstr "xyz%2"
     31 # Invalid: added non-final argument
     32 msgid  "abc%2def"
     33 msgstr "xyz%1%2"
     34 EOF
     35 
     36 : ${MSGFMT=msgfmt}
     37 n=0
     38 while read comment; do
     39   read msgid_line
     40   read msgstr_line
     41   n=`expr $n + 1`
     42   tmpfiles="$tmpfiles f-y-2-$n.po f-y-2-$n.mo"
     43   cat <<EOF > f-y-2-$n.po
     44 #, ycp-format
     45 ${msgid_line}
     46 ${msgstr_line}
     47 EOF
     48   fail=
     49   if echo "$comment" | grep 'Valid:' > /dev/null; then
     50     if ${MSGFMT} --check-format -o f-y-2-$n.mo f-y-2-$n.po; then
     51       :
     52     else
     53       fail=yes
     54     fi
     55   else
     56     ${MSGFMT} --check-format -o f-y-2-$n.mo f-y-2-$n.po 2> /dev/null
     57     if test $? = 1; then
     58       :
     59     else
     60       fail=yes
     61     fi
     62   fi
     63   if test -n "$fail"; then
     64     echo "Format string checking error:" 1>&2
     65     cat f-y-2-$n.po 1>&2
     66     exit 1
     67   fi
     68   rm -f f-y-2-$n.po f-y-2-$n.mo
     69 done < f-y-2.data
     70 
     71 rm -fr $tmpfiles
     72 
     73 exit 0
     74