1#! /bin/sh
2. "${srcdir=.}/init.sh"; path_prepend_ . ../src
3
4# Test checking of Perl format strings.
5# This test is for the combination of printf and brace format strings.
6
7cat <<\EOF > f-pm-2.data
8# Valid: normal case.
9#, perl-format, perl-brace-format
10msgid  "{foo} %d {bar} %s"
11msgstr "{bar} {foo} %d %s"
12# Invalid: missing argument.
13#, perl-format, perl-brace-format
14msgid  "{foo} %d {bar} %s"
15msgstr "{bar} %d %s"
16# Valid: missing argument but checking disabled.
17#, perl-format, no-perl-brace-format
18msgid  "{foo} %d {bar} %s"
19msgstr "{bar} %d %s"
20# Invalid: printf format reordered without position specifiers %1$, %2$.
21#, perl-format, perl-brace-format
22msgid  "{foo} %d {bar} %s"
23msgstr "{bar} %s {foo} %d"
24# Valid: same thing but checking disabled.
25#, no-perl-format, perl-brace-format
26msgid  "{foo} %d {bar} %s"
27msgstr "{bar} %s {foo} %d"
28# Invalid: unnamed vs. named arguments
29#, perl-format
30msgid  "abc%sdef"
31msgstr "xyz{value}"
32# Invalid: named vs. unnamed arguments
33#, perl-brace-format
34msgid  "abc{value}def"
35msgstr "xyz%s"
36EOF
37
38: ${MSGFMT=msgfmt}
39n=0
40while read comment; do
41  read formats
42  read msgid_line
43  read msgstr_line
44  n=`expr $n + 1`
45  cat <<EOF > f-pm-2-$n.po
46${formats}
47${msgid_line}
48${msgstr_line}
49EOF
50  fail=
51  if echo "$comment" | grep 'Valid:' > /dev/null; then
52    if ${MSGFMT} --check-format -o f-pm-2-$n.mo f-pm-2-$n.po; then
53      :
54    else
55      fail=yes
56    fi
57  else
58    ${MSGFMT} --check-format -o f-pm-2-$n.mo f-pm-2-$n.po 2> /dev/null
59    if test $? = 1; then
60      :
61    else
62      fail=yes
63    fi
64  fi
65  if test -n "$fail"; then
66    echo "Format string checking error:" 1>&2
67    cat f-pm-2-$n.po 1>&2
68    Exit 1
69  fi
70done < f-pm-2.data
71
72Exit 0
73