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