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