Home | History | Annotate | Line # | Download | only in tests
      1  1.1  christos #! /bin/sh
      2  1.1  christos 
      3  1.1  christos # Test checking of Perl brace 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-pb-2.data"
      9  1.1  christos cat <<\EOF > f-pb-2.data
     10  1.1  christos # Valid: same named arguments
     11  1.1  christos msgid  "abc{date}{time}"
     12  1.1  christos msgstr "xyz{date}{time}"
     13  1.1  christos # Valid: permutation
     14  1.1  christos msgid  "abc{x3}{x1}{x2}def"
     15  1.1  christos msgstr "xyz{x2}{x1}{x3}"
     16  1.1  christos # Invalid: missing argument
     17  1.1  christos msgid  "abc{x2}def{x1}"
     18  1.1  christos msgstr "xyz{x1}"
     19  1.1  christos # Invalid: missing argument
     20  1.1  christos msgid  "abc{x1}def{x2}"
     21  1.1  christos msgstr "xyz{x2}"
     22  1.1  christos # Valid: added argument (valid since "{zoo}" expands to itself)
     23  1.1  christos msgid  "abc{foo}def"
     24  1.1  christos msgstr "xyz{foo}uvw{zoo}"
     25  1.1  christos # Valid: multiple reuse of same argument
     26  1.1  christos msgid  "{foo} {bar} {baz}"
     27  1.1  christos msgstr "{baz} {bar} {foo} {bar}"
     28  1.1  christos # Valid: single reuse of same argument
     29  1.1  christos msgid  "{baz} {bar} {foo} {bar}"
     30  1.1  christos msgstr "{foo} {bar} {baz}"
     31  1.1  christos EOF
     32  1.1  christos 
     33  1.1  christos : ${MSGFMT=msgfmt}
     34  1.1  christos n=0
     35  1.1  christos while read comment; do
     36  1.1  christos   read msgid_line
     37  1.1  christos   read msgstr_line
     38  1.1  christos   n=`expr $n + 1`
     39  1.1  christos   tmpfiles="$tmpfiles f-pb-2-$n.po f-pb-2-$n.mo"
     40  1.1  christos   cat <<EOF > f-pb-2-$n.po
     41  1.1  christos #, perl-brace-format
     42  1.1  christos ${msgid_line}
     43  1.1  christos ${msgstr_line}
     44  1.1  christos EOF
     45  1.1  christos   fail=
     46  1.1  christos   if echo "$comment" | grep 'Valid:' > /dev/null; then
     47  1.1  christos     if ${MSGFMT} --check-format -o f-pb-2-$n.mo f-pb-2-$n.po; then
     48  1.1  christos       :
     49  1.1  christos     else
     50  1.1  christos       fail=yes
     51  1.1  christos     fi
     52  1.1  christos   else
     53  1.1  christos     ${MSGFMT} --check-format -o f-pb-2-$n.mo f-pb-2-$n.po 2> /dev/null
     54  1.1  christos     if test $? = 1; then
     55  1.1  christos       :
     56  1.1  christos     else
     57  1.1  christos       fail=yes
     58  1.1  christos     fi
     59  1.1  christos   fi
     60  1.1  christos   if test -n "$fail"; then
     61  1.1  christos     echo "Format string checking error:" 1>&2
     62  1.1  christos     cat f-pb-2-$n.po 1>&2
     63  1.1  christos     exit 1
     64  1.1  christos   fi
     65  1.1  christos   rm -f f-pb-2-$n.po f-pb-2-$n.mo
     66  1.1  christos done < f-pb-2.data
     67  1.1  christos 
     68  1.1  christos rm -fr $tmpfiles
     69  1.1  christos 
     70  1.1  christos exit 0
     71