tests: Add a test for xgettext's computation of the POT-Creation-Date.

* gettext-tools/tests/testdata/repo.tar.gz: New file.
* gettext-tools/tests/xgettext-git-1: New file.
* gettext-tools/tests/Makefile.am (TESTS): Add it.
(EXTRA_DIST): Add testdata/repo.tar.gz.
This commit is contained in:
Bruno Haible 2025-05-02 00:38:57 +02:00
parent edff5c9ab2
commit 1077d538be
3 changed files with 265 additions and 0 deletions

View File

@ -87,6 +87,7 @@ TESTS = gettext-1 gettext-2 \
xgettext-13 xgettext-14 xgettext-15 xgettext-16 xgettext-17 \
xgettext-18 \
xgettext-combine-1 xgettext-combine-2 xgettext-combine-3 \
xgettext-git-1 \
xgettext-appdata-1 xgettext-appdata-2 xgettext-appdata-3 \
xgettext-awk-1 xgettext-awk-2 xgettext-awk-3 \
xgettext-awk-stackovfl-1 xgettext-awk-stackovfl-2 \
@ -289,6 +290,7 @@ EXTRA_DIST += init.sh init.cfg $(TESTS) \
testdata/dprog.utf-16be.d testdata/dprog.utf-16le.d \
testdata/dprog.utf-32be.d testdata/dprog.utf-32le.d \
testdata/nonascii.pot \
testdata/repo.tar.gz \
testdata/tcltest_pl.po testdata/tcltest_pl.msg \
testdata/tcltest_cs.po testdata/tcltest_cs.msg \
testdata/xg-el-so-3.el testdata/xg-el-so-4.el \

BIN
gettext-tools/tests/testdata/repo.tar.gz vendored Normal file

Binary file not shown.

View File

