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