Imported Upstream version 0.19.7
[platform/upstream/gettext.git] / gettext-tools / tests / format-perl-mixed-2
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
7 cat <<\EOF > f-pm-2.data
8 # Valid: normal case.
9 #, perl-format, perl-brace-format
10 msgid  "{foo} %d {bar} %s"
11 msgstr "{bar} {foo} %d %s"
12 # Invalid: missing argument.
13 #, perl-format, perl-brace-format
14 msgid  "{foo} %d {bar} %s"
15 msgstr "{bar} %d %s"
16 # Valid: missing argument but checking disabled.
17 #, perl-format, no-perl-brace-format
18 msgid  "{foo} %d {bar} %s"
19 msgstr "{bar} %d %s"
20 # Invalid: printf format reordered without position specifiers %1$, %2$.
21 #, perl-format, perl-brace-format
22 msgid  "{foo} %d {bar} %s"
23 msgstr "{bar} %s {foo} %d"
24 # Valid: same thing but checking disabled.
25 #, no-perl-format, perl-brace-format
26 msgid  "{foo} %d {bar} %s"
27 msgstr "{bar} %s {foo} %d"
28 # Invalid: unnamed vs. named arguments
29 #, perl-format
30 msgid  "abc%sdef"
31 msgstr "xyz{value}"
32 # Invalid: named vs. unnamed arguments
33 #, perl-brace-format
34 msgid  "abc{value}def"
35 msgstr "xyz%s"
36 EOF
37
38 : ${MSGFMT=msgfmt}
39 n=0
40 while 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}
49 EOF
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
70 done < f-pm-2.data
71
72 exit 0