1 1.1 christos #! /bin/sh 2 1.1 christos 3 1.1 christos # Test recognition 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-1.data" 9 1.1 christos cat <<\EOF > f-p-1.data 10 1.1 christos # Valid: no argument 11 1.1 christos "abc%%" 12 1.1 christos # Valid: one character argument 13 1.1 christos "abc%c" 14 1.1 christos # Valid: one string argument 15 1.1 christos "abc%s" 16 1.1 christos # Valid: one string argument 17 1.1 christos "abc%r" 18 1.1 christos # Valid: one integer argument 19 1.1 christos "abc%i" 20 1.1 christos # Valid: one integer argument 21 1.1 christos "abc%d" 22 1.1 christos # Valid: one integer argument 23 1.1 christos "abc%u" 24 1.1 christos # Valid: one integer argument 25 1.1 christos "abc%o" 26 1.1 christos # Valid: one integer argument 27 1.1 christos "abc%x" 28 1.1 christos # Valid: one integer argument 29 1.1 christos "abc%X" 30 1.1 christos # Valid: one floating-point argument 31 1.1 christos "abc%e" 32 1.1 christos # Valid: one floating-point argument 33 1.1 christos "abc%E" 34 1.1 christos # Valid: one floating-point argument 35 1.1 christos "abc%f" 36 1.1 christos # Valid: one floating-point argument 37 1.1 christos "abc%g" 38 1.1 christos # Valid: one floating-point argument 39 1.1 christos "abc%G" 40 1.1 christos # Valid: one argument with flags 41 1.1 christos "abc%0#g" 42 1.1 christos # Valid: one argument with width 43 1.1 christos "abc%2g" 44 1.1 christos # Valid: one argument with width 45 1.1 christos "abc%*g" 46 1.1 christos # Valid: one argument with precision 47 1.1 christos "abc%.4g" 48 1.1 christos # Valid: one argument with precision 49 1.1 christos "abc%.*g" 50 1.1 christos # Valid: one argument with width and precision 51 1.1 christos "abc%14.4g" 52 1.1 christos # Valid: one argument with width and precision 53 1.1 christos "abc%14.*g" 54 1.1 christos # Valid: one argument with width and precision 55 1.1 christos "abc%*.4g" 56 1.1 christos # Valid: one argument with width and precision 57 1.1 christos "abc%*.*g" 58 1.1 christos # Valid: one argument with size specifier 59 1.1 christos "abc%hi" 60 1.1 christos # Valid: one argument with size specifier 61 1.1 christos "abc%li" 62 1.1 christos # Valid: one argument with size specifier 63 1.1 christos "abc%Li" 64 1.1 christos # Invalid: unterminated 65 1.1 christos "abc%" 66 1.1 christos # Invalid: unknown format specifier 67 1.1 christos "abc%y" 68 1.1 christos # Invalid: flags after width 69 1.1 christos "abc%*0g" 70 1.1 christos # Invalid: twice precision 71 1.1 christos "abc%.4.2g" 72 1.1 christos # Invalid: two size specifiers 73 1.1 christos "abc%lli" 74 1.1 christos # Valid: three arguments 75 1.1 christos "abc%d%u%u" 76 1.1 christos # Valid: a named argument 77 1.1 christos "abc%(value)d" 78 1.1 christos # Valid: an empty name 79 1.1 christos "abc%()d" 80 1.1 christos # Invalid: unterminated name 81 1.1 christos "abc%(value" 82 1.1 christos # Valid: ignored named argument 83 1.1 christos "abc%(dummy)%" 84 1.1 christos # Invalid: flags before name 85 1.1 christos "abc%0(value)d" 86 1.1 christos # Valid: three arguments, two with equal names 87 1.1 christos "abc%(addr)4x,%(char)c,%(addr)u" 88 1.1 christos # Invalid: argument with conflicting types 89 1.1 christos "abc%(addr)4x,%(char)c,%(addr)s" 90 1.1 christos # Valid: no conflict 91 1.1 christos "abc%(addr)r,%(addr)s" 92 1.1 christos # Invalid: mixing of named and unnamed arguments 93 1.1 christos "abc%d%(addr)x" 94 1.1 christos # Valid: named argument with constant precision 95 1.1 christos "abc%(addr).9x" 96 1.1 christos # Invalid: mixing of named and unnamed arguments 97 1.1 christos "abc%(addr).*x" 98 1.1 christos EOF 99 1.1 christos 100 1.1 christos tmpfiles="$tmpfiles f-p-1.err" 101 1.1 christos : ${XGETTEXT=xgettext} 102 1.1 christos n=0 103 1.1 christos while read comment; do 104 1.1 christos read string 105 1.1 christos n=`expr $n + 1` 106 1.1 christos tmpfiles="$tmpfiles f-p-1-$n.in f-p-1-$n.po" 107 1.1 christos cat <<EOF > f-p-1-$n.in 108 1.1 christos gettext(${string}); 109 1.1 christos EOF 110 1.1 christos # Hide xgettext's "The translator cannot reorder the arguments." warnings. 111 1.1 christos ${XGETTEXT} -L Python -o f-p-1-$n.po f-p-1-$n.in 2> f-p-1.err \ 112 1.1 christos || { cat f-p-1.err 1>&2; exit 1; } 113 1.1 christos test -f f-p-1-$n.po || exit 1 114 1.1 christos fail= 115 1.1 christos if echo "$comment" | grep 'Valid:' > /dev/null; then 116 1.1 christos if grep python-format f-p-1-$n.po > /dev/null; then 117 1.1 christos : 118 1.1 christos else 119 1.1 christos fail=yes 120 1.1 christos fi 121 1.1 christos else 122 1.1 christos if grep python-format f-p-1-$n.po > /dev/null; then 123 1.1 christos fail=yes 124 1.1 christos else 125 1.1 christos : 126 1.1 christos fi 127 1.1 christos fi 128 1.1 christos if test -n "$fail"; then 129 1.1 christos echo "Format string recognition error:" 1>&2 130 1.1 christos cat f-p-1-$n.in 1>&2 131 1.1 christos echo "Got:" 1>&2 132 1.1 christos cat f-p-1-$n.po 1>&2 133 1.1 christos exit 1 134 1.1 christos fi 135 1.1 christos rm -f f-p-1-$n.in f-p-1-$n.po 136 1.1 christos done < f-p-1.data 137 1.1 christos 138 1.1 christos rm -fr $tmpfiles 139 1.1 christos 140 1.1 christos exit 0 141