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