1 #! /bin/sh 2 3 # Test checking of Java format strings. 4 5 tmpfiles="" 6 trap 'rm -fr $tmpfiles' 1 2 3 15 7 8 tmpfiles="$tmpfiles f-cs-2.data" 9 cat <<\EOF > f-cs-2.data 10 # Invalid: invalid msgstr 11 msgid "abc{0}def" 12 msgstr "abc{" 13 # Valid: same arguments 14 msgid "abc{1}def" 15 msgstr "xyz{1}" 16 # Valid: same arguments, differently written 17 msgid "abc{1}def" 18 msgstr "xyz{01}" 19 # Valid: permutation 20 msgid "abc{2}{0}{1}def" 21 msgstr "xyz{1}{0}{2}" 22 # Invalid: too few arguments 23 msgid "abc{1}def{0}" 24 msgstr "xyz{0}" 25 # Invalid: too many arguments 26 msgid "abc{0}def" 27 msgstr "xyz{0}uvw{1}" 28 # Valid: missing non-final argument 29 msgid "abc{1}def{0}" 30 msgstr "xyz{1}" 31 # Valid: added non-final argument 32 msgid "abc{1}def" 33 msgstr "xyz{0}{1}" 34 # Invalid: different number of arguments 35 msgid "abc{500000000}def" 36 msgstr "xyz{500000001}" 37 # Valid: type compatibility 38 msgid "abc{1:X}" 39 msgstr "xyz{1:g}" 40 EOF 41 42 : ${MSGFMT=msgfmt} 43 n=0 44 while read comment; do 45 read msgid_line 46 read msgstr_line 47 n=`expr $n + 1` 48 tmpfiles="$tmpfiles f-cs-2-$n.po f-cs-2-$n.mo" 49 cat <<EOF > f-cs-2-$n.po 50 #, csharp-format 51 ${msgid_line} 52 ${msgstr_line} 53 EOF 54 fail= 55 if echo "$comment" | grep 'Valid:' > /dev/null; then 56 if ${MSGFMT} --check-format -o f-cs-2-$n.mo f-cs-2-$n.po; then 57 : 58 else 59 fail=yes 60 fi 61 else 62 ${MSGFMT} --check-format -o f-cs-2-$n.mo f-cs-2-$n.po 2> /dev/null 63 if test $? = 1; then 64 : 65 else 66 fail=yes 67 fi 68 fi 69 if test -n "$fail"; then 70 echo "Format string checking error:" 1>&2 71 cat f-cs-2-$n.po 1>&2 72 exit 1 73 fi 74 rm -f f-cs-2-$n.po f-cs-2-$n.mo 75 done < f-cs-2.data 76 77 rm -fr $tmpfiles 78 79 exit 0 80