Home | History | Annotate | Line # | Download | only in tests
      1 #!/bin/sh
      2 
      3 # Test Python support: --from-code option and encoding recognition.
      4 
      5 tmpfiles=""
      6 trap 'rm -fr $tmpfiles' 1 2 3 15
      7 
      8 tmpfiles="$tmpfiles xg-py-3a.py"
      9 cat <<\EOF > xg-py-3a.py
     10 #!/usr/bin/env python
     11 # TRANSLATORS: Franois Pinard is a hero.
     12 print gettext.gettext("");
     13 EOF
     14 
     15 tmpfiles="$tmpfiles xg-py-3b.py"
     16 cat <<\EOF > xg-py-3b.py
     17 #!/usr/bin/env python
     18                        # Hey Emacs! -*- coding: euc-jp -*-
     19 # TRANSLATORS: Franois Pinard is a hero.
     20 print gettext.gettext("");
     21 EOF
     22 
     23 tmpfiles="$tmpfiles xg-py-3.ok"
     24 cat <<\EOF > xg-py-3.ok
     25 # SOME DESCRIPTIVE TITLE.
     26 # Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
     27 # This file is distributed under the same license as the PACKAGE package.
     28 # FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
     29 #
     30 #, fuzzy
     31 msgid ""
     32 msgstr ""
     33 "Project-Id-Version: PACKAGE VERSION\n"
     34 "Report-Msgid-Bugs-To: \n"
     35 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
     36 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
     37 "Language-Team: LANGUAGE <LL (at] li.org>\n"
     38 "MIME-Version: 1.0\n"
     39 "Content-Type: text/plain; charset=UTF-8\n"
     40 "Content-Transfer-Encoding: 8bit\n"
     41 
     42 #. TRANSLATORS: Franois Pinard is a hero.
     43 msgid ""
     44 msgstr ""
     45 EOF
     46 
     47 # Verify that if the source file has no magic coding comment, xgettext fails
     48 # if no --from-code option is given but succeeds if it is given.
     49 tmpfiles="$tmpfiles xg-py-3a.tmp xg-py-3a.pot"
     50 : ${XGETTEXT=xgettext}
     51 ${XGETTEXT} --add-comments=TRANSLATORS: --no-location \
     52   -d xg-py-3a xg-py-3a.py > /dev/null 2>&1
     53 test $? = 1 || { rm -fr $tmpfiles; exit 1; }
     54 ${XGETTEXT} --add-comments=TRANSLATORS: --no-location --from-code=euc-jp \
     55   -o xg-py-3a.tmp xg-py-3a.py
     56 test $? = 0 || { rm -fr $tmpfiles; exit 1; }
     57 grep -v 'POT-Creation-Date' < xg-py-3a.tmp > xg-py-3a.pot
     58 
     59 : ${DIFF=diff}
     60 ${DIFF} xg-py-3.ok xg-py-3a.pot
     61 test $? = 0 || { rm -fr $tmpfiles; exit 1; }
     62 
     63 # Verify that if the source file has a magic coding comment, xgettext succeeds.
     64 
     65 tmpfiles="$tmpfiles xg-py-3b.tmp xg-py-3b.pot"
     66 ${XGETTEXT} --add-comments=TRANSLATORS: --no-location \
     67   -o xg-py-3b.tmp xg-py-3b.py
     68 test $? = 0 || { rm -fr $tmpfiles; exit 1; }
     69 grep -v 'POT-Creation-Date' < xg-py-3b.tmp > xg-py-3b.pot
     70 
     71 ${DIFF} xg-py-3.ok xg-py-3b.pot
     72 test $? = 0 || { rm -fr $tmpfiles; exit 1; }
     73 
     74 # Verify that if the source file has a magic coding comment and a --from-code
     75 # option is given, the magic coding comment takes precedence over it.
     76 
     77 tmpfiles="$tmpfiles xg-py-3c.tmp xg-py-3c.pot"
     78 ${XGETTEXT} --add-comments=TRANSLATORS: --no-location --from-code=iso-8859-1 \
     79   -o xg-py-3c.tmp xg-py-3b.py
     80 test $? = 0 || { rm -fr $tmpfiles; exit 1; }
     81 grep -v 'POT-Creation-Date' < xg-py-3c.tmp > xg-py-3c.pot
     82 
     83 ${DIFF} xg-py-3.ok xg-py-3c.pot
     84 test $? = 0 || { rm -fr $tmpfiles; exit 1; }
     85 
     86 # Verify that backslashes in and second bytes with value 0x5C are correctly
     87 # distinguished in weird encodings like BIG5.
     88 
     89 tmpfiles="$tmpfiles xg-py-3d.py"
     90 cat <<\EOF > xg-py-3d.py
     91 #!/usr/bin/env python
     92                        # Hey Emacs! -*- coding: big5 -*-
     93 print gettext.gettext(u"\u0021");
     94 print gettext.gettext(u"\\u0021");
     95 EOF
     96 
     97 tmpfiles="$tmpfiles xg-py-3d.tmp xg-py-3d.pot"
     98 ${XGETTEXT} --add-comments=TRANSLATORS: \
     99   -o xg-py-3d.tmp xg-py-3d.py
    100 test $? = 0 || { rm -fr $tmpfiles; exit 1; }
    101 grep -v 'POT-Creation-Date' < xg-py-3d.tmp > xg-py-3d.pot
    102 
    103 tmpfiles="$tmpfiles xg-py-3d.ok"
    104 cat <<\EOF > xg-py-3d.ok
    105 # SOME DESCRIPTIVE TITLE.
    106 # Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
    107 # This file is distributed under the same license as the PACKAGE package.
    108 # FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
    109 #
    110 #, fuzzy
    111 msgid ""
    112 msgstr ""
    113 "Project-Id-Version: PACKAGE VERSION\n"
    114 "Report-Msgid-Bugs-To: \n"
    115 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
    116 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
    117 "Language-Team: LANGUAGE <LL (at] li.org>\n"
    118 "MIME-Version: 1.0\n"
    119 "Content-Type: text/plain; charset=UTF-8\n"
    120 "Content-Transfer-Encoding: 8bit\n"
    121 
    122 #: xg-py-3d.py:3
    123 msgid "u0021"
    124 msgstr ""
    125 
    126 #: xg-py-3d.py:4
    127 msgid "!"
    128 msgstr ""
    129 EOF
    130 
    131 ${DIFF} xg-py-3d.ok xg-py-3d.pot
    132 test $? = 0 || { rm -fr $tmpfiles; exit 1; }
    133 
    134 rm -fr $tmpfiles
    135 
    136 exit 0
    137