Home | History | Annotate | Line # | Download | only in tests
format-gcc-internal-1 revision 1.1.1.1
      1  1.1  christos #! /bin/sh
      2  1.1  christos 
      3  1.1  christos # Test recognition of GCC internal 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-gi-1.data"
      9  1.1  christos cat <<\EOF > f-gi-1.data
     10  1.1  christos # Valid: no argument
     11  1.1  christos "abc%%"
     12  1.1  christos # Valid: no argument
     13  1.1  christos "abc%<"
     14  1.1  christos # Valid: no argument
     15  1.1  christos "abc%>"
     16  1.1  christos # Valid: no argument
     17  1.1  christos "abc%'"
     18  1.1  christos # Valid: no argument
     19  1.1  christos "abc%m"
     20  1.1  christos # Valid: one character argument
     21  1.1  christos "abc%c"
     22  1.1  christos # Valid: one string argument
     23  1.1  christos "abc%s"
     24  1.1  christos # Valid: one integer argument
     25  1.1  christos "abc%i"
     26  1.1  christos # Valid: one integer argument
     27  1.1  christos "abc%d"
     28  1.1  christos # Valid: one integer argument
     29  1.1  christos "abc%o"
     30  1.1  christos # Valid: one integer argument
     31  1.1  christos "abc%u"
     32  1.1  christos # Valid: one integer argument
     33  1.1  christos "abc%x"
     34  1.1  christos # Valid: one integer and one string argument
     35  1.1  christos "abc%.*s"
     36  1.1  christos # Valid: one pointer argument
     37  1.1  christos "abc%p"
     38  1.1  christos # Valid: one pointer argument
     39  1.1  christos "abc%H"
     40  1.1  christos # Valid: one pointer argument
     41  1.1  christos "%J"
     42  1.1  christos # Valid: %J not at start
     43  1.1  christos "abc%J"
     44  1.1  christos # Valid: %J with flags
     45  1.1  christos "%qJ"
     46  1.1  christos # Valid: one pointer argument
     47  1.1  christos "abc%D"
     48  1.1  christos # Valid: one pointer argument
     49  1.1  christos "abc%F"
     50  1.1  christos # Valid: one pointer argument
     51  1.1  christos "abc%T"
     52  1.1  christos # Valid: one pointer argument
     53  1.1  christos "abc%A"
     54  1.1  christos # Valid: one pointer argument
     55  1.1  christos "abc%C"
     56  1.1  christos # Valid: one pointer argument
     57  1.1  christos "abc%E"
     58  1.1  christos # Valid: one pointer argument
     59  1.1  christos "abc%L"
     60  1.1  christos # Valid: one pointer argument
     61  1.1  christos "abc%O"
     62  1.1  christos # Valid: one pointer argument
     63  1.1  christos "abc%P"
     64  1.1  christos # Valid: one pointer argument
     65  1.1  christos "abc%Q"
     66  1.1  christos # Valid: one pointer argument
     67  1.1  christos "abc%V"
     68  1.1  christos # Valid: one argument with flags
     69  1.1  christos "abc%qdef"
     70  1.1  christos # Valid: one argument with flags
     71  1.1  christos "abc%+#Ag"
     72  1.1  christos # Valid: one argument with size specifier
     73  1.1  christos "abc%li"
     74  1.1  christos # Valid: one argument with size specifier
     75  1.1  christos "abc%lli"
     76  1.1  christos # Invalid: one argument with invalid size specifier
     77  1.1  christos "abc%llli"
     78  1.1  christos # Valid: one argument with size specifier
     79  1.1  christos "abc%wi"
     80  1.1  christos # Invalid: unterminated
     81  1.1  christos "abc%"
     82  1.1  christos # Invalid: unknown format specifier
     83  1.1  christos "abc%y"
     84  1.1  christos # Invalid: precision with non-string
     85  1.1  christos "abc%.*c"
     86  1.1  christos # Invalid: twice precision
     87  1.1  christos "abc%.*.*s"
     88  1.1  christos # Valid: three arguments
     89  1.1  christos "abc%d%u%u"
     90  1.1  christos # Valid: a numbered argument
     91  1.1  christos "abc%1$d"
     92  1.1  christos # Invalid: zero
     93  1.1  christos "abc%0$d"
     94  1.1  christos # Valid: two-digit numbered arguments
     95  1.1  christos "abc%11$def%10$dgh%9$dij%8$dkl%7$dmn%6$dop%5$dqr%4$dst%3$duv%2$dwx%1$dyz"
     96  1.1  christos # Invalid: unterminated number
     97  1.1  christos "abc%1"
     98  1.1  christos # Invalid: flags before number
     99  1.1  christos "abc%+1$d"
    100  1.1  christos # Valid: three arguments, two with same number
    101  1.1  christos "abc%1$x,%2$c,%1$u"
    102  1.1  christos # Invalid: argument with conflicting types
    103  1.1  christos "abc%1$x,%2$c,%1$s"
    104  1.1  christos # Valid: no conflict
    105  1.1  christos "abc%1$x,%2$c,%1$u"
    106  1.1  christos # Invalid: mixing of numbered and unnumbered arguments
    107  1.1  christos "abc%d%2$x"
    108  1.1  christos # Valid: numbered argument with constant precision
    109  1.1  christos "abc%1$.9s"
    110  1.1  christos # Invalid: mixing of numbered and unnumbered arguments
    111  1.1  christos "abc%1$.*s"
    112  1.1  christos # Valid: missing non-final argument
    113  1.1  christos "abc%2$x%3$s"
    114  1.1  christos # Valid: permutation
    115  1.1  christos "abc%2$ddef%1$d"
    116  1.1  christos # Valid: multiple uses of same argument
    117  1.1  christos "abc%2$xdef%1$sghi%2$x"
    118  1.1  christos # Valid: one argument with precision
    119  1.1  christos "abc%2$#.*1$s"
    120  1.1  christos # Invalid: non-string argument with precision
    121  1.1  christos "abc%2$#.*1$d"
    122  1.1  christos # Invalid: one argument with width
    123  1.1  christos "abc%2$#*1$s"
    124  1.1  christos # Invalid: one argument with width and precision
    125  1.1  christos "abc%3$*2$.*1$s"
    126  1.1  christos # Invalid: zero
    127  1.1  christos "abc%1$#.*0$s"
    128  1.1  christos EOF
    129  1.1  christos 
    130  1.1  christos : ${XGETTEXT=xgettext}
    131  1.1  christos n=0
    132  1.1  christos while read comment; do
    133  1.1  christos   read string
    134  1.1  christos   n=`expr $n + 1`
    135  1.1  christos   tmpfiles="$tmpfiles f-gi-1-$n.in f-gi-1-$n.po"
    136  1.1  christos   cat <<EOF > f-gi-1-$n.in
    137  1.1  christos gettext(${string});
    138  1.1  christos EOF
    139  1.1  christos   ${XGETTEXT} -L GCC-source -o f-gi-1-$n.po f-gi-1-$n.in || exit 1
    140  1.1  christos   test -f f-gi-1-$n.po || exit 1
    141  1.1  christos   fail=
    142  1.1  christos   if echo "$comment" | grep 'Valid:' > /dev/null; then
    143  1.1  christos     if grep gcc-internal-format f-gi-1-$n.po > /dev/null; then
    144  1.1  christos       :
    145  1.1  christos     else
    146  1.1  christos       fail=yes
    147  1.1  christos     fi
    148  1.1  christos   else
    149  1.1  christos     if grep gcc-internal-format f-gi-1-$n.po > /dev/null; then
    150  1.1  christos       fail=yes
    151  1.1  christos     else
    152  1.1  christos       :
    153  1.1  christos     fi
    154  1.1  christos   fi
    155  1.1  christos   if test -n "$fail"; then
    156  1.1  christos     echo "Format string recognition error:" 1>&2
    157  1.1  christos     cat f-gi-1-$n.in 1>&2
    158  1.1  christos     echo "Got:" 1>&2
    159  1.1  christos     cat f-gi-1-$n.po 1>&2
    160  1.1  christos     exit 1
    161  1.1  christos   fi
    162  1.1  christos   rm -f f-gi-1-$n.in f-gi-1-$n.po
    163  1.1  christos done < f-gi-1.data
    164  1.1  christos 
    165  1.1  christos rm -fr $tmpfiles
    166  1.1  christos 
    167  1.1  christos exit 0
    168