1 #! /bin/sh 2 3 # Test checking of Python format strings. 4 5 tmpfiles="" 6 trap 'rm -fr $tmpfiles' 1 2 3 15 7 8 tmpfiles="$tmpfiles f-p-2.data" 9 cat <<\EOF > f-p-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, with different widths 17 msgid "abc%2sdef" 18 msgstr "xyz%3s" 19 # Invalid: too few arguments 20 msgid "abc%sdef%u" 21 msgstr "xyz%s" 22 # Invalid: too many arguments 23 msgid "abc%udef" 24 msgstr "xyz%uvw%c" 25 # Valid: same named arguments, with different widths 26 msgid "abc%(date)5s%(time)4s" 27 msgstr "xyz%(date)4s%(time)5s" 28 # Valid: permutation 29 msgid "abc%(3)d%(1)c%(2)sdef" 30 msgstr "xyz%(2)s%(1)c%(3)d" 31 # Invalid: missing argument 32 msgid "abc%(2)sdef%(1)u" 33 msgstr "xyz%(1)u" 34 # Invalid: missing argument 35 msgid "abc%(1)sdef%(2)u" 36 msgstr "xyz%(2)u" 37 # Invalid: added argument 38 msgid "abc%(foo)udef" 39 msgstr "xyz%(foo)uvw%(char)c" 40 # Invalid: added argument 41 msgid "abc%(foo)udef" 42 msgstr "xyz%(foo)uvw%(zoo)c" 43 # Invalid: unnamed vs. named arguments 44 msgid "abc%sdef" 45 msgstr "xyz%(value)s" 46 # Invalid: named vs. unnamed arguments 47 msgid "abc%(value)sdef" 48 msgstr "xyz%s" 49 # Valid: type compatibility 50 msgid "abc%s" 51 msgstr "xyz%r" 52 # Valid: type compatibility 53 msgid "abc%r" 54 msgstr "xyz%s" 55 # Valid: type compatibility 56 msgid "abc%i" 57 msgstr "xyz%d" 58 # Valid: type compatibility 59 msgid "abc%i" 60 msgstr "xyz%u" 61 # Valid: type compatibility 62 msgid "abc%i" 63 msgstr "xyz%o" 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%s" 93 msgstr "xyz%i" 94 # Invalid: type incompatibility 95 msgid "abc%s" 96 msgstr "xyz%e" 97 # Invalid: type incompatibility 98 msgid "abc%i" 99 msgstr "xyz%e" 100 # Invalid: type incompatibility for width 101 msgid "abc%g%*g" 102 msgstr "xyz%*g%g" 103 EOF 104 105 : ${MSGFMT=msgfmt} 106 n=0 107 while read comment; do 108 read msgid_line 109 read msgstr_line 110 n=`expr $n + 1` 111 tmpfiles="$tmpfiles f-p-2-$n.po f-p-2-$n.mo" 112 cat <<EOF > f-p-2-$n.po 113 #, python-format 114 ${msgid_line} 115 ${msgstr_line} 116 EOF 117 fail= 118 if echo "$comment" | grep 'Valid:' > /dev/null; then 119 if ${MSGFMT} --check-format -o f-p-2-$n.mo f-p-2-$n.po; then 120 : 121 else 122 fail=yes 123 fi 124 else 125 ${MSGFMT} --check-format -o f-p-2-$n.mo f-p-2-$n.po 2> /dev/null 126 if test $? = 1; then 127 : 128 else 129 fail=yes 130 fi 131 fi 132 if test -n "$fail"; then 133 echo "Format string checking error:" 1>&2 134 cat f-p-2-$n.po 1>&2 135 exit 1 136 fi 137 rm -f f-p-2-$n.po f-p-2-$n.mo 138 done < f-p-2.data 139 140 rm -fr $tmpfiles 141 142 exit 0 143