Home | History | Annotate | Line # | Download | only in tests
format-boost-1 revision 1.1.1.1
      1  1.1  christos #! /bin/sh
      2  1.1  christos 
      3  1.1  christos # Test recognition of Boost 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-bo-1.data"
      9  1.1  christos cat <<\EOF > f-bo-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 character argument
     15  1.1  christos "abc%|c|"
     16  1.1  christos # Valid: one string argument
     17  1.1  christos "abc%s"
     18  1.1  christos # Valid: one string argument
     19  1.1  christos "abc%|s|"
     20  1.1  christos # Valid: one integer argument
     21  1.1  christos "abc%i"
     22  1.1  christos # Valid: one integer argument
     23  1.1  christos "abc%|i|"
     24  1.1  christos # Valid: one integer argument
     25  1.1  christos "abc%d"
     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%|o|"
     32  1.1  christos # Valid: one integer argument
     33  1.1  christos "abc%u"
     34  1.1  christos # Valid: one integer argument
     35  1.1  christos "abc%|u|"
     36  1.1  christos # Valid: one integer argument
     37  1.1  christos "abc%x"
     38  1.1  christos # Valid: one integer argument
     39  1.1  christos "abc%|x|"
     40  1.1  christos # Valid: one integer argument
     41  1.1  christos "abc%X"
     42  1.1  christos # Valid: one integer argument
     43  1.1  christos "abc%|X|"
     44  1.1  christos # Valid: one floating-point argument
     45  1.1  christos "abc%e"
     46  1.1  christos # Valid: one floating-point argument
     47  1.1  christos "abc%|e|"
     48  1.1  christos # Valid: one floating-point argument
     49  1.1  christos "abc%E"
     50  1.1  christos # Valid: one floating-point argument
     51  1.1  christos "abc%|E|"
     52  1.1  christos # Valid: one floating-point argument
     53  1.1  christos "abc%f"
     54  1.1  christos # Valid: one floating-point argument
     55  1.1  christos "abc%|f|"
     56  1.1  christos # Valid: one floating-point argument
     57  1.1  christos "abc%g"
     58  1.1  christos # Valid: one floating-point argument
     59  1.1  christos "abc%|g|"
     60  1.1  christos # Valid: one floating-point argument
     61  1.1  christos "abc%G"
     62  1.1  christos # Valid: one floating-point argument
     63  1.1  christos "abc%|G|"
     64  1.1  christos # Valid: one pointer argument
     65  1.1  christos "abc%p"
     66  1.1  christos # Valid: one pointer argument
     67  1.1  christos "abc%|p|"
     68  1.1  christos # Valid: no argument
     69  1.1  christos "abc%n"
     70  1.1  christos # Valid: no argument
     71  1.1  christos "abc%|n|"
     72  1.1  christos # Valid: one argument with flags
     73  1.1  christos "abc%0#g"
     74  1.1  christos # Valid: one argument with flags
     75  1.1  christos "abc%|0#g|"
     76  1.1  christos # Valid: one argument with width
     77  1.1  christos "abc%2g"
     78  1.1  christos # Valid: one argument with width
     79  1.1  christos "abc%|2g|"
     80  1.1  christos # Valid: one argument with width
     81  1.1  christos "abc%*g"
     82  1.1  christos # Valid: one argument with width
     83  1.1  christos "abc%|*g|"
     84  1.1  christos # Valid: one argument with precision
     85  1.1  christos "abc%.4g"
     86  1.1  christos # Valid: one argument with precision
     87  1.1  christos "abc%|.4g|"
     88  1.1  christos # Valid: one argument with precision
     89  1.1  christos "abc%.*g"
     90  1.1  christos # Valid: one argument with precision
     91  1.1  christos "abc%|.*g|"
     92  1.1  christos # Valid: one argument with width and precision
     93  1.1  christos "abc%14.4g"
     94  1.1  christos # Valid: one argument with width and precision
     95  1.1  christos "abc%|14.4g|"
     96  1.1  christos # Valid: one argument with width and precision
     97  1.1  christos "abc%14.*g"
     98  1.1  christos # Valid: one argument with width and precision
     99  1.1  christos "abc%|14.*g|"
    100  1.1  christos # Valid: one argument with width and precision
    101  1.1  christos "abc%*.4g"
    102  1.1  christos # Valid: one argument with width and precision
    103  1.1  christos "abc%|*.4g|"
    104  1.1  christos # Valid: one argument with width and precision
    105  1.1  christos "abc%*.*g"
    106  1.1  christos # Valid: one argument with width and precision
    107  1.1  christos "abc%|*.*g|"
    108  1.1  christos # Valid: one argument with size specifier
    109  1.1  christos "abc%hhi"
    110  1.1  christos # Valid: one argument with size specifier
    111  1.1  christos "abc%|hhi|"
    112  1.1  christos # Valid: one argument with size specifier
    113  1.1  christos "abc%hi"
    114  1.1  christos # Valid: one argument with size specifier
    115  1.1  christos "abc%|hi|"
    116  1.1  christos # Valid: one argument with size specifier
    117  1.1  christos "abc%li"
    118  1.1  christos # Valid: one argument with size specifier
    119  1.1  christos "abc%|li|"
    120  1.1  christos # Valid: one argument with size specifier
    121  1.1  christos "abc%lli"
    122  1.1  christos # Valid: one argument with size specifier
    123  1.1  christos "abc%|lli|"
    124  1.1  christos # Valid: one argument with size specifier
    125  1.1  christos "abc%Lg"
    126  1.1  christos # Valid: one argument with size specifier
    127  1.1  christos "abc%|Lg|"
    128  1.1  christos # Invalid: unknown size specifier
    129  1.1  christos "abc%qi"
    130  1.1  christos # Invalid: unknown size specifier
    131  1.1  christos "abc%|qi|"
    132  1.1  christos # Invalid: unknown size specifier
    133  1.1  christos "abc%ji"
    134  1.1  christos # Invalid: unknown size specifier
    135  1.1  christos "abc%|ji|"
    136  1.1  christos # Invalid: unknown size specifier
    137  1.1  christos "abc%zi"
    138  1.1  christos # Invalid: unknown size specifier
    139  1.1  christos "abc%|zi|"
    140  1.1  christos # Invalid: unterminated
    141  1.1  christos "abc%"
    142  1.1  christos # Invalid: unterminated
    143  1.1  christos "abc%|"
    144  1.1  christos # Invalid: unterminated
    145  1.1  christos "abc%|d"
    146  1.1  christos # Invalid: unknown format specifier
    147  1.1  christos "abc%a"
    148  1.1  christos # Invalid: unknown format specifier
    149  1.1  christos "abc%|a|"
    150  1.1  christos # Invalid: unknown format specifier
    151  1.1  christos "abc%A"
    152  1.1  christos # Invalid: unknown format specifier
    153  1.1  christos "abc%|A|"
    154  1.1  christos # Invalid: unknown format specifier
    155  1.1  christos "abc%F"
    156  1.1  christos # Invalid: unknown format specifier
    157  1.1  christos "abc%|F|"
    158  1.1  christos # Invalid: unknown format specifier
    159  1.1  christos "abc%y"
    160  1.1  christos # Invalid: unknown format specifier
    161  1.1  christos "abc%|y|"
    162  1.1  christos # Invalid: flags after width
    163  1.1  christos "abc%*0g"
    164  1.1  christos # Invalid: flags after width
    165  1.1  christos "abc%|*0g|"
    166  1.1  christos # Invalid: twice precision
    167  1.1  christos "abc%.4.2g"
    168  1.1  christos # Invalid: twice precision
    169  1.1  christos "abc%|.4.2g|"
    170  1.1  christos # Valid: three arguments
    171  1.1  christos "abc%d%u%u"
    172  1.1  christos # Valid: three arguments, mixed syntax
    173  1.1  christos "abc%|d|%u%u"
    174  1.1  christos # Valid: three arguments, mixed syntax
    175  1.1  christos "abc%d%u%|u|"
    176  1.1  christos # Valid: a numbered argument
    177  1.1  christos "abc%1$d"
    178  1.1  christos # Valid: a numbered argument
    179  1.1  christos "abc%|1$d|"
    180  1.1  christos # Valid: a numbered argument
    181  1.1  christos "abc%1%"
    182  1.1  christos # Invalid: zero
    183  1.1  christos "abc%0$d"
    184  1.1  christos # Invalid: zero
    185  1.1  christos "abc%|0$d|"
    186  1.1  christos # Invalid: zero
    187  1.1  christos "abc%0%def"
    188  1.1  christos # Valid: two-digit numbered arguments
    189  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"
    190  1.1  christos # Valid: two-digit numbered arguments
    191  1.1  christos "abc%|11$d|ef%|10$d|gh%|9$d|ij%|8$d|kl%|7$d|mn%|6$d|op%|5$d|qr%|4$d|st%|3$d|uv%|2$d|wx%|1$d|yz"
    192  1.1  christos # Invalid: unterminated number
    193  1.1  christos "abc%1"
    194  1.1  christos # Valid: omitted directive number
    195  1.1  christos "abc%|1|"
    196  1.1  christos # Invalid: flags before number
    197  1.1  christos "abc%+1$d"
    198  1.1  christos # Invalid: flags before number
    199  1.1  christos "abc%|+1$d|"
    200  1.1  christos # Valid: three arguments, two with same number
    201  1.1  christos "abc%1$4x,%2$c,%1$u"
    202  1.1  christos # Valid: three arguments, two with same number
    203  1.1  christos "abc%|1$4x|,%|2$c|,%|1$u|"
    204  1.1  christos # Invalid: argument with conflicting types
    205  1.1  christos "abc%1$4x,%2$c,%1$p"
    206  1.1  christos # Invalid: argument with conflicting types
    207  1.1  christos "abc%|1$4x|,%|2$c|,%|1$p|"
    208  1.1  christos # Valid: no conflict
    209  1.1  christos "abc%1$4x,%2$c,%1$s"
    210  1.1  christos # Valid: no conflict
    211  1.1  christos "abc%|1$4x|,%|2$c|,%|1$s|"
    212  1.1  christos # Valid: no conflict
    213  1.1  christos "abc%1$4x,%2$c,%1$u"
    214  1.1  christos # Valid: no conflict
    215  1.1  christos "abc%|1$4x|,%|2$c|,%|1$u|"
    216  1.1  christos # Invalid: mixing of numbered and unnumbered arguments
    217  1.1  christos "abc%d%2$x"
    218  1.1  christos # Invalid: mixing of numbered and unnumbered arguments
    219  1.1  christos "abc%|d|%|2$x|"
    220  1.1  christos # Invalid: mixing of numbered and unnumbered arguments
    221  1.1  christos "abc%|d|%2%"
    222  1.1  christos # Valid: numbered argument with constant precision
    223  1.1  christos "abc%1$.9x"
    224  1.1  christos # Valid: numbered argument with constant precision
    225  1.1  christos "abc%|1$.9x|"
    226  1.1  christos # Invalid: mixing of numbered and unnumbered arguments
    227  1.1  christos "abc%1$.*x"
    228  1.1  christos # Invalid: mixing of numbered and unnumbered arguments
    229  1.1  christos "abc%|1$.*x|"
    230  1.1  christos # Valid: missing non-final argument
    231  1.1  christos "abc%2$x%3$s"
    232  1.1  christos # Valid: missing non-final argument
    233  1.1  christos "abc%|2$x|%|3$s|"
    234  1.1  christos # Valid: missing non-final argument
    235  1.1  christos "abc%2%%3%"
    236  1.1  christos # Valid: permutation
    237  1.1  christos "abc%2$ddef%1$d"
    238  1.1  christos # Valid: permutation
    239  1.1  christos "abc%|2$d|def%|1$d|"
    240  1.1  christos # Valid: multiple uses of same argument
    241  1.1  christos "abc%2$xdef%1$pghi%2$x"
    242  1.1  christos # Valid: multiple uses of same argument
    243  1.1  christos "abc%|2$x|def%|1$p|ghi|%2$x|"
    244  1.1  christos # Valid: one argument with width
    245  1.1  christos "abc%2$#*1$g"
    246  1.1  christos # Valid: one argument with width
    247  1.1  christos "abc%|2$#*1$g|"
    248  1.1  christos # Valid: one argument with width and precision
    249  1.1  christos "abc%3$*2$.*1$g"
    250  1.1  christos # Valid: one argument with width and precision
    251  1.1  christos "abc%|3$*2$.*1$g|"
    252  1.1  christos # Invalid: zero
    253  1.1  christos "abc%2$*0$.*1$g"
    254  1.1  christos # Invalid: zero
    255  1.1  christos "abc%|2$*0$.*1$g|"
    256  1.1  christos # Valid: tab
    257  1.1  christos "abc%t"
    258  1.1  christos # Valid: tab
    259  1.1  christos "abc%9t"
    260  1.1  christos # Valid: tab
    261  1.1  christos "abc%|9t|"
    262  1.1  christos # Invalid: unterminated directive
    263  1.1  christos "abc%T"
    264  1.1  christos # Valid: tab
    265  1.1  christos "abc%T "
    266  1.1  christos # Valid: tab
    267  1.1  christos "abc%99T "
    268  1.1  christos # Invalid: unterminated directive
    269  1.1  christos "abc%|99T "
    270  1.1  christos # Invalid: unterminated directive
    271  1.1  christos "abc%|99T|"
    272  1.1  christos # Valid: tab
    273  1.1  christos "abc%|99T |"
    274  1.1  christos # Valid: tab
    275  1.1  christos "abc%|99T||"
    276  1.1  christos EOF
    277  1.1  christos 
    278  1.1  christos : ${XGETTEXT=xgettext}
    279  1.1  christos n=0
    280  1.1  christos while read comment; do
    281  1.1  christos   read string
    282  1.1  christos   n=`expr $n + 1`
    283  1.1  christos   tmpfiles="$tmpfiles f-bo-1-$n.in f-bo-1-$n.po"
    284  1.1  christos   cat <<EOF > f-bo-1-$n.in
    285  1.1  christos gettext(${string});
    286  1.1  christos EOF
    287  1.1  christos   ${XGETTEXT} -L C++ --boost -o f-bo-1-$n.po f-bo-1-$n.in || exit 1
    288  1.1  christos   test -f f-bo-1-$n.po || exit 1
    289  1.1  christos   fail=
    290  1.1  christos   if echo "$comment" | grep 'Valid:' > /dev/null; then
    291  1.1  christos     if grep boost-format f-bo-1-$n.po > /dev/null; then
    292  1.1  christos       :
    293  1.1  christos     else
    294  1.1  christos       fail=yes
    295  1.1  christos     fi
    296  1.1  christos   else
    297  1.1  christos     if grep boost-format f-bo-1-$n.po > /dev/null; then
    298  1.1  christos       fail=yes
    299  1.1  christos     else
    300  1.1  christos       :
    301  1.1  christos     fi
    302  1.1  christos   fi
    303  1.1  christos   if test -n "$fail"; then
    304  1.1  christos     echo "Format string recognition error:" 1>&2
    305  1.1  christos     cat f-bo-1-$n.in 1>&2
    306  1.1  christos     echo "Got:" 1>&2
    307  1.1  christos     cat f-bo-1-$n.po 1>&2
    308  1.1  christos     exit 1
    309  1.1  christos   fi
    310  1.1  christos   rm -f f-bo-1-$n.in f-bo-1-$n.po
    311  1.1  christos done < f-bo-1.data
    312  1.1  christos 
    313  1.1  christos rm -fr $tmpfiles
    314  1.1  christos 
    315  1.1  christos exit 0
    316