@ -0,0 +1,263 @@
#! /bin/sh
. "${srcdir=.}/init.sh"; path_prepend_ . ../src
# Test extraction of POT-Creation-Date from git version-control info.
: ${XGETTEXT=xgettext}
# ==============================================================================
# Verify that xgettext succeeds when possibly run outside of any git checkout
# (namely from a tarball, or in a VPATH build in /tmp).
cat <<\EOF > xg-gi-test1-a.c
gettext ("Hello world!");
EOF
${XGETTEXT} -o xg-gi-test1-a.tmp1 --no-location xg-gi-test1-a.c
LC_ALL=C tr -d '\r' < xg-gi-test1-a.tmp1 > xg-gi-test1-a.tmp2 || Exit 1
sed -e '/POT-Creation-Date/d' < xg-gi-test1-a.tmp2 > xg-gi-test1-a.pot
cat <<\EOF > xg-gi-test1-a.ok
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=CHARSET\n"
"Content-Transfer-Encoding: 8bit\n"
msgid "Hello world!"
msgstr ""
EOF
: ${DIFF=diff}
${DIFF} xg-gi-test1-a.ok xg-gi-test1-a.pot || Exit 1
# ==============================================================================
# Skip the rest of this test if 'git' is not present.
(git --version) >/dev/null 2>/dev/null \
|| { echo "Skipping test: git not found"; Exit 77; }
# Unpack a prepared git repository.
: ${TAR=tar}
gzip -d -c < "$wabs_srcdir"/testdata/repo.tar.gz | ${TAR} xf -
cd repo || Exit 1
git restore . || Exit 1
cd src || Exit 1
# ==============================================================================
# Verify the computation of a POT-Creation-Date from 1000 files
# in a single commit.
TZ=UTC0 \
${XGETTEXT} -o xg-gi-test1-b.tmp --no-location \
'Hadschi Halef Omar/ben/Hadschi Abul Abbas/ibn/Hadschi Dawuhd al Gossarah'/same*.c
LC_ALL=C tr -d '\r' < xg-gi-test1-b.tmp > xg-gi-test1-b.pot || Exit 1
cat <<\EOF > xg-gi-test1-b.ok
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2025-05-01 20:47+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
msgid "Hello, world!"
msgstr ""
EOF
: ${DIFF=diff}
${DIFF} xg-gi-test1-b.ok xg-gi-test1-b.pot || Exit 1
# ------------------------------------------------------------------------------
# Verify the computation of a POT-Creation-Date from 1000 files
# in different commits.
TZ=UTC0 \
${XGETTEXT} -o xg-gi-test1-c.tmp --no-location \
'Hadschi Halef Omar/ben/Hadschi Abul Abbas/ibn/Hadschi Dawuhd al Gossarah'/sequence*.c
LC_ALL=C tr -d '\r' < xg-gi-test1-c.tmp > xg-gi-test1-c.pot || Exit 1
cat <<\EOF > xg-gi-test1-c.ok
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2025-05-01 21:08+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
msgid "Hello, world!"
msgstr ""
EOF
: ${DIFF=diff}
${DIFF} xg-gi-test1-c.ok xg-gi-test1-c.pot || Exit 1
# ------------------------------------------------------------------------------
# Verify the computation of a POT-Creation-Date from a file
# outside the current directory.
TZ=UTC0 \
${XGETTEXT} -o xg-gi-test1-d.tmp --no-location --force-po ../README
LC_ALL=C tr -d '\r' < xg-gi-test1-d.tmp > xg-gi-test1-d.pot || Exit 1
cat <<\EOF > xg-gi-test1-d.ok
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2025-05-01 20:44+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=CHARSET\n"
"Content-Transfer-Encoding: 8bit\n"
EOF
: ${DIFF=diff}
${DIFF} xg-gi-test1-d.ok xg-gi-test1-d.pot || Exit 1
# ------------------------------------------------------------------------------
# Verify that the computation of a POT-Creation-Date reflects the
# modification status of a given file.
echo >> ../README
TZ=UTC0 \
${XGETTEXT} -o xg-gi-test1-e.tmp --no-location --force-po ../README
LC_ALL=C tr -d '\r' < xg-gi-test1-e.tmp > xg-gi-test1-e.pot || Exit 1
: ${DIFF=diff}
if ${DIFF} xg-gi-test1-d.ok xg-gi-test1-e.pot; then
Exit 1
fi
# ------------------------------------------------------------------------------
# Verify that the computation of a POT-Creation-Date does not fail
# when a given file is outside the git checkout.
cat <<\EOF > ../../xg-gi-test1-f.c
gettext ("outside");
EOF
${XGETTEXT} -o xg-gi-test1-f.tmp1 --no-location ../../xg-gi-test1-f.c
LC_ALL=C tr -d '\r' < xg-gi-test1-f.tmp1 > xg-gi-test1-f.tmp2 || Exit 1
sed -e '/POT-Creation-Date/d' < xg-gi-test1-f.tmp2 > xg-gi-test1-f.pot
cat <<\EOF > xg-gi-test1-f.ok
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=CHARSET\n"
"Content-Transfer-Encoding: 8bit\n"
msgid "outside"
msgstr ""
EOF
: ${DIFF=diff}
${DIFF} xg-gi-test1-f.ok xg-gi-test1-f.pot || Exit 1
# ------------------------------------------------------------------------------
# Verify that the computation of a POT-Creation-Date fails
# when a given file is inside the git checkout but non-existent.
if ${XGETTEXT} -o xg-gi-test1-g.tmp1 --no-location --force-po ../xg-gi-test1-g.c; then
Exit 1
fi
if ${XGETTEXT} -o xg-gi-test1-g.tmp1 --no-location --force-po xg-gi-test1-g.c; then
Exit 1
fi
# ------------------------------------------------------------------------------
# Verify that the computation of a POT-Creation-Date does not fail
# when a given file is inside the git checkout but not under version control.
cat <<\EOF > ../xg-gi-test1-h.c
gettext ("inside");
EOF
${XGETTEXT} -o xg-gi-test1-h.tmp1 --no-location ../xg-gi-test1-h.c
LC_ALL=C tr -d '\r' < xg-gi-test1-h.tmp1 > xg-gi-test1-h.tmp2 || Exit 1
sed -e '/POT-Creation-Date/d' < xg-gi-test1-h.tmp2 > xg-gi-test1-h.pot
cat <<\EOF > xg-gi-test1-h.ok
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=CHARSET\n"
"Content-Transfer-Encoding: 8bit\n"
msgid "inside"
msgstr ""
EOF
: ${DIFF=diff}
${DIFF} xg-gi-test1-h.ok xg-gi-test1-h.pot || Exit 1