Home | History | Annotate | Line # | Download | only in tests
format-awk-1 revision 1.1.1.1
      1  1.1  christos #! /bin/sh
      2  1.1  christos 
      3  1.1  christos # Test recognition of awk 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-a-1.data"
      9  1.1  christos cat <<\EOF > f-a-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 integer argument
     17  1.1  christos "abc%i"
     18  1.1  christos # Valid: one integer argument
     19  1.1  christos "abc%d"
     20  1.1  christos # Valid: one integer argument
     21  1.1  christos "abc%o"
     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%x"
     26  1.1  christos # Valid: one integer argument
     27  1.1  christos "abc%X"
     28  1.1  christos # Valid: one floating-point argument
     29  1.1  christos "abc%e"
     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%f"
     34  1.1  christos # Valid: one floating-point argument
     35  1.1  christos "abc%g"
     36  1.1  christos # Valid: one floating-point argument
     37  1.1  christos "abc%G"
     38  1.1  christos # Valid: one argument with flags
     39  1.1  christos "abc%0#g"
     40  1.1  christos # Valid: one argument with width
     41  1.1  christos "abc%2g"
     42  1.1  christos # Valid: one argument with width
     43  1.1  christos "abc%*g"
     44  1.1  christos # Valid: one argument with precision
     45  1.1  christos "abc%.4g"
     46  1.1  christos # Valid: one argument with precision
     47  1.1  christos "abc%.*g"
     48  1.1  christos # Valid: one argument with width and precision
     49  1.1  christos "abc%14.4g"
     50  1.1  christos # Valid: one argument with width and precision
     51  1.1  christos "abc%14.*g"
     52  1.1  christos # Valid: one argument with width and precision
     53  1.1  christos "abc%*.4g"
     54  1.1  christos # Valid: one argument with width and precision
     55  1.1  christos "abc%*.*g"
     56  1.1  christos # Invalid: unterminated
     57  1.1  christos "abc%"
     58  1.1  christos # Invalid: unknown format specifier
     59  1.1  christos "abc%y"
     60  1.1  christos # Invalid: unknown format specifier
     61  1.1  christos "abc%F"
     62  1.1  christos # Invalid: flags after width
     63  1.1  christos "abc%*0g"
     64  1.1  christos # Invalid: twice precision
     65  1.1  christos "abc%.4.2g"
     66  1.1  christos # Valid: three arguments
     67  1.1  christos "abc%d%u%u"
     68  1.1  christos # Valid: a numbered argument
     69  1.1  christos "abc%1$d"
     70  1.1  christos # Invalid: zero
     71  1.1  christos "abc%0$d"
     72  1.1  christos # Valid: two-digit numbered arguments
     73  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"
     74  1.1  christos # Invalid: unterminated number
     75  1.1  christos "abc%1"
     76  1.1  christos # Invalid: flags before number
     77  1.1  christos "abc%+1$d"
     78  1.1  christos # Valid: three arguments, two with same number
     79  1.1  christos "abc%1$4x,%2$c,%1$u"
     80  1.1  christos # Invalid: argument with conflicting types
     81  1.1  christos "abc%1$4x,%2$c,%1$s"
     82  1.1  christos # Valid: no conflict
     83  1.1  christos "abc%1$4x,%2$c,%1$u"
     84  1.1  christos # Invalid: mixing of numbered and unnumbered arguments
     85  1.1  christos "abc%d%2$x"
     86  1.1  christos # Valid: numbered argument with constant precision
     87  1.1  christos "abc%1$.9x"
     88  1.1  christos # Invalid: mixing of numbered and unnumbered arguments
     89  1.1  christos "abc%1$.*x"
     90  1.1  christos # Valid: missing non-final argument
     91  1.1  christos "abc%2$x%3$s"
     92  1.1  christos # Valid: permutation
     93  1.1  christos "abc%2$ddef%1$d"
     94  1.1  christos # Valid: multiple uses of same argument
     95  1.1  christos "abc%2$xdef%1$sghi%2$x"
     96  1.1  christos # Valid: one argument with width
     97  1.1  christos "abc%2$#*1$g"
     98  1.1  christos # Valid: one argument with width and precision
     99  1.1  christos "abc%3$*2$.*1$g"
    100  1.1  christos # Invalid: zero
    101  1.1  christos "abc%2$*0$.*1$g"
    102  1.1  christos EOF
    103  1.1  christos 
    104  1.1  christos : ${XGETTEXT=xgettext}
    105  1.1  christos n=0
    106  1.1  christos while read comment; do
    107  1.1  christos   read string
    108  1.1  christos   n=`expr $n + 1`
    109  1.1  christos   tmpfiles="$tmpfiles f-a-1-$n.in f-a-1-$n.po"
    110  1.1  christos   cat <<EOF > f-a-1-$n.in
    111  1.1  christos dcgettext(${string});
    112  1.1  christos EOF
    113  1.1  christos   ${XGETTEXT} -L awk -o f-a-1-$n.po f-a-1-$n.in || exit 1
    114  1.1  christos   test -f f-a-1-$n.po || exit 1
    115  1.1  christos   fail=
    116  1.1  christos   if echo "$comment" | grep 'Valid:' > /dev/null; then
    117  1.1  christos     if grep awk-format f-a-1-$n.po > /dev/null; then
    118  1.1  christos       :
    119  1.1  christos     else
    120  1.1  christos       fail=yes
    121  1.1  christos     fi
    122  1.1  christos   else
    123  1.1  christos     if grep awk-format f-a-1-$n.po > /dev/null; then
    124  1.1  christos       fail=yes
    125  1.1  christos     else
    126  1.1  christos       :
    127  1.1  christos     fi
    128  1.1  christos   fi
    129  1.1  christos   if test -n "$fail"; then
    130  1.1  christos     echo "Format string recognition error:" 1>&2
    131  1.1  christos     cat f-a-1-$n.in 1>&2
    132  1.1  christos     echo "Got:" 1>&2
    133  1.1  christos     cat f-a-1-$n.po 1>&2
    134  1.1  christos     exit 1
    135  1.1  christos   fi
    136  1.1  christos   rm -f f-a-1-$n.in f-a-1-$n.po
    137  1.1  christos done < f-a-1.data
    138  1.1  christos 
    139  1.1  christos rm -fr $tmpfiles
    140  1.1  christos 
    141  1.1  christos exit 0
    142