1 #! /bin/sh 2 3 # Test checking of Shell format strings. 4 5 tmpfiles="" 6 trap 'rm -fr $tmpfiles' 1 2 3 15 7 8 tmpfiles="$tmpfiles f-sh-2.data" 9 cat <<\EOF > f-sh-2.data 10 # Invalid: invalid msgstr 11 msgid "abc$file" 12 msgstr "xyz$file$" 13 # Valid: same arguments, permutation 14 msgid "abc$file in $dir" 15 msgstr "xyz$dir o $file" 16 # Invalid: missing argument 17 msgid "abc$dir/$file" 18 msgstr "xyz$file" 19 # Invalid: added argument 20 msgid "abc$file" 21 msgstr "xyz$file in $dir" 22 # Valid: braces or not, doesn't matter 23 msgid "abc$file" 24 msgstr "xyz${file}" 25 # Invalid: different default value 26 msgid "abc$file" 27 msgstr "xyz${file-/tmpdir}" 28 EOF 29 30 : ${MSGFMT=msgfmt} 31 n=0 32 while read comment; do 33 read msgid_line 34 read msgstr_line 35 n=`expr $n + 1` 36 tmpfiles="$tmpfiles f-sh-2-$n.po f-sh-2-$n.mo" 37 cat <<EOF > f-sh-2-$n.po 38 #, sh-format 39 ${msgid_line} 40 ${msgstr_line} 41 EOF 42 fail= 43 if echo "$comment" | grep 'Valid:' > /dev/null; then 44 if ${MSGFMT} --check-format -o f-sh-2-$n.mo f-sh-2-$n.po; then 45 : 46 else 47 fail=yes 48 fi 49 else 50 ${MSGFMT} --check-format -o f-sh-2-$n.mo f-sh-2-$n.po 2> /dev/null 51 if test $? = 1; then 52 : 53 else 54 fail=yes 55 fi 56 fi 57 if test -n "$fail"; then 58 echo "Format string checking error:" 1>&2 59 cat f-sh-2-$n.po 1>&2 60 exit 1 61 fi 62 rm -f f-sh-2-$n.po f-sh-2-$n.mo 63 done < f-sh-2.data 64 65 rm -fr $tmpfiles 66 67 exit 0 68