Bugzilla – Attachment 178009 Details for
Bug 39130
Add unit tests for xgettext.pl
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 39130: Add unit tests for xgettext.pl
Bug-39130-Add-unit-tests-for-xgettextpl.patch (text/plain), 4.10 KB, created by
Julian Maurice
on 2025-02-13 13:40:57 UTC
(
hide
)
Description:
Bug 39130: Add unit tests for xgettext.pl
Filename:
MIME Type:
Creator:
Julian Maurice
Created:
2025-02-13 13:40:57 UTC
Size:
4.10 KB
patch
obsolete
>From 100f7d3a6bcf4152afc9b9f713ec78bbc9dc0eb2 Mon Sep 17 00:00:00 2001 >From: Julian Maurice <julian.maurice@biblibre.com> >Date: Thu, 13 Feb 2025 14:26:55 +0100 >Subject: [PATCH] Bug 39130: Add unit tests for xgettext.pl > >Test plan: >1. Run `prove t/db_dependent/misc/translator/xgettext.pl.t` >--- > .../misc/translator/sample-not-working.tt | 3 + > t/db_dependent/misc/translator/sample.tt | 9 +++ > t/db_dependent/misc/translator/xgettext.pl.t | 64 +++++++++++++++++++ > 3 files changed, 76 insertions(+) > create mode 100644 t/db_dependent/misc/translator/sample-not-working.tt > create mode 100755 t/db_dependent/misc/translator/xgettext.pl.t > >diff --git a/t/db_dependent/misc/translator/sample-not-working.tt b/t/db_dependent/misc/translator/sample-not-working.tt >new file mode 100644 >index 0000000000..5c1366cb78 >--- /dev/null >+++ b/t/db_dependent/misc/translator/sample-not-working.tt >@@ -0,0 +1,3 @@ >+<p>The whole file won't be translatable because of the following line:</p> >+<span [% IF 0 > 1 %]title="Don't use > in TT directives that are inside HTML tags"></span> >+<p>Still not translatable</p> >diff --git a/t/db_dependent/misc/translator/sample.tt b/t/db_dependent/misc/translator/sample.tt >index 3fd4fca2a5..a24b2b99f7 100644 >--- a/t/db_dependent/misc/translator/sample.tt >+++ b/t/db_dependent/misc/translator/sample.tt >@@ -34,3 +34,12 @@ > [% BLOCK %] > [% t('Inside block') | $raw %] > [% END %] >+ >+<span>This should be picked by xgettext.pl</span> >+ >+<img alt="alt text"> >+ >+<option [% IF value == expected %]selected[% END %] title="foo title" value="foo">Foo</option> >+ >+<span [% IF show_title %]title="this is not translatable (known bug)"[% END %]></span> >+<span [% IF show_title %] title="but this is (thanks to space before attribute name)"[% END %]></span> >diff --git a/t/db_dependent/misc/translator/xgettext.pl.t b/t/db_dependent/misc/translator/xgettext.pl.t >new file mode 100755 >index 0000000000..b6d2a4d1d3 >--- /dev/null >+++ b/t/db_dependent/misc/translator/xgettext.pl.t >@@ -0,0 +1,64 @@ >+#!/usr/bin/perl >+ >+use Modern::Perl; >+ >+use File::Slurp; >+use File::Temp qw(tempdir); >+use FindBin qw($Bin); >+use Locale::PO; >+use Test::More tests => 20; >+ >+my $tempdir = tempdir( CLEANUP => 1 ); >+ >+write_file( "$tempdir/files", "$Bin/sample.tt" ); >+ >+my $xgettext_cmd = "$Bin/../../../../misc/translator/xgettext.pl -o $tempdir/Koha.pot -f $tempdir/files"; >+ >+system($xgettext_cmd); >+system("msgcat -o $tempdir/Koha.sorted.pot -s $tempdir/Koha.pot"); >+my $pot = Locale::PO->load_file_asarray("$tempdir/Koha.sorted.pot"); >+ >+my @expected = ( >+ { >+ msgid => >+ '"%s %s %s %s %s %s %s %s %s %s [%% # it also works on multiple lines tnpx ( \'context\', \'{count} item\', \'{count} items\', count, { count = count, } ) | $raw %%] [%% # and t* calls can be nested tx(\'status is {status}\', { status = active ? t(\'active\') : t(\'inactive\') }) | $raw %%] [%%# but a TT comment won\'t get picked t(\'not translatable\') %%] %s %s %s "', >+ }, >+ { >+ msgid => '"Foo"', >+ }, >+ { >+ msgid => '"This should be picked by xgettext.pl"', >+ }, >+ { >+ msgid => '"alt text"', >+ }, >+ { >+ msgid => '"but this is (thanks to space before attribute name)"', >+ }, >+ { >+ msgid => '"foo title"', >+ }, >+); >+ >+for ( my $i = 0 ; $i < @expected ; $i++ ) { >+ for my $key (qw(msgid msgid_plural msgctxt)) { >+ my $expected = $expected[$i]->{$key}; >+ my $expected_str = defined $expected ? $expected : 'not defined'; >+ my $msg = $pot->[ $i + 1 ]; >+ if ($msg) { >+ is( $msg->$key, $expected, "$i: $key is $expected_str" ); >+ } else { >+ fail("$i: $key is $expected_str (no corresponding message in POT)"); >+ } >+ } >+} >+ >+is( scalar @$pot, 1 + scalar(@expected) ); >+ >+write_file( "$tempdir/files", "$Bin/sample-not-working.tt" ); >+ >+$xgettext_cmd = "$Bin/../../../../misc/translator/xgettext.pl -o $tempdir/Koha.pot -f $tempdir/files 2>/dev/null"; >+ >+system($xgettext_cmd); >+$pot = Locale::PO->load_file_asarray("$tempdir/Koha.pot"); >+is( scalar @$pot, 0, 'xgettext.pl failed to generate a POT file because of incorrect structure' ); >-- >2.39.5
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 39130
:
178008
|
178009
|
178153
|
178380
|
178381
|
179110
|
179111