Imported Upstream version 0.19.7
[platform/upstream/gettext.git] / gettext-tools / tests / format-sh-2
1 #! /bin/sh
2 . "${srcdir=.}/init.sh"; path_prepend_ . ../src
3
4 # Test checking of Shell format strings.
5
6 cat <<\EOF > f-sh-2.data
7 # Invalid: invalid msgstr
8 msgid  "abc$file"
9 msgstr "xyz$file$"
10 # Valid: same arguments, permutation
11 msgid  "abc$file in $dir"
12 msgstr "xyz$dir o $file"
13 # Invalid: missing argument
14 msgid  "abc$dir/$file"
15 msgstr "xyz$file"
16 # Invalid: added argument
17 msgid  "abc$file"
18 msgstr "xyz$file in $dir"
19 # Valid: braces or not, doesn't matter
20 msgid  "abc$file"
21 msgstr "xyz${file}"
22 # Invalid: different default value
23 msgid  "abc$file"
24 msgstr "xyz${file-/tmpdir}"
25 EOF
26
27 : ${MSGFMT=msgfmt}
28 n=0
29 while read comment; do
30   read msgid_line
31   read msgstr_line
32   n=`expr $n + 1`
33   cat <<EOF > f-sh-2-$n.po
34 #, sh-format
35 ${msgid_line}
36 ${msgstr_line}
37 EOF
38   fail=
39   if echo "$comment" | grep 'Valid:' > /dev/null; then
40     if ${MSGFMT} --check-format -o f-sh-2-$n.mo f-sh-2-$n.po; then
41       :
42     else
43       fail=yes
44     fi
45   else
46     ${MSGFMT} --check-format -o f-sh-2-$n.mo f-sh-2-$n.po 2> /dev/null
47     if test $? = 1; then
48       :
49     else
50       fail=yes
51     fi
52   fi
53   if test -n "$fail"; then
54     echo "Format string checking error:" 1>&2
55     cat f-sh-2-$n.po 1>&2
56     exit 1
57   fi
58   rm -f f-sh-2-$n.po f-sh-2-$n.mo
59 done < f-sh-2.data
60
61 exit 0