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