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