From: Dan Scott Date: Fri, 7 Apr 2017 18:19:22 +0000 (-0400) Subject: LP#1680312 Ensure oils_i18n_gettext keys are unique X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=9d3e6ff798e7604272481fc71f9dbe133c79ca39;p=evergreen%2Fpines.git LP#1680312 Ensure oils_i18n_gettext keys are unique To avoid inadvertent introduction of duplicate oils_18n_gettext() keys in the data seed SQL, which will then prevent translated strings from being able to be loaded, add a regression test. Signed-off-by: Dan Scott Signed-off-by: Ben Shum --- diff --git a/Open-ILS/src/perlmods/t/24-sql-gettext-unique.t b/Open-ILS/src/perlmods/t/24-sql-gettext-unique.t new file mode 100644 index 0000000000..5df76ce08d --- /dev/null +++ b/Open-ILS/src/perlmods/t/24-sql-gettext-unique.t @@ -0,0 +1,37 @@ +use strict; +use warnings; +use Test::More; +use Test::Output; + +my $num_tests = 0; + +my $data; +{ + open(my $fh, "<", "../sql/Pg/950.data.seed-values.sql") + or die "Can't open 950.data.seed-values.sql: $!"; + local $/ = undef; + $data = <$fh>; +} + +my $findi18n = qr/oils_i18n_gettext\((.*?)\'\s*\)/; +my $intkey = qr/\s*(\d+)\s*,\s*E?\'(.+?)\',\s*\'(.+?)\',\s*\'(.+?)$/; +my $textkey = qr/\s*\'(.*?)\'\s*,\s*E?\'(.+?)\',\s*\'(.+?)\',\s*\'(.+?)$/; + +my %found; +my @caps = $data =~ m/$findi18n/gms; +foreach my $cap (@caps) { + my $unique; + my @matches = $cap =~ m/$intkey/gms; + if (length($matches[0])) { + $unique = join('', $matches[0], $matches[2], $matches[3]); + } else { + @matches = $cap =~ m/$textkey/gms; + $unique = join('', $matches[0], $matches[2], $matches[3]); + } + isnt(exists($found{$unique}), 1, "oils_18n_gettext duplicate key: $cap'"); + $found{"$unique"} = 1; + $num_tests++; + #print "$cap \n"; +} + +done_testing($num_tests